I'm trying to write a script to move nodes on a circular selection for value dr in radial direction. I'm not so sharp with API library. Can anyone please help?
# Before running this script, select the circle edge nodes and input radial displacement dr.
# It then moves selected nodes for dr in polar coordinate system.
import math
dr = 1.0 # <-- your input (model units)
def set_node_xyz(nid, x, y, z):
# Try the most likely setter names across Mecway versions
for name in ("set_node", "set_node_pos", "set_node_coords", "set_node_coord", "set_node_position"):
if hasattr(mw, name):
getattr(mw, name)(nid, Vector(x, y, z))
return
raise Exception("Can't find a node-coordinate setter on 'mw'. "
"Try printing dir(mw) to see available functions.")
for nid in mw.selected_nodes():
p = mw.node(nid) # Vector: current node position
x1, y1, z1 = p.X, p.Y, p.Z
th = math.atan2(y1, x1) # polar angle at the node
x2 = x1 + dr*math.cos(th)
y2 = y1 + dr*math.sin(th)
set_node_xyz(nid, x2, y2, z1)
Comments
But if you do need a script, could you please format the script to "Code" in the forum otherwise indenting is lost and other things get changed.
Is it searching for a function to set node coordinates? That hasn't changed across versions. It's 3 functions:
And I don't want to edit the mesh. This is meant as a load as "Displacement". Let's say the edge of a hole moves out radially for 0,05 mm.
# Before running this script, select the circle edge nodes and input radial displacement dr. # It then moves selected nodes for dr in polar coordinate system. import math dr = 1.0 # <-- your input (model units) def set_node_xyz(nid, x, y, z): # Try the most likely setter names across Mecway versions for name in ("set_node", "set_node_pos", "set_node_coords", "set_node_coord", "set_node_position"): if hasattr(mw, name): getattr(mw, name)(nid, Vector(x, y, z)) return raise Exception("Can't find a node-coordinate setter on 'mw'. " "Try printing dir(mw) to see available functions.") for nid in mw.selected_nodes(): p = mw.node(nid) # Vector: current node position x1, y1, z1 = p.X, p.Y, p.Z th = math.atan2(y1, x1) # polar angle at the node x2 = x1 + dr*math.cos(th) y2 = y1 + dr*math.sin(th) set_node_xyz(nid, x2, y2, z1)You can do a radial prescribed displacement without a script, using formulas in Displacement like this:
If you need to adjust the distance in a script, you can create the displacement constraint in advance then set the values in the script using
mw.set_load_property(load, property, value)See Help -> API Reference for details.
The API is generally not very capable at setting loads and constraints. It can't set formula values, for instance, or create them from scratch or assign nodes to them.