...
Now it is easy to loop through the individual elements of userSelection. A simple for … in loop will do the job. The process of checking whether rigid body dynamics is already activated or not should not be difficult, as it is simply an if-condition. Reading out the current “@ mass” value is also no mysteryIn case an object is already an active rigid body, the script will change its mass. So the body of the script could look like this:
Code Block |
---|
theme | Eclipse |
---|
language | python |
---|
linenumbers | true |
---|
|
userSelection = scene.getSelectedNodes()
for node in userSelection:
rbdState = node.getParameter("Dynamics")
if (rbdState != "RigidActive rigid body"):
node.setParameter("Dynamics", "RigidActive rigid body")
currentMass = node.getParameter("@ mass") |
...
Code Block |
---|
theme | Eclipse |
---|
language | python |
---|
linenumbers | true |
---|
|
import random
percentVariation = 10
range rangeMass = (currentMass / 100) * (percentVariation / 2)
randomValue randomMass = random.uniform(-rangerangeMass, rangerangeMass)
newMass = currentMass + randomValuerandomMass |
Info |
---|
Please note that the operation above might fail for very small mass settings! |
...
Code Block |
---|
theme | Eclipse |
---|
language | python |
---|
|
scene.message("\nActionnProcess completedfinished...\nElapsed time: "+str(diffTime)+" seconds") |
...
Code Block |
---|
theme | Eclipse |
---|
language | python |
---|
linenumbers | true |
---|
|
from time import *
import random
startTime = clock()
percentVariation = 10
userSelection = scene.getSelectedNodes()
for node in userSelection:
rbdState = node.getParameter("Dynamics")
if (rbdState != "RigidActive rigid body"):
node.setParameter("Dynamics", "RigidActive rigid body")
currentMass = node.getParameter("@ mass")
range rangeMass = (currentMass / 100) * (percentVariation / 2)
randomMass randomValue = random.uniform(-rangerangeMass, rangerangeMass)
newMass = currentMass + randomValue
randomMass
node.setParameter("@ mass", newMass)
endTime = clock()
diffTime = endTime - startTime
scene.message("\nProcess finshedfinished...\nElapsed time: "+str(diffTime)+" seconds") |
...