Solve Model Variables With a Python Program

General

  • Python is a programming language developed by the Python Software Foundation, which is currently (year 2022) a reasonably popular programming language.
  • This manual does not contain instructions for using the Python program.
  • See an example of editing a model with the help of a python program on the page https://kb.vertex.fi/vxinfofi
    • Select Vertex G4 20XX product documentation (latest).
    • Select the section Usage tips (from the list on the left side).
    • See the instructions: Dimension-driven assembly model added with Python program
  • The values of the model's variables can be solved using the Python program.
  • The Python program related to the model must be located in the same folder as the model and its name must match the model label, for example:
    • Model file name: MODEL123.vxm
    • Name of the Python program: MODEL123.py
  • The Python program is executed in the browser or in the dimension table as follows
    • With the Run function in the Python program section.
    • With the Apply function in the dimension table.
    • When exiting the dimension table with the OK function.
    • When making changes in the dimension table that affect the model (except for color selection), if Run automatically is selected.

Things to consider

Naming of variables

The variables of the model must be named so that the variables are also valid for Python.

  • The length of the name of the variables is not limited.
  • A variable can contain uppercase and lowercase letters. Valid characters are the alphabet A...Z and a...z, the numbers 0...9 and the underscore (_).
  • The variable name of the model must not start with an underscore (_), because a variable name starting with an underscore is reserved for changeable components or parts in the Python program.
  • Vertex recommends using uppercase letters for variable names.

Notepad++ text editor

Notepad++ editor should be used to edit the Python program.

  • Edit the SETUP file in the Vertex G4 home directory, for example:
    • In standalone installations ../vxg4/user/SETUP
    • In server installations //SERVER_NAME/SHARED_FOLDER/vxg4_srv/user/SETUP.computer_name
  • Add a line there:
    • text_editor= py "C:/Program Files/Notepad++/notepad++.exe"
  • This causes the file ending in .py to be opened with Notepad++ and not with Wordpad, for example.

Python program and model in Flow

  • The Python program is saved inside the model file, while the model is checked-in to Flow.
  • At the same time, the Python file next to the model (e.g. MODEL123.py) is deleted, just as the model (e.g. MODEL123.vxm) is deleted from the ../vxg4/shared/picts folder.
  • When the model is loaded from Flow and the python program is needed for the first time, it is retrieved from the model and a file named model.py is created from it next to the model file.

TIP, about writing a Python program

Applies to writing a program with Notepad++, for example:
  • Use four spaces to indent, and not a tab.
  • When you use the tab key, the program appears to be in line with the other code, but the program cannot be executed.