Getting Cable Positions with Scripts
It is possible to use Python scripting in order to retrieve the position and orientation of generic cables in your simulation.
To add a script to fetch cable position:
- In the Toolbox, select Simulation, then double-click Dynamics Script. This adds a Python 3 script extension.
- In the Explorer, select the Dynamics Script extension you just added and right-click, and then Edit Fields.
- In the resulting dialog box, click the Add button in the Inputs section. An input row is now added.
- In the new input's Name field, enter "Cable_Extension".
- For the new input's type, select Extension Pointer.
- Click Ok at the bottom of the dialog box.
- Select the script in the Explorer panel to display its Properties panel.
- In the Inputs section of the script's Properties panel, move your mouse over the blank field next to "Inputs > Cable_Extension", and then click the "..." button that appears. Click the second "..." button to browse to your cable's "Dynamics Generic Cable" in the Explorer panel. Alternatively, you can drag and drop the Dynamics Generic Cable from the Explorer panel into the input field. (Note: Ensure the Dynamics Generic Cable is selected, and not its parent "Generic Cable")Â
Launch your favorite text editor and enter the following code:
from Vortex import * def on_simulation_start(extension): # An Inputs for the Script was added and this input was of type Extension Pointer # This input is set with the Dynamics Generic Cable extension.cableExt = extension.inputs.Cable_Extension.value def post_step(extension): cables = extension.cableExt.getOutput('Cables') cablesContainer = cables.toContainer() # Check if the cable is active. # If not active, the number of cables will be zero. nbCables = cablesContainer["Number Of Cables"].toInteger() if nbCables > 0: # Print the position and the orientation (a quaternion) ptInfos = cablesContainer['Point Infos'] infos = ptInfos[0] nbPts = infos["Number of Points"].toInteger() # Get Points Positions positions = infos['Positions'].toVectorVector3() # Get Points Orientations orientations = infos['Orientations'].toVectorQuaternion() for i in range(nbPts): pos = positions[i] q = orientations[i] print(f"{i} Position: [{pos.x}, {pos.y}, {pos.z}] Orientation:[{q.x}, {q.y}, {q.z}, {q.w}]")
- Save the file.
- In the Vortex Studio Editor, in the Properties view of the Dynamics Script extension, click the ... icon next to the Script Path parameter and select the Python 3 script you just saved from your text editor.
- At the top-right corner of the Vortex Studio Editor click the panel display button and enable the Python Output.
- Click play to run the simulation. You should now see the information concerning the position and orientation of the cable in the Python Output panel.
You must repeat this process with a new Script extension for each generic cable whose position you want to fetch.