It is recommended that Python developers use the hyperx Python package where possible to make interacting with the API as smooth as possible. In cases where users would rather interact directly with the API, additional steps are required to pass lists to methods which require them as inputs.
Important
Referencing the API assembly and opening a HyperX Database are prerequisites for the following example script. See How To Setup Your Environment and How To Open and Close a Database for more information.
This example also requires the Python package Python.NET (pythonnet) to be installed prior to executing, so users can make use of the clr.AddReference() method to reference the C# Collections namespace. Once this is done, one can import the List class from System.Collections.Generic.
The below Script is an example of a use-case where an engineer wants to pull in FEM properties to an existing Structure in their Database. They have a Python list of integers that correspond to the property IDs in their FEM which they’d like to pull into their Structure. They instantiate an empty C# list, expecting to contain integers, and then loop through their existing Python list of property IDs, adding them to the C# list one-by-one. Finally, this list can be passed to the AddPfemProperties method on the selected Structure.
import clr
clr.AddReference('System.Collections') # Get C#-compatible types
from System.Collections.Generic import List
# Set up environment, instantiate Application, and open project here
# Select a structure in the database to which you want to add FEM properties
structure = project.Structures.Get('My Structure')
# Input property IDs to be added to previously selected structure
propertyIds = [1, 2, 3, 4]
# Instantiate an EMPTY C#-style list,which expects integers
propertyIdsCSharpList = List[int]()
# Loop through our property IDs and add them one at a time to our list
for id in propertyIds:
propertyIdsCSharpList.Add(id)
# Pass this list to a method as youwould any other parameter
structure.AddPfemProperties(propertyIdsCSharpList)
Tip
When using the hyperx Python package, the above Script can be simplified (see below)
import hyperx as hx
# Open project here
# Select a structure in the database to which you want to add FEM properties
structure = project.Structures.Get('My Structure')
# Input property IDs to be added to previously selected structure
propertyIds = [1, 2, 3, 4]
# Pass this list to a method as you would any other parameter
structure.AddPfemProperties(propertyIds)