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:

  1. In the Toolbox, select Simulation, then double-click Dynamics Script. This adds a Python 3 script extension.
  2. In the Explorer, select the Dynamics Script extension you just added and right-click, and then Edit Fields.
  3. In the resulting dialog box, click the Add button in the Inputs section. An input row is now added.
  4. In the new input's Name field, enter "Cable_Extension".
  5. For the new input's type, select Extension Pointer.
  6. Click Ok at the bottom of the dialog box.
  7. Select the script in the Explorer panel to display its Properties panel.
  8. In the Inputs section of the script's Properties panel, click the Browse button at the end of the field and select the generic cable from the Explorer panel. (Alternatively, you can drag and drop the generic cable from the Explorer panel into the input field.)
  9. Launch you 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}]")
  10. Save the file.
  11. 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.
  12. At the top-right corner of the Vortex Studio Editor click the panel display button and enable the Python Output.
  13. 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.