PY4D Code "am leben" halten

Hei cool, das funktioniert, super danke ! :)
Man muss also ersteinmal das Partikelsystem des Documents erhalten, von welchem aus man dann Partikel beeinflussen kann. 'partikelsystem' ist also ein Objekt der Klasse 'TP_Master'.

Dankeeschön. ;)
PS: nicht immer die main vergessen. Wenn einen Skript posten, dann einen der auch funktioniert ;)
Code:
import c4d
from c4d.modules import thinkingparticles
 

def main():
    partikelsystem = doc.GetParticleSystem()
     
    partikelsystem.AllocParticles(1)
     
    print partikelsystem.IsBorn(0)
    vector = c4d.Vector()
    vector.x = 40
    vector.y = 80
    vector.z = 100
     
    partikelsystem.SetPosition(0,vector)


Hehe, können wir machen ;-)
Habe ja schon etwas Erfahrung mit Programmiersprachen, ich merke wie mir das den Einstieg erleichtert. :)
Falls es dich (oder einen stillen Mitleser ;-) ) interessiert, wie es gemacht wurde: Hier der Code für ein simples Klonobjekt (für den Python Generator).
Der Code ist kommentiert damit Anfänger verstehen, was
passiert.

Code:
### Simple Cloner for Py4D - Python Generator
### Written & Commented by Niklas Rosenstein
### Contact: contact@nux95.com
### OpenSource - All rights reserved
### Last Update: 02/21/2011 1:25 PM
################################################
################################################
# We first need to import c4d itself
# because it contains all basic classes well need.
# We do this using 'import [module]'

import c4d



# Then we usually declare global variables.
# In this case we don't need any.

# Since the Python Generator can only
# generate *one* Object, we have to think
# in hierarchies. We'll create a function
# which creates the Object's clones under
# a NullObject. We can finally return this
# NullObject to the PythonGenerator

def CreateClones(ref,cnt,off):       # later we need to overload the referenceobject [ref], the anmount of clones [cnt] and the offset per clone [off]
    null = c4d.BaseObject(c4d.Onull)

    for i in xrange(cnt):            # Repeats the following Code while i is smaller than cnt. i starts from 0 and will be set i+1 at the end of the codeblock.
        obj = ref.GetClone()
        obj.SetAbsPos(c4d.Vector(off.x*i,off.y*i,off.z*i))
        obj.InsertUnder(null)
    return null

# Now that we've created the function for cloning the refernce,
# we can create the main function, which
# is the only function being called while
# C4D executes the PythonGenerator.
# But in this mian()-function, we can call other functions. ;)´

def main():
    # To obtain the UserData of the PythonGenerator,
    # the Syntax looks like this: obj[c4d.ID_USERDATA, ID]
    # while ID is the ID of the UserData we want to obtain
    # and obj is the Object which has got the UserData on it

    # [op] is the PythonGenerator itself

    cnt = op[c4d.ID_USERDATA, 1]
    offx = op[c4d.ID_USERDATA, 4]
    offy = op[c4d.ID_USERDATA, 5]
    offz = op[c4d.ID_USERDATA, 6]
    off = c4d.Vector(offx,offy,offz)

    # Now that we've defined the count- & offsetvariable
    # We still need to create the variable for the reference
    # to overload it the CreateClones() function.
    # Of course it's not the PythonGenerator that should be
    # cloned, so we can't use op. As in the MoGraph Cloner
    # we want the childobject beeing cloned. We can obtain this
    # by using op.GetDown()
    # Also, if there is no childobject, nothing should be cloned
    # so the hole execution should be stopped
	
    ref = op.GetDown()
    if ref is None:
        return;            # returns None, the Generator will generate nothing

    # Now we can execute the CreateClones() function and
    # return its return, the NullObject with the Clones under it,
    # to the PythonGenerator

    clones = CreateClones(ref,cnt,off)
    return clones

Und hier die Szenen Datei mit den enthaltenen Benutzerdaten
http://www.file-upload.net/download-3232208/Simple-Cloner.c4d.html

lg nux
 
Zuletzt bearbeitet:
Zurück