Methods#
getModel#
- getModel()#
The root of the Inspire data model tree.
Its not explicitly created. It exists as a singleton for the lifetime of the application. Multiple models may be supported in future releases.
Use model.getChildren(…) to access all the descendent entities. Most types are stored as direct children of the model but Parts & Assemblies form a hierarchy.
Use model.save(file) and inspire.openFile(file) to save/load the model contents.
- Returns:
Model
Example
from hwx import inspire
model = inspire.getModel()
# get objects in the model
print("objects:", model.getChildren()[:3], "...")
newModel#
- newModel()#
Clear the model resetting it back to its initial/empty state.
- Returns:
Model
Example
from hwx import inspire
# Start with an empty model
model = inspire.newModel()
# New model is initialized with materials, ...
print("initial objects:", set(type(obj) for obj in model.getChildren()))
# Construct your model from scratch
model.createSolidSphere()
inspire.fitView()
openFile#
- openFile(file)#
Replace the current model with the saved one.
- Parameters:
file (str) – Path to the file.
- Returns:
Model
Example
from hwx import inspire
filePath = inspire.getTutorialFilePath("Structures/baseline_oilpan.stmod")
model = inspire.openFile(filePath)
print("parts:", model.parts)
importFile#
- importFile(file)#
Imports and merges a saved model with the current model.
The imported model is inserted as an assembly under the top-level folder in the Model Browser.
- Parameters:
file (str) – Path to the file.
Example
from hwx import inspire
model = inspire.getModel()
print("parts:", model.parts)
filePath = inspire.getTutorialFilePath("Structures/bolt.x_t")
inspire.importFile(filePath)
print("parts:", model.parts)
# Add new part
filePath = inspire.getTutorialFilePath("Structures/bracket.x_t")
inspire.importFile(filePath)
print("parts:", model.parts)
inspire.fitView()
getTutorialFilePath#
- getTutorialFilePath(file)#
Returns the absolute path to a tutorial model give a relative path.
- Parameters:
file (str) – Path relative to the tutorial_models directory.
- Returns:
pathlib.Path
openTutorialFile#
- openTutorialFile(file)#
Opens the given input model from tutorial directory.
- Parameters:
file (str) – Path relative to the tutorial_models directory.
- Returns:
Model
importTutorialFile#
- importTutorialFile(file)#
Opens the model from the tutorials folder and add it to the active model.
- Parameters:
file (str) – Path relative to the tutorial_models directory.
getUnits#
- getUnits()#
UnitsManager: For internal use…
Use with inspire.usingUnits(…) to get/set values in a certain unit system.
usingUnits#
- usingUnits(system)#
Get or set data model values in specified unit system.
- Parameters:
system (str) –
Name of unit system: base: The default units when none is specified (MKS). gui: User selected units for display in the gui. solver: Used for converting numbers when exporting to a solver.
Comes from: inspire.getSetting(“Unity/Mbd/Run Options/Run Options/Solver units”)
- MKS, CGS, IPS,…: Name of system.
See inspire.getUnits().gui.getSystemNames() for all options.
- Returns:
contextmanager
getProject#
- getProject()#
getMaterials#
- getMaterials()#
Return a dictionary of defined material keys to the material name.
- Returns:
dict[str, Material]
getSystemDirectory#
- getSystemDirectory()#
Returns the path to the installation directory.
- Returns:
pathlib.Path
getSetting#
- getSetting(setting=None, mustExist=False)#
Returns the user preference value for a given setting.
- Parameters:
setting (str) – The preference option path with ‘/’.
mustExist (bool) – Raise exception if setting does not exist.
- Returns:
bool | int | float | str | None
setSetting#
- setSetting(setting, value)#
Sets the user preference value for a given setting.
- Parameters:
setting (str) – Path to preference option.
value (bool | int | float | str) –
ishole#
runningInBatch#
- runningInBatch()#
Return True if the application runs in batch mode, False otherwise.
- Returns:
Returns True in batch mode, else False.
- Return type:
bool
Example
from hwx import inspire
if inspire.runningInBatch():
print("We are running in batch mode")
else:
print("We are running in gui mode")
enableDebugMessaging#
- enableDebugMessaging(level='ALL')#
Prints internal inspire messaging to command window.
- Parameters:
level (str) –
level defines the lowest level of messaging that should be seen. Defaults to ALL. Level can be, ERROR - prints internal inspire error messaging to command window. WARN - prints internal inspire warning messaging to command window. INFO - prints internal inspire error, warning and info messaging
to command window.
False - passed as boolean and disables all messaging.
Example
from hwx import inspire
inspire.enableDebugMessaging(level="ALL")
print('TODO make an error occur so we can see the message')
runInParallel#
- runInParallel(raiseOnError=True)#
A context manager to use for running multiple analysis in paralell. Note: This can be used only for OptiStruct Analysis.
- Parameters:
raiseOnError (bool) – If True, raise error on any failed run.
resultsFormatOptions#
- resultsFormatOptions(**kwargs)#
Params: formatType = format type: default, legacy, fixed, scientific, mixed or custom formatStr = a printf-like format string, e.g. ‘%.2f’, the format type will set to ‘custom’ if formatStr is provided
formula = a formula to be used to convert the value, by default there will be used the formula related to the result type units = the units to be used for the output, by default the current units will be used convertValue = whether the value should be converted with the given/default formula/units
showUnits = whether to show the units unitsDisplayName = the units to be shown, by default the current units will be used
width = output width (excluding units) - except legacy and custom format types precision = precision - except legacy and custom format types
stripSpaces = whether to remove leading and tailing spaces from the output removeTrailingZeros = whether to remove trailing zeroes
fixedMinMax = (min, max) values for the mixed format, to be considered to switch to scientific format