Skip to article

 

Importing Coreform Cubit into Python

Python users are able to import Fidesys into Python and make calls into Fidesys via FidesysInterface and the other Python classes described in this section. Below is a simple Python script. The key parts are ensuring the Fidesys libraries are on the path and ensuring the cubit.init() call is made first.

import sys
 
# add Coreform Cubit libraries to your path
sys.path.append('/opt/Coreform Cubit/bin')
 
import cubit
 
# start cubit - this step is key. Note that:
# cubit.init does not require any arguments.
# If you do want to provide arguments, you must
# provide 2 or more, where the first must
# be "cubit", and user args start 
# as the 2nd argument.
# If only one argument is used, it will be ignored.
cubit.init(['cubit','-nojournal'])
 
height = 1.2
blockHexRadius = 0.1732628
 
#hexagon
cubit.cmd(f"create prism height {height} sides 6 radius {blockHexRadius}")
 
#etc . . .    

Python scripts that run inside Fidesys have a special module name. This module name can be used to differentiate code that run in and out of Fidesys:

if __name__ == "__main__:
    . . . # Do this if running from 
          # an external process
elif __name__ == "__coreformcubit__":
    . . . # Do this if running from 
          # inside Coreform Cubit.