setColor In Python Script

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

setColor In Python Script

Post by Brad Humphreys » Tue Dec 04, 2012 2:33 pm

I am looking for some example text in how the color of a body can me changed in a python script. The body was created using:

block.addDisplayGeometry("PART.obj")

I have tried using the DisplayGeometry class under openSim to no avail.

Thanks!

Brad

User avatar
Ayman Habib
Posts: 2235
Joined: Fri Apr 01, 2005 12:24 pm

Re: setColor In Python Script

Post by Ayman Habib » Thu Dec 06, 2012 10:44 am

Hi Brad,

The distribution include a script to set color in the GUI. If you want to set the color from a generic Python script you'd use the following code snippet:

Code: Select all

pelvis = model.getBodySet().get('pelvis')
displayer = pelvis.getDisplayer()
geometrySet = displayer.getGeometrySet() 
gi = geometrySet.get(0)
gi.setColor([1, 0, .5])
Hope this helps,
-Ayman

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

Re: setColor In Python Script

Post by Brad Humphreys » Thu Dec 06, 2012 2:18 pm

Ayman,

Thanks! Works great. IMHO, this would be a good example for documentation of the python scripting. While "color" is a bit secondary, your code snippet maps/keys well to the doxygen documentation hierarchy.

Brad

POST REPLY