Insert Nulls Sequentially, Problem [SOLVED]



  • On 25/06/2015 at 02:18, xxxxxxxx wrote:

    Hi Community,

    i just started with python (i'm a total n00b and no mathematical genius ;)) and i have a logical problem with my script. maybe someone can help me out _<_img src="http://www.c4dcafe.com/ipb/uploads/emoticons/default_smile.gif" border="0" alt=":)" title=":)" /_>_

    insert_light **creates a null_object with a light as a child. The null gets named Light.1, Light.2, Light.3...
    insert_scene **creates a null_object with a cube as a child. The null gets named Scene.1, Scene.2, Scene.3...

    the problem with my script is, that insert_light() and insert_scene() create Nulls like

    Light.1 
    Scene.2
    Light.3
    Scene.4

    But I want it like

    Light.1
    Scene.1
    Light.2
    Scene.2
    How can i rename the nulls with the same child sequentially and not all nulls? Can anyone help me with this?
    Thanks! Martin
     
    --------------------------------------------------------------------------

    import c4d
    from c4d import gui
    #Welcome to the world of Python

    def insert_light() :
        
         doc.InsertObject(c4d.BaseObject(c4d.Onull))
         doc.InsertObject(c4d.BaseObject(c4d.Olight))
              
         parent = doc.SearchObject("Null")
         child = doc.SearchObject("Light")
         child.InsertUnder(parent)
         
         ObjCount = doc.GetObjects()
         
         OTypCount = 0
         
         for i in ObjCount:
             if child.GetType() == 5102 and i.GetType() == 5140:
                OTypCount = OTypCount + 1
                parent.SetName("Light."+ str(OTypCount))
         
         c4d.EventAdd()       
         
    def insert_scene() :
        
         doc.InsertObject(c4d.BaseObject(c4d.Onull))
         doc.InsertObject(c4d.BaseObject(c4d.Ocube))
              
         parent = doc.SearchObject("Null")
         child = doc.SearchObject("Cube")
         child.InsertUnder(parent)
         
         ObjCount = doc.GetObjects()
         
         OTypCount = 0
         
         for i in ObjCount:
             if child.GetType() == 5159 and i.GetType() == 5140:
                OTypCount = OTypCount + 1
                parent.SetName("Scene."+ str(OTypCount))
         
         c4d.EventAdd()  
         
    if __name__=='__main__':
        insert_light()
        insert_scene()



  • On 25/06/2015 at 03:09, xxxxxxxx wrote:

    this is a logic error, in these 2 lines:
    if child.GetType() == 5102 and i.GetType() == 5140:
    if child.GetType() == 5159 and i.GetType() == 5140:

    you are checking child every time "which is always true" .



  • On 25/06/2015 at 03:30, xxxxxxxx wrote:

    Like this?:

    import c4d   
    from c4d import gui   
    #Welcome to the world of Python   
      
    def insert_lights_and_objects(numberOfLights) :   
              
        for i in xrange(numberOfLights) :   
            # Create the null and the light. Set the names   
            lightNull = c4d.BaseObject(c4d.Onull)   
            lightNull.SetName("Light." + str(i+1))   
            lightObj = c4d.BaseObject(c4d.Olight)   
            lightObj.SetName("Light." + str(i+1))   
            # Insert into scene   
            doc.InsertObject(lightNull)   
            lightObj.InsertUnder(lightNull)   
      
            # Create the null and the cube. Set names   
            objectNull = c4d.BaseObject(c4d.Onull)   
            objectNull.SetName("Scene." + str(i+1))   
            cubeObj = c4d.BaseObject(c4d.Ocube)   
            cubeObj.SetName("Scene." + str(i+1))   
            # Insert into scene   
            doc.InsertObject(objectNull)   
            cubeObj.InsertUnder(objectNull)   
      
        c4d.EventAdd()   
           
    if __name__=='__main__':   
        insert_lights_and_objects(5)
    


  • On 25/06/2015 at 03:38, xxxxxxxx wrote:

    Oops. Didn't see your post Mohamed :)

    -b



  • On 25/06/2015 at 03:50, xxxxxxxx wrote:

    Hi Mohamed and bonsak, thanks for your replies!!

    @yes, but i don't know how to solve this :)

    @bonsak
    thanks for your script, but it is not exactly what i want.
    everytime your script gets executed, you get the same names according to the given range number.
    what i want is that the script checks how many Scene-nulls or Light-nulls are already there in the objectmanager und changes the names of newly created nulls "incrementally" according to the count of nulls of the same "kind". mh, confusing i know ;) just like c4d does it if you create new objects of the same kind



  • On 25/06/2015 at 08:31, xxxxxxxx wrote:

    change this:
    if child.GetType() == 5102 and i.GetType() == 5140:
    to:
    if i.GetDown() and i.GetType() == 5140:
        if i.GetDown().GetType() == 5102:



  • On 25/06/2015 at 09:13, xxxxxxxx wrote:

    It works!!! Thank you so much :)


Log in to reply