Modifying .osim XML file via API
Posted: Sun May 09, 2010 4:22 am
Hi, I'm fairly new to c++ and even newer to opensim, so please be gentle
I want to perform some simulations using the Stanford upper limb model in which I repeat the analysis with variations to the model (different inertia properties, scale, etc). I was thinking rather than edit the model's XML file every time I could simply use opensim's API to open the model, make changes to the model's Opensim::Model class, and then save the modified model as a new XML file.
I have written some code to do this, but it only half works. I am able to open the file and print model information to the screen. I was also able to open the model, edit the credits, and save the modifed model and the altered credits did show up in the new XML file. However when I try to change the mass properties of some of the models bodies these changes are not saved in the new XML file. I am able to read and print the modified values to the screen (and they do appear to change) but still they are not saved when I save the new XML file.
Here are the steps I use:
// Open existing XML model
Model osimModel(osim_file);
// Create a pointer to the body set
// within the osimModel class
BodySet bodyset = osimModel.updBodySet();
// Modify the mass of the "humerus" body
bodyset[bodyset.getIndex("humerus",0)].setMass(10);
// Save modified model class to new XML file
osimModel.print("model_modified.osim");
So when I take these steps, a new XML file is made, but the mass of the humerus body remains its previous value (0kg). If someone could give me a clue to what I am doing wrong then I would greatly appreciate it.
Cheers
I want to perform some simulations using the Stanford upper limb model in which I repeat the analysis with variations to the model (different inertia properties, scale, etc). I was thinking rather than edit the model's XML file every time I could simply use opensim's API to open the model, make changes to the model's Opensim::Model class, and then save the modified model as a new XML file.
I have written some code to do this, but it only half works. I am able to open the file and print model information to the screen. I was also able to open the model, edit the credits, and save the modifed model and the altered credits did show up in the new XML file. However when I try to change the mass properties of some of the models bodies these changes are not saved in the new XML file. I am able to read and print the modified values to the screen (and they do appear to change) but still they are not saved when I save the new XML file.
Here are the steps I use:
// Open existing XML model
Model osimModel(osim_file);
// Create a pointer to the body set
// within the osimModel class
BodySet bodyset = osimModel.updBodySet();
// Modify the mass of the "humerus" body
bodyset[bodyset.getIndex("humerus",0)].setMass(10);
// Save modified model class to new XML file
osimModel.print("model_modified.osim");
So when I take these steps, a new XML file is made, but the mass of the humerus body remains its previous value (0kg). If someone could give me a clue to what I am doing wrong then I would greatly appreciate it.
Cheers