Syntax help - Wrap Object

Discussion about scripting with Python
Realflow_22
Posts: 1
Joined: Wed Sep 12, 2018 2:38 am

Syntax help - Wrap Object

Postby Realflow_22 » Wed Sep 12, 2018 2:53 am

Hi,
Firstly, i have little scripting knowledge :-) . I came across this script on the forum and wanted to use it, but came across syntax errors that i dont know how to fix. Essentially it should wrap an object in particles ( this seems quicker than using magic as i only need it for an initial state ) Below is the script, syntax errors from line 12, any help would be appreciated.

#Enter emitter name.
emitterName = "Circle01"

#-------------------------
#DON'T TOUCH BELOW

em = scene.getEmitter(emitterName)

obs = scene.getSelectedNodes()

for eachObject in obs:

faces = eachObject.getFaces()
verts = eachObject.getVertices(REF_GLOBAL)

for eachFace in faces:
indices = eachFace.getIndices()
vertX = verts[indices[0]]
vertY = verts[indices[1]]
vertZ = verts[indices[2]]
posX = vertX.getPosition()
posY = vertY.getPosition()
posZ = vertZ.getPosition()

facePosX = (posX.getX() + posY.getX() + posZ.getX()) /3
facePosY = (posX.getY() + posY.getY() + posZ.getY()) /3
facePosZ = (posX.getZ() + posY.getZ() + posZ.getZ()) /3
facePosFinal = Vector.new(facePosX, facePosY, facePosZ)

em.addParticle(facePosFinal, Vector.new(0.0,0.0,0.0))

for each in verts:
getPos = each.getPosition()
em.addParticle(getPos, Vector.new(0.0,0.0,0.0))

em.export()
em.removeAllParticles()


User avatar
Herbert
Posts: 349
Joined: Fri Sep 08, 2006 9:19 pm
Contact:

Re: Syntax help - Wrap Object

Postby Herbert » Wed Sep 12, 2018 8:40 am

Try this:

Code: Select all

#Enter emitter name.
emitterName = "Circle01"

#-------------------------
#DON'T TOUCH BELOW

em = scene.getEmitter(emitterName)

obs = scene.getSelectedNodes()

for eachObject in obs:
    faces = eachObject.getFaces()
    verts = eachObject.getVertices(REF_GLOBAL)

for eachFace in faces:
    indices = eachFace.getIndices()
    vertX = verts[indices[0]]
    vertY = verts[indices[1]]
    vertZ = verts[indices[2]]
    posX = vertX.getPosition()
    posY = vertY.getPosition()
    posZ = vertZ.getPosition()

facePosX = (posX.getX() + posY.getX() + posZ.getX()) /3
facePosY = (posX.getY() + posY.getY() + posZ.getY()) /3
facePosZ = (posX.getZ() + posY.getZ() + posZ.getZ()) /3
facePosFinal = Vector.new(facePosX, facePosY, facePosZ)

em.addParticle(facePosFinal, Vector.new(0.0,0.0,0.0))

for each in verts:
    getPos = each.getPosition()
    em.addParticle(getPos, Vector.new(0.0,0.0,0.0))

em.export()
em.removeAllParticles()


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest