Coreform CubitのPythonへのImport
PythonユーザーはCoreform CubitをPythonにインポートし、CubitInterfaceおよび本節で説明するその他のPythonクラスを介してCoreform Cubitを呼び出すことができます。以下に簡単なPythonスクリプトを示します。重要な点は、Coreform Cubitのライブラリがパスに含まれていることを確認し、最初にcubit.init()を呼び出すことです。
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 . . .
Coreform Cubit内部で実行されるPythonスクリプトには特別なモジュール名があります。このモジュール名を使用すると、Coreform Cubit内部で実行されるコードと外部で実行されるコードを区別できます:
if __name__ == "__main__:
. . . # Do this if running from
# an external process
elif __name__ == "__coreformcubit__":
. . . # Do this if running from
# inside Coreform Cubit.