python API : -add a marker to a model

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Fabien Leboeuf
Posts: 17
Joined: Thu Sep 20, 2007 5:26 am

python API : -add a marker to a model

Post by Fabien Leboeuf » Fri May 27, 2016 9:00 am

Hi

I have a memory issue when i want to append markers to my model.
if my model already get marker, i can use the updMarkerSet() method. then, that works fine

In my case, the model group Makerset is empty.
i add marker with this snippet

Code: Select all

            m = opensim.Marker()
            m.setOffset(opensim.Vec3(localPos[0]/toMeter,localPos[1]/toMeter,localPos[2]/toMeter))
            m.setName(label)
            m.setBodyName(osimBodyName)
            m.setFixed(False)

	    m_model.getMarkerSet().set(0,m) 
the last line works fines when I run the code once.
if i run again it. I got a memory issue. my python process stop working

what is the best way to add a marker with the python API ?

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: python API : -add a marker to a model

Post by Brad Humphreys » Tue May 31, 2016 9:13 am

Fabien,

I run into this problem periodically and I believe it has something to do with you overwriting a already instantiated reference. I can't remember how I get around that, but I do know there are some nice example code on how to create marker sets from scratch. Scroll down to "Building a MarkerSet Object Programmatically and attaching it to a Model":
http://simtk-confluence.stanford.edu:80 ... g+Commands


Brad

User avatar
Fabien Leboeuf
Posts: 17
Joined: Thu Sep 20, 2007 5:26 am

Re: python API : -add a marker to a model

Post by Fabien Leboeuf » Tue May 31, 2016 4:09 pm

Thank for your reply.

I am still waiting a reply for a whie. I appreaciate someone replied.
the problem is the method "getMarkerSet".

I can use updMarkerset, but i want to add markerset from scratch.

any idea.

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: python API : -add a marker to a model

Post by Brad Humphreys » Wed Jun 01, 2016 6:20 am

Fabien,

I'm not sure what is missing? I checked and the following works from the scripting page: creates a new marker set when one does not exist, adds a marker, them overwrites it:

Code: Select all

myModel=modeling.Model("tug_of_war.osim")
gndBody=myModel.getBodySet().get("ground")
newMarkerSet=modeling.MarkerSet()
newMarkerSet.addMarker("LASI",[0, 0, 0],gndBody)
myState=myModel.initSystem()
myModel.replaceMarkerSet(myState,newMarkerSet)
myState=myModel.initSystem()

newMarkerSet=modeling.MarkerSet()
newMarkerSet.addMarker("RASI",[0.1, 0.1, 0.1],gndBody)
myModel.replaceMarkerSet(myState,newMarkerSet)
myState=myModel.initSystem()

myModel.print(tug_of_war_withMarker.osim)

POST REPLY