Example: creation of points starting from a file
Objective
The objective is to show on a simple example how to write and use a macro. This macro makes the repetitive tasks to enter the coordinates during the creation of points easier.
Example description
The Polypoint3D macro is designed to automatically create 3D points starting from a series of coordinates previously saved in a text file. The file name and the coordinate system for definition of the points are selected by the user during the execution of the macro.
Process
The process includes the following stages:
Stage | Description | Context |
---|---|---|
1* | Writing the definition of the macro into the *.py file using the PyFlux language | Text editor |
2 | Writing the coordinates of points into the text file | Text editor |
3 | Loading the macro into the Flux project | Flux |
4 | Running the macro | Flux |
Stage 1
To define the macro in the PyFlux language:
Step | Action |
---|---|
1 | Type a header of executable Flux program |
2 | Describe input parameters of the macro |
3 | Define the Polypoint3D parameterized function in the PyFlux language |
4 | Save the file of the macro under the name Polypoint3D.py in the Polypoint3D.PFM directory. |
Stage 1: file explanation
The file of the macro Polypoint3D.py is presented as follows:
Element | Function |
---|---|
|
indication on the executable program |
|
parameter statement using the keyword @param |
|
parameter names: filename , coordSys |
|
PyFlux types: File , CoordSys |
|
minimal and maximal cardinalities |
|
default value points.txt keyword None |
|
labels of parameters |
|
definition of the Polypoint3D function with 2 parameters (parameters to define the file name and the coordinate system) |
|
creation of a variable f which takes for values the data of the filename file |
|
realization of a for loop to reiterate on the file lines |
|
creation of a variable coords which takes for values the list of strings for each file line |
|
creation of the points with the following characteristics:
|
Stage 2
To save the coordinates of points in the text file:
- type data in the form of table
- save the file under the name point.txt
Stage 2: file
The point.txt file is presented as follows:
Stage 3
To load the macro:
-
click on the Load command in the
or in the contextual menu of the macro
Stage 4
To run the macro:
- click on the Run command in the contextual menu of the macro
- fill out the fields in the dialog box Polypoint3D
Stage 4: final result
After running the Polypoint3D macro, the user has the following 8 points in his Flux project:
(0, 0, 0), (3, 0, 0), (3, 2, 0), (2, 2, 0), (2, 1, 0), (1, 1, 0), (1, 2, 0), (0, 2, 0).