beginner question



  • On 21/08/2013 at 12:32, xxxxxxxx wrote:

    Hi guys-- C4D-Python newbie here. I'm trying to understand the relationship between variable name and base objects, if any exists at all.

    Can someone shed some light on what's happening here? In a Python Generator Object: I create a null, and place Cube ("box") under it. I place a second Cube diagonal to "box" ("box2"). If I define box2 again, this time opposite from the first definition of box2, another Cube is created.

    What's going on here? Is my original box2 essentially a left over artifact, deposited into the scene in a static manner and unable to be referenced again? Can I still access it somehow or is it essential "floating in space" as a by product of how the Generator Object relates to the timeline? I guess I expected the original box2 to be overwritten and thus removed from the scene.

    My background is in Processing, so I'm sure this is pretty straightforward.. just trying to understand.

    Thank you!

    import c4d
    #Welcome to the world of Python

    def main() :
        null = c4d.BaseObject(c4d.Onull)
        
        box = c4d.BaseObject(c4d.Ocube)
        box.InsertUnder(null)
        
        box2 = c4d.BaseObject(c4d.Ocube)
        box2.InsertUnder(null)
        box2.SetAbsPos(c4d.Vector(box[c4d.PRIM_CUBE_LEN]))
        
        box2 = c4d.BaseObject(c4d.Ocube)
        box2.InsertUnder(null)
        box2.SetAbsPos(c4d.Vector(box[c4d.PRIM_CUBE_LEN]*-1))
        
        return null



  • On 21/08/2013 at 16:23, xxxxxxxx wrote:

    Hi,

    I do not really understand what your question is ? box2 is a reference to a memory address.
    Overwriting the reference by allocating a new object does not delete the object the variable
    was referencing before. You can always regrab the object of course.

    > myoldbox = null.GetDownLast() // inverted order due to InsertUnder

    It is also more convenient to use InsertUnderLast() instead of InsertUnder()

    InsertUnder()
      
    parent
    \> child 2
    \> 
    \> child 1
    \> 
    \> child 0
      
    InsertUnderLast()
      
    parent
    \> child 0
    \> 
    \> child 1
    \> 
    \> child 2
    

    Generally speaking the python generator object is just an interface to the ObjectData.
    GetVirtualObject() method, the core method for object plugins.  The method is called 
    when c4d has to rebuild an object cache. The lifetime of the returned objects is handled 
    by c4d (c4d owns the pointed object). 
    You can always access the cache of a BaseObject by calling GetDeformCache() or 
    GetCache(). C4d returns then the reference to the full cache hierarchy. Technically you
    can modify this cache, but you should be careful, as c4d does not expect you to do so. 
    The intended way is to flag the object dirty, so that c4d calls GVO and you can rebuild 
    the cache to your needs.


Log in to reply