In this example, we cycle through all Sets and Structures in a given Database and print out their constituent Zone and Joint names. It is written in the format expected by the Script Runner, containing a Run method that provides the script with a Database and active Project. It also makes use of the hyperx Python package, which is recommended to make interacting with the Scripting API easier for a Python developer.
Note
It is also useful to export information like this to an Excel or CSV file, for easy import in other utility Scripts.
Python packages like csv or openpyxl are helpful tools to make file import and export easier.
The sample code below demonstrates how a user might query various organizational entities in a Database and print them out to the console.
import hyperx as hx
def Run(database_):
# Wrap database coming from Script Runner in
# Python API wrapper, to make interacting with API easier
database = hx.Application(database_)
project = database.ActiveProject
if (len(project.Sets) > 0):
print(f'Sets in {project.Name}:')
for set in project.Sets:
print(f'Set "{set.Name}"')
for zone in set.Zones:
print(f'\tZone "{zone.Name}"')
for joint in set.Joints:
print(f'\tJoint "{joint.Name}"')
print()
if (len(project.Structures) > 0):
print(f'Structures in {project.Name}')
for structure in project.Structures:
print(f'Structure "{structure.Name}"')
for zone in structure.Zones:
print(f'\tZone "{zone.Name}"')
for joint in structure.Joints:
print(f'\tJoint "{joint.Name}"')