Setting Sizing Variables is another task that can be accelerated with the Scripting API. These are examples of how to do that with the HyperSizer and HyperX Scripting APIs, respectively.
Sizing variables are Group data located in the Variables property. When working with a Component, you can easily retrieve the associated group ID using Component.GroupId. Group Sizing variables are set per Concept.
The following code samples assume that Concepts have been assigned.
def set_sizing_variable(project, component, variable_ID, min, max, step_size):
# Given the project, component, and variable ID, set the min, max, and number of steps.
# Get the group associated with the component.
group = project.Groups.GetGroup(component.GroupId)
# Get the group concept IDs.
concept_IDs = group.GetConcepts()
# For each concept, set the variable (if applicable).
variables = group.Variables
for concept_ID in concept_IDs:
if not variables.Contains(concept_ID, variable_ID):
continue
variable = variables.GetVariable(concept_ID, variable_ID)
variable.MinBound = min
variable.MaxBound = max
variable.StepSize = step_size
group.Save()
Sizing variables are located in the Design Property.
import hyperx as hx
def SetSizingVariable(hxApp: hx.Application, zone: hx.Zone, min: float, max: float, stepSize: int):
"""Set some sizing variables on an existing design property and assign it to a zone."""
designPropertyName = "Plate" # Name of existing design property
zoneDesignProperty: hx.ZoneDesignProperty = hxApp.DesignProperties.Get(designPropertyName)
# Confirm that the zone design property created was the correct type (and not joint, etc).
if not isinstance(zoneDesignProperty, hx.ZoneDesignProperty):
raise TypeError(f"Expected zone design property to be of type {hx.ZoneDesignProperty} but was {type(zoneDesignProperty)}.")
# Variable parameters correspond to particular rows in the variable table on the HyperX design form.
designVariableParameter = hx.types.VariableParameter.TopFaceThicknessMaterial
designVariable = zoneDesignProperty.DesignVariables.Get(designVariableParameter)
# Set design variable properties
designVariable.Min = min
designVariable.Max = max
designVariable.StepSize = stepSize
zone.AssignDesignProperty(zoneDesignProperty.Id)