Just wanted to share a quick snippet that allows one to get the body ID (and potentially select the body and get information about the body) from a node ID using Mechanical scripting:
Code in attachement:
my_node = meshData.NodeById( node_ID )
Find out which body the node belongs to
body_ID = my_node.BodyIds
body = DataModel.GetObjectById( body_ID )
Hi @Pernelle Marone-Hitz
Hope you've been well.
Is this only available in 2023 version?
when I attempted to use the BodyIds attribute in Ansys 2022r2, i get an error message saying: 'Node' object has no attribute 'BodyIds'.
I defined the mash as follows:
analysis = ExtAPI.DataModel.Project.Model.Analyses
dataSource = dpf.DataSources(analysis.ResultFileName)
Node was defined as so:
and here's the prompt:
'Node' object has no attribute 'BodyIds'
Just checking to see if I've missed a step.
Is there another way to achieve this?
My appologies, just found your other post on this and saw my mistake.
mesh needs to be defined like this:
Thanks for this useful post Pernelle.