How do I get a joint associated with a given coordinate system?
When I get ExtAPI.DataModel.Project.Model.CoordinateSystems.Children
, I get a list that includes all the coordinate systems associated with joints in the Connections branch of the tree. Further, there doesn't seem to be a means of distinguishing between a joint coordinate system that only shows up under the associated joint in the tree and a regular coordinate system that only shows up under the Coordinate Systems branch of the tree, with the possible exception of the fact that the name for all joint coordinate systems is "Reference Coordinate System". Further, from what I can tell, the only connection between the joint and the coordinate system from the perspective of the API is by accessing joint.ReferenceCoordinateSystem
. However, I'm trying to either go the other direction (i.e., coordinate system --> joint), or at least be able to detect that the coordinate system is a child of the joint.
Answers
-
I did discover that I can access the tree structure via the following:
ExtAPI.UserInterface.GetPane(Ansys.ACT.Interfaces.Mechanical.MechanicalPanelEnum.Outline).ControlUnknown.Nodes
However, it isn't clear how to relate the items from this to the corresponding Ansys objects.
0 -
Hi @tlewis3348. How about something like this?:
joints = ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.Connections.Joint) Joint_to_RefCS = {j:j.ReferenceCoordinateSystem for j in joints} RefCS_to_Joint = {} for k, v in Joint_to_RefCS.iteritems(): RefCS_to_Joint[v] = RefCS_to_Joint.get(v, []) + [k]
1 -
@Mike.Thompson , Have you noticed this behavior? tlewis3348 is trying to export the Mechanical tree to a text file for lightweight recreation. I know you have worked on similar efforts, so maybe you already have a solution for how to handle joint coordinate systems?
1 -
@tlewis3348 , I don't think there is a way to go backwards directly from the CS to the joint. If you are looking to do that, especially at scale of lots of joints, I suggest doing an initial mapping of the data to a dictionary like this:
Joints = ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Joint) CSDict = {J.ReferenceCoordinateSystem.ObjectId:J.ObjectId for J in Joints}
Other than that... here are some undocumented ways you can get info from the tree control itself and the nodes. As with all undocumented features, use at your own risk and assume they may not work in the future.
The NodeId in this context is the API ObjectId of the object represented by the node in the tree.from os.path import * #Mechanical Tree Navigation #region def GetTreeControl(ExtAPI, Ansys): """ Get the Mechanical Tree internal control """ OutlinePane=ExtAPI.UserInterface.GetPane(Ansys.ACT.Interfaces.Mechanical.MechanicalPanelEnum.Outline) MechTreeNativeControl = OutlinePane.ControlUnknown return MechTreeNativeControl def GetNextNodeDown(N): """ Get the next node down in the tree structure acoss any level. """ NextNode = None if N.Children>0: return N.Child elif N.Next!=None: return N.Next else: while N.Next==None: N=N.Parent if N==None: return None return N.Next def GetRootNode(ExtAPI, Ansys): RootNode=GetTreeControl(ExtAPI, Ansys).Nodes[1] #Tree node index starts at 1 not 0 return RootNode def GetNodesInTreeOrder(ExtAPI, Ansys): RootNode = GetRootNode(ExtAPI, Ansys) Nodes = [RootNode] NextNode = GetNextNodeDown(RootNode) while NextNode!=None: Nodes.append(NextNode) NextNode = GetNextNodeDown(NextNode) return Nodes def GetNodeId(Node): return int(Node.key[1:]) def GetParentNodeId(Node): if Node.Parent==None: return 0 else: return int(GetNodeId(Node.Parent)) #endregion def WriteTreeSummary(ExtAPI, Ansys, FilePath=None, Delimiter=","): """ Write a summary file of the tree data Writes the nodes in the order they appear in the tree. """ Nodes = GetNodesInTreeOrder(ExtAPI, Ansys) D=Delimiter StrList = [] for N in Nodes: ParentId = GetParentNodeId(N) StrList.append(str(ParentId)+D+str(GetNodeId(N))+D+N.Text+D+N.Image+D+str(int(N.Expanded))+'\n') NodeStr = "".join(StrList) if FilePath!=None: File = open(FilePath, 'w') File.write(NodeStr) File.close() return NodeStr
1