Page 1 of 1

MultiJoints + Scripting

Posted: Tue Aug 03, 2010 10:00 am
by tsn
Is there a certain reason why MultiJoints aren't supported by RF's Python interface? It's not even possible to switch "Simulation" from "Inactive" to "Active".

Re: MultiJoints + Scripting

Posted: Tue Aug 03, 2010 11:56 am
by FlorianK
Hi Thomas,

just an advice- recently, I had some troubles keying/ switching "Simulation" (thus not by script but by hand) but everything was working fine when doing this on "Dyn Motion", intead,

Re: MultiJoints + Scripting

Posted: Tue Aug 03, 2010 4:18 pm
by tsn
Thanks for the tip. Unfortunately this won't help with MultiJoints, since they're obviously not implemented in the Python API, but I hope this will be changed with the next patch.

Re: MultiJoints + Scripting

Posted: Mon Aug 09, 2010 1:07 pm
by Alex
Hi Thomas,

for that specific purpose, you can use an XML import workaround:

Code: Select all

import os
import tempfile

def setMultiJointSimulation( mjname, status ):
	# Compose XML code
	xmlcode = '<?xml version="1.0" encoding="UTF-8"?>'
	xmlcode += '<!DOCTYPE rfxml><rfxml version="0.2">'
	xmlcode += '<nodes>'

	xmlcode += '<node name="'
	xmlcode += mjname
	xmlcode += '" class="MultiJoint"><parameters>'
	
	xmlcode += '<param name="Simulation"><enum_val><string>'
	xmlcode += status
	xmlcode += '</string></enum_val></param>'
	
	xmlcode += '</parameters></node></nodes></rfxml>'

	# Save to temporary file and import
	tmp = tempfile.NamedTemporaryFile(suffix=".xml", delete=False)
	tmp.write( xmlcode )
	tmp.close()

	scene.importFromXML(tmp.name,False,True)

	os.remove(tmp.name)
	scene.paint()


# Example
setMultiJointSimulation( "MultiJoint01", "Inactive" )
Hope that helps until MultiJoints are finally added for scripting.

Re: MultiJoints + Scripting

Posted: Mon Aug 09, 2010 1:59 pm
by tsn
Hi Alex,

Many thanks for this clever workaround. I've tested it and it works great.

8-)