Example: creation of points starting from a file


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.


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
Note: * The definition of macro requires good knowledge of the Flux database structure and concepts of programming.

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
#! Preflu3D 9.33
indication on the executable program
parameter statement using the keyword @param
parameter names: filename , coordSys
PyFlux types: File , CoordSys
1 1
minimal and maximal cardinalities

default value points.txt

keyword None

Fichier des coordonnées des points
Repère de définition des points
labels of parameters
def Polypoint3D(filename,coordSys) :

definition of the Polypoint3D function with 2 parameters

(parameters to define the file name and the coordinate system)

f = file(filename)
creation of a variable f which takes for values the data of the filename file
for line in f :
realization of a for loop to reiterate on the file lines
coords = line.split()
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:

  • color = white
  • visibility = visible
  • coordinates = (0, 0, 0); (3, 0, 0); (3, 2, 0);

    (2, 2, 0); (2, 1, 0); (1, 1, 0); (1, 2, 0); (0, 2, 0)

  • nature = standard

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 Extensions > Macro menu

    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).