How can we define a Coordinate system with X axis point along a direction vector between two nodes
Erik Kostson
Member, Employee Posts: 209
✭✭✭✭
Say we have two nodes, 1, and 2. Using scripting, how can one define a Coordinate system with X axis point along a direction vector between two nodes (origin on 1st node)?
Tagged:
0
Best Answer

There are many ways of doing this, but one sample example below , uses 2 named selections (node 1 and 2) and the difference vector between them giving the direction of the Xaxis.
This is just an example and can be used and tailored perhaps as needed to suit purpose:
model=ExtAPI.DataModel.Project.Model # refer to Model analysis = model.Analyses[0] solution = analysis.Solution ##get 2 NS node 1 and 2 ncs1=ExtAPI.DataModel.GetObjectsByName("MYNCS1")[0] mncs1=ncs1.Location.Ids ncs2=ExtAPI.DataModel.GetObjectsByName("MYNCS2")[0] mncs2=ncs2.Location.Ids ##get mesh nodes of NS MeshData=ExtAPI.DataModel.MeshDataByName("Global") node1= MeshData.NodeById(mncs1[0]) node2= MeshData.NodeById(mncs2[0]) ## vector = node1node2 vec=[] vec[0]=node2.Xnode1.X vec[1]=node2.Ynode1.Y vec[2]=node2.Znode1.Z ## define UCS testCS = ExtAPI.DataModel.Project.Model.CoordinateSystems.AddCoordinateSystem() testCS.CoordinateSystemType = CoordinateSystemTypeEnum.Cartesian testCS.OriginX = Quantity(node1.X,"m") testCS.OriginY = Quantity(node1.Y,"m") testCS.OriginZ = Quantity(node1.Z,"m") testCS.PrimaryAxisDirection=Ansys.ACT.Math.Vector3D(vec[0],vec[1],vec[2])
Another way is by selecting to nodes graphically (1st node selection is the origin, and 2nd node is used together with 1st for the alignment):
model=ExtAPI.DataModel.Project.Model # refer to Model analysis = model.Analyses[0] solution = analysis.Solution cursel=ExtAPI.SelectionManager.CurrentSelection.Ids selectionor = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.MeshNodes) selectionor.Ids=[cursel[0]] # first node is origin testCS = ExtAPI.DataModel.Project.Model.CoordinateSystems.AddCoordinateSystem() testCS.CoordinateSystemType = CoordinateSystemTypeEnum.Cartesian testCS.OriginLocation = selectionor selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.MeshNodes) selection.Ids=cursel # both nodes needed for xaxis def. testCS.PrimaryAxisDefineBy=CoordinateSystemAlignmentType.Associative testCS.PrimaryAxisLocation=selection
Finally the above example can be extended to give some guidelines to the user on how to use it (e.g., to select 2 nodes, etc.  this is done via a text message box)
import clr clr.AddReference('System.Windows.Forms') from System.Windows.Forms import MessageBox model=ExtAPI.DataModel.Project.Model # refer to Model analysis = model.Analyses[0] solution = analysis.Solution cursel=ExtAPI.SelectionManager.CurrentSelection.Ids selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.MeshNodes) selection.Ids=cursel # both nodes needed for xaxis def. if len(selection.Ids)==2: selectionor = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.MeshNodes) selectionor.Ids=[cursel[0]] # first node is origin testCS = ExtAPI.DataModel.Project.Model.CoordinateSystems.AddCoordinateSystem() testCS.CoordinateSystemType = CoordinateSystemTypeEnum.Cartesian testCS.OriginLocation = selectionor selection.Ids=cursel # both nodes needed for xaxis def. testCS.PrimaryAxisDefineBy=CoordinateSystemAlignmentType.Associative testCS.PrimaryAxisLocation=selection else: MessageBox.Show('We need to select 2 nodes. 1st node is the CS origin and 2nd is used for the alignmnet of the CS xaxis')
0
This discussion has been closed.