Torque (hwx.inspire)#
- class Torque(features, location=None, direction=None, magnitude=None, isRemote=False, **kwds)#
Bases:
BoundaryCondition
A torque is a twisting force.
It is a type of load and can be applied either to a face or the center of a hole, in which case it acts on the interior face of the hole.
Attribute Table# Name
Type
icon
str
Method Table# Name
Description
updatePosition
(self, m44)Update the position by multiplying input M44 matrix.
Example
from hwx import inspire # Start with an empty model model = inspire.newModel() # Alternatively, you can get an existing model # model = inspire.getModel() # Create two cylinders cyl1 = model.createSolidCylinder(location=(5, 5, 0), radius=1, height=1) cyl2 = model.createSolidCylinder(location=(5, 5, 0), radius=0.7, height=1) hollow_cylinder = inspire.geometry.booleanSubtract(targets=cyl1, tools=cyl2, keepTools=False) # Filter out the available cylindrical faces from cyl1 cylSurfaces = hollow_cylinder.getFeatures(type='FeatureCylindrical') # Alternatively, you can use the following line to get cylindrical features cylSurfaces = [feat for feat in hollow_cylinder.features if isinstance(feat, inspire.FeatureCylindrical)] # Select the first cylindrical face feature face = cylSurfaces[1] # Apply a torque load on the Cylindrical face feature torqueOnFace = inspire.Torque( features = face, #direction=[0, 0, -1],# optional, if not provided, the direction will be determined by the face normal magnitude=10.0, loadCase='current' ) circles = hollow_cylinder.getFeatures(type='FeatureCylindrical') # Filter out the available circular edges from cyl1 circles = [feat for feat in cyl1.features if isinstance(feat, inspire.FeatureCircular)] # Select the first circular edge feature edge = circles[0] # Apply a torque load on the edge feature torqueOnEdge = inspire.Torque(features=edge, magnitude=100.0, loadCase='current' ) # Display the initial torque values print("Initial torque values:") print(" Torque on face, magnitude:", torqueOnFace.magnitude) print(" Torque on edge, direction:", torqueOnEdge.direction) # Modify the torque attributes torqueOnFace.magnitude = 59.0 # How to make torque magnitude parametric # Add a model variable for torque magnitude # The default unit for torque is N*m model.variables.add(name="torqueMagnitude", type='Torque', expression=10) # Assign the variable to the torque load magnitude torqueOnFace.magnitude = "torqueMagnitude" # How to modify the torque magnitude variable model.variables.update(name="torqueMagnitude", expression=20) # How to change the torque magnitude with a string with units torqueOnFace.magnitude = "20 N*m" # How to query the existing torques from the model existing_torques = model.getChildren(type='Torque') print("Existing torques in the model:") for torque in existing_torques: print(f" Torque on {torque.features[0].name}, magnitude: {torque.magnitude}," f" direction: {torque.direction}") # How to query the torque by its name torque_by_name = model.getChild(type='Torque', name='Torque 1') # Update the view inspire.orientView(direction="top")
- property magnitude#
Returns the magnitude of the torque.
Example
from hwx import inspire # Start with an empty model model = inspire.newModel() # Create two cylinders cyl1 = model.createSolidCylinder(location=(5, 5, 0), radius=1, height=1) cyl2 = model.createSolidCylinder(location=(5, 5, 0), radius=0.7, height=1) # Boolean subtract cyl2 from cyl1 to form a hollow cylinder hollow_cylinder = inspire.geometry.booleanSubtract(targets=cyl1, tools=cyl2, keepTools=False) # Filter out the cylindrical face features from the hollow cylinder cylSurfaces = [feat for feat in hollow_cylinder.features if isinstance(feat, inspire.FeatureCylindrical)] face = cylSurfaces[1] # Apply a torque load on the cylindrical face feature using a numeric magnitude torqueOnFace = inspire.Torque( features=face, magnitude=10.0, # numeric torque magnitude (default unit N*m) loadCase='current' ) # Display the initial torque magnitude print("Initial torque magnitude (numeric):", torqueOnFace.magnitude) # --------------------------------------------------------- # Make torque magnitude parametric using a model variable # Add a model variable for torque magnitude. The default unit for torque is N*m. model.variables.add(name="torqueMagnitude", type='Torque', expression=10) # Assign the variable to the torque load magnitude torqueOnFace.magnitude = "torqueMagnitude" print("Torque magnitude after assigning model variable:", torqueOnFace.magnitude) # Modify the torque magnitude variable model.variables.update(name="torqueMagnitude", expression=20) print("Torque magnitude after updating model variable:", torqueOnFace.magnitude) # --------------------------------------------------------- # Change the torque magnitude using a string with units torqueOnFace.magnitude = "20 N*m" print("Torque magnitude after setting a string with units:", torqueOnFace.magnitude) # Update the view to reflect modifications inspire.orientView(direction="top") inspire.fitView() # Display all existing torques in the model for verification existing_torques = model.getChildren(type='Torque') print("Existing torques in the model:") for torque in existing_torques: print(f" Torque on {torque.features[0].name}, magnitude: {torque.magnitude}, " f"direction: {torque.direction}") # Optionally, query a torque load by its name torque_by_name = model.getChild(type='Torque', name='Torque 1') if torque_by_name: print("Queried torque by name:") print(f" Torque on {torque_by_name.features[0].name}, magnitude: {torque_by_name.magnitude}, f" direction: {torque_by_name.direction}") inspire.orientView(direction="isometric")
- updatePosition(m44)#
Update the position by multiplying input M44 matrix.