Running Python Script and Journal Files Together

Hello,

Currently I am running a python script in Trelis which also plays other journal scripts to generate some geometry. Once this geometry is created I use the same python script to extract data from the geometry and store this data in an external file. This process works fine until I add a loop structure in the python script to do this repetitively. In this case, the python functions are called immediately and the counter is incremented to the maximum value. It is not until the loop counter reaches the final value that each of the journal files are executed. This is causing a major issue because the data from the geometry cannot be extracted until the geometry has been built. Is there a way to force Trelis to run the python code in the correct order rather than running it first? I’ve provided some pseudocode example here, but regardless of the journal files I use this still occurs.

[code]Python Script Format Example:

test = 15
for i in range(test):
print(i)
cubit.cmd(‘play “journalfile1.jou”’)

  • python code to grab data from the geometry
    cubit.cmd(‘reset’)[/code]

In this example, the loop will increment from 0 to 14 and print 0, 1, 2, …, 14 prior to executing the journal files. Once i = 14 the journal files will be executed 14 times in a row

Thank you in advanced! I hope that there is some easy fix or solution to this problem.

Sorry for not responding sooner. Due to the manner in which Trelis runs journal files within loops, your approach will not work. Try something like below, manually reading each line of the journal file.

test = 15
for i in range(test):
print(i)
infile = open(“journalfile.jou”, “r”)
for line in infile:
cubit.cmd(line)
#python queries
print( cubit.get_volume_area(1) )
cubit.cmd(‘reset’)

Thanks for the reply.

I tried this method and it seems to work fine as long the journal file I am using does not have any loop structures in it (e.g. #{Loop(n)} … #{EndLoop}). Once I introduce a loop into the geometry creation step, the journal file is not longer executed in the correct order and geometry creation fails. Unfortunately I need the loops inside of the journal file because I use these to automatically group surfaces and curves and create blocks.

I was able to find one workaround to these issues which is to just eliminate the outer loop structure by copying and pasting the commands for the required number of times (15 in the previous example). This is undesirable, but it does work for now.

cubit.cmd('play "journalfile1.jou"')
- python code to grab data from the geometry
cubit.cmd('reset')

cubit.cmd('play "journalfile1.jou"')
- python code to grab data from the geometry
cubit.cmd('reset')

...

cubit.cmd('play "journalfile1.jou"')
- python code to grab data from the geometry
cubit.cmd('reset')