Page 1 of 1

python API : -add a marker to a model

Posted: Fri May 27, 2016 9:00 am
by fabienleboeuf
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 ?

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

Posted: Tue May 31, 2016 9:13 am
by bradh
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

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

Posted: Tue May 31, 2016 4:09 pm
by fabienleboeuf
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.

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

Posted: Wed Jun 01, 2016 6:20 am
by bradh
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)