User-Defined Loads can be set using the Scripting API in both HyperSizer and HyperX.
When using the API there are two important ideas to remember:
-
User (and FEA) loads are associated with load sets not load cases. Load cases are linear combinations of load set(s).
-
There are two types of design-to loads in HyperSizer: strength and buckling.
The following examples assign user loads to a panel Component in a non-FEA project. Imagine there is a spreadsheet with the following loads prescribed.
|
Load Case |
Nx |
Ny |
Nxy |
|---|---|---|---|
|
101-201 |
1100.0 |
0.0 |
110.0 |
|
102-202 |
-1200.0 |
0.0 |
220.0 |
from hs_enums import *
from collections import namedtuple
def main(databasePath, projectName):
hs, project = OpenHyperSizerProject(databasePath, projectName)
# Make a class to store the input loads - perhaps read in from a spreadsheet.
UserLoad = namedtuple('UserLoad', ['LoadCaseName', 'Nx', 'Ny', 'Nxy'])
userLoads = [
UserLoad('101-201', 1100.0, 0.0, 110.0),
UserLoad('102-202', -1200.0, 0.0, 220.0),
]
# Retrieve the component.
component = project.Components.GetComponent(1)
# Loop over user loads.
for userLoad in userLoads:
# Grab the load case by name.
loadCaseName = userLoad.LoadCaseName
loadCase = project.LoadCases.GetLoadCase(loadCaseName)
# Loop over the associated load SETS.
# * Each load case is associated with one or many load sets
# * This is similar to how Nastran subcases are associate with one or many set IDs.
for loadSetMultipler in loadCase.Multipliers:
loadSetId = loadSetMultipler.LoadSetId
loadSet = GetLoadSetFromId(project, loadSetId)
# Skip thermal load sets.
if loadSet.IsThermal:
continue
# With the user load, component, and panel load, we are ready to set the loads.
# We call the helper function twice. For both strength and buckling.
SetPanelLoads(userLoad, component, loadSetId, DesignToPropertyType.dptForStrengthAnalysis)
SetPanelLoads(userLoad, component, loadSetId, DesignToPropertyType.dptForBucklingAnalysis)
# Save the changes.
component.Save()
def GetLoadSetFromId(project, loadSetId):
# Retrieve load set by ID.
# No API method for this so have to use a helper method.
for loadSet in project.LoadSets:
if loadSet.LoadSetId == loadSetId:
return loadSet
raise Exception('Load set ID ' + str(loadSetId) + ' was not found.')
def SetPanelLoads(userLoad, component, loadSetId, designToProperty):
# Retrieve the existing loads.
panelLoad = component.DesignLoadsPanel(loadSetId, designToProperty)
# Modify.
panelLoad.Nx = userLoad.Nx
panelLoad.Ny = userLoad.Ny
panelLoad.Nxy = userLoad.Nxy
# Apply the changes.
component.SetDesignLoadsPanel(loadSetId, designToProperty, panelLoad)
A single user FEA Load Property can contain many different load scenarios.
import hyperx as hx
def SetUserLoads(hxApp: hx.Application, zone: hx.Zone):
"""Create a new user load property and assign it to a zone"""
loadProperty: hx.LoadPropertyUserFeaPanel = hxApp.LoadProperties.CreateLoadProperty(hx.types.LoadPropertyType.UserFEA, hx.types.FamilyCategory.Panel, "New Load Property")
# Confirm that the load property created was the correct type (and not beam, joint, etc).
if not isinstance(loadProperty, hx.LoadPropertyUserFeaPanel):
raise TypeError(f"Expected load property to be of type {hx.LoadPropertyUserFeaPanel} but was {type(loadProperty)}.")
scenario = loadProperty.UserFeaRows.AddScenario()
# Set userScenario properties (Note: To enhance performance it may be preferable to use a bulk updater when modifying load scenario components)
scenario.SetName("User Scenario Name")
scenario.Nx = 1
scenario.Ny = 2
scenario.Nxy = 3 # etc.
zone.AssignLoadProperty(loadProperty.Id)