Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
-
Aaron Henry
- Posts: 32
- Joined: Tue Dec 03, 2019 8:47 am
Post
by Aaron Henry » Tue Jul 06, 2021 8:43 am
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.
Tags:
-
Ayman Habib
- Posts: 2252
- Joined: Fri Apr 01, 2005 12:24 pm
Post
by Ayman Habib » Tue Jul 06, 2021 9:00 am
Hi Aaron,
The call
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
-
Aaron Henry
- Posts: 32
- Joined: Tue Dec 03, 2019 8:47 am
Post
by Aaron Henry » Tue Jul 06, 2021 10:42 am
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