Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This notation indicates that getObjects() will only catch true objects and write them to a list, which is represented with square brackets. getSelectedNodes() does not distinguish between node types – all nodes  are written to the list and it is up to you to sort out which one you can use. Just a tip: The getType() instruction will help you out here.

Since this script should only use true objects, the getObjects() statement is the best choice. Whenever there is more than one element inside a list you have to create a loop to make them accessible. The for … in loop will perfectly serve your needs, but before it can be executed, a counter variable has to be introduced and finally incremented:

...

The next step is to get the vertices from each single_object and the individual positions. Again there is more than one element, so the next variable will be a list, too:

...

The result from this second loop is vertex_position , which is a  vector – what you receive from getPosition() is a trio of three values for the X, Y and Z coordinates, which is considered a “vector” in RealFlow. This vector will then be used as a reference for the clone objects. To proceed, an object is needed for each vertex – here it is a sphere, but you can choose any other object. Creating objects is a little bit different from adding emitters or daemons, because each object has its own statement:

...

Code Block
themeEclipse
languagepython
linenumberstrue
# Batch script

counter    = 1
objectList = scene.getObjects()

for single_object in objectList:
    vertexList = single_object.getVertices()

    for single_vertex in vertexList:
        vertex_position = single_vertex.getPosition()
        scene.addSphere()

        if (counter < 10):
            cloneObject_name= "Sphere0"+str(counter)

        else:
            cloneObject_name = "Sphere"+str(counter)

        cloneObject = scene.getObject(cloneObject_name)
        cloneObject.setParameter("Position", vertex_position)
        cloneObject.setParameter("Scale", Vector.new(0.2, 0.2, 0.2))
        counter += 1