Page 1 of 1

get_attached_geometry Crashes Python Kernel

Posted: Tue Jul 06, 2021 8:43 am
by ahenry
Hello,
I am currently trying to print the scale factors of a scaled model through the Python API. I have attempted to run the following script:

Code: Select all

model = osim.Model(scaled_model_path)
body = model.getBodySet().get(0)
geometry = body.get_attached_geometry(0)
factors = geometry.get_scale_factors()
The python kernel dies every time I call the get_attached_geometry() method. I have not had any issues with calling other methods from the body object and can manually open the scaled model to view the scale factors, so I know there is no issue with the model file.

Re: get_attached_geometry Crashes Python Kernel

Posted: Tue Jul 06, 2021 9:00 am
by aymanh
Hi Aaron,

The call

Code: Select all

body.get_attached_geometry(0)
assumes that there are actually some Geometry items attached to the body and that you're getting the first one of them. If that's not the case you're indexing out of bounds and a crash is not surprising. I would not call get_attached_geometry(n) unless you verify first that you have (n+1) attached pieces of Geometry due to zero indexing (e.g. using

Code: Select all

getProperty_attached_geometry().size()
)

Hope this helps,
-Ayman

Re: get_attached_geometry Crashes Python Kernel

Posted: Tue Jul 06, 2021 10:42 am
by ahenry
Ayman thanks for the reply. I am assuming you mean getPropertyByName('attached_geometry')? I used that function to check the size and it did return 0 which is likely why my kernel was crashing. I can confirm that each body has at least 1 attached geometry in the .osim file, but how would I call the attached geometry for bodies that only have 1 attached geometry and not n+1? Would this require me to first go through the components, then the physical offset frame and finally the attached geometry associated with that frame?
Thanks