Navigation

    • Register
    • Login
    • Search
    • Categories
    1. Home
    2. orestiskon
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    orestiskon

    @orestiskon

    1
    Reputation
    13
    Posts
    40
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online
    Website youtube/orestiskon Location Germania

    orestiskon Follow

    Posts made by orestiskon

    • RE: Getting cache of a Python Generator under a Python Generator

      Update:

      def main():
          obj = op.GetDown().GetCache().GetClone()
          print obj
          return obj
      

      getting the cache before cloning does seem to work, I couldn't see the object as it was off screen before.
      Still it opens some questions such as why the clone didn't initially work; I assume I needed to insert it into the doc, which I had tried without much success (crashed cinema when I tried to evaluate the doc).

      In any case, the problem seems solved for now.

      posted in Cinema 4D Development
      orestiskon
    • Getting cache of a Python Generator under a Python Generator

      Hi all,
      using a python generator as a source for another python generator can be helpful for prototyping. But I'm having trouble getting the cache of the child generator.

      GetCache always returns me "None", and using current state to object also returns "None".

      This is a code sample:

      def main():
          obj = op.GetDown().GetClone()
          print obj.GetCache()
          return obj
      

      I tried to see if it has children or siblings with GetDown or GetNext but I get:
      "AttributeError: 'NoneType' object has no attribute 'GetDown'"

      Code with current state to object:

      def currentState(obj) :
          return c4d.utils.SendModelingCommand(c4d.MCOMMAND_CURRENTSTATETOOBJECT,[obj],c4d.MODELINGCOMMANDMODE_ALL,c4d.BaseContainer(),doc)[0]
      
      def main():
          obj = op.GetDown().GetClone()
          collapsed = currentState(obj)
          print collapsed.GetChildren() //returns []
          return collapsed
      

      In the docs there is a recursion function for the cache but I'm not sure how to use it.

      I'm trying to understand what I'm doing wrong, are there suggestions on how to achieve this?
      Here is a sample file:
      python_under_python.c4d

      posted in Cinema 4D Development
      orestiskon
    • RE: Python Generator: Getting polygon data from new generators

      Wow much obliged for all the replies everyone, it is really helpful!
      I think evaluating in a tempdocument is what I was looking for. I have another question about best practices:

      In zipit's example the original cube is removed from the temp document after use. Is there a reason to do that? Does it help with performance and/or memory management?

      posted in Cinema 4D Development
      orestiskon
    • Python Generator: Getting polygon data from new generators

      Hi all,
      I'm trying to see if I can access the polygon data from generators that I create within the Python Generator.
      E.g. the default python generator creates a cube, is it possible to print out the polygon count of that cube?

      GetCache() returns None as there doesn't seem to be any cache yet.
      What is the designated way to do this? Is CurrentStateToObject an optimal way?

      posted in Cinema 4D Development
      orestiskon
    • RE: Python Tag: Matrix is always dirty? (or vice versa)

      Thanks a lot, I'll try this out.
      Unfortunately iterating through the matrices one-by-one makes it much more costly to just check for the dirty state, so I'm not sure if is practical to use this solution.
      It would be more viable if the built-in Get Dirty worked, maybe that's a bug or a mistake from my side.

      posted in Cinema 4D Development
      orestiskon
    • RE: Python Tag: Matrix is always dirty? (or vice versa)

      Hi,
      yes I noticed that this happens and your suggestion is more fool-proof.
      But the issue is that moData.GetDirty(c4d.MDDIRTY_ALL) doesn't increase when affecting the matrix using an Effector, or when adjusting its target object.

      posted in Cinema 4D Development
      orestiskon
    • RE: Dirty State with Python Generator

      Thanks a lot for the explanation!
      I replaced the plugin id with a user data and it seems to work ok. Still trying to figure out the matrix on the other thread though.

      Here is the adapted code:

      def main():
          ID_PYGEN_DIRTY_CACHE = op[c4d.ID_USERDATA,3]
          linked_object = op[c4d.ID_USERDATA, 2]
          # Get the last cached dirty count and the current dirty count.
          lst_dcount = ID_PYGEN_DIRTY_CACHE
          cur_dcount = linked_object.GetDirty(c4d.DIRTYFLAGS_ALL)
      
          if linked_object is None:
              return c4d.BaseList2D(c4d.Onull)
          # Return the linked object if its dirty count exceeds our cached dirty
          # count or there is no cached dirty count.
          if lst_dcount is None or lst_dcount < cur_dcount or op.GetCache() is None:
              # Cache the current dirty count.
              op[c4d.ID_USERDATA,3] = cur_dcount
              clone = linked_object.GetClone(c4d.COPYFLAGS_NO_HIERARCHY)
              clone.SetMg(c4d.Matrix())
              print "Built cache"
              return clone
          # Otherwise return the cache.
          else:
              print "Returned cache"
              return op.GetCache()
      

      And the file:
      python_dirtyState_0001.c4d

      posted in Cinema 4D Development
      orestiskon
    • RE: Python Tag: Matrix is always dirty? (or vice versa)

      Thanks a lot. I didn't notice that GetDirty gives a dirty count instead of a boolean.
      I adapted your code (very helpful!) and I used a user-data instead of a plugin id, it seems to work for normal objects, but with the Matrix I still have trouble...

      Changing the Matrix parameters does change the GetDirty, but when using an Effector that changes the matrices, even though I can read these matrices from the MoData, the GetDirty doesn't increase the count, at least with the "MDDIRTY_ALL" flag.

      In the documentation it says for the "MDDIRTY_DATA":
      "Data in the arrays changed, must be manually set."
      But I'm not sure what it means by "manually set. I assume it refers to when manually setting the array data? What happens when using an effector or changing a target object?

      This is the current code:

      def main():
          dirty_storage = op[c4d.ID_USERDATA,1]
          moData = mo.GeGetMoData(op.GetObject())
          # Get the last cached dirty count and the current dirty count.
          lst_dcount = dirty_storage
          cur_dcount = moData.GetDirty(c4d.MDDIRTY_ALL)
          print "dirty count: " + str(cur_dcount)
          
          # count or there is no cached dirty count.
          if lst_dcount < cur_dcount:
              op[c4d.ID_USERDATA,1] = cur_dcount
              print "dirty"
          else:
              print "not dirty"
      

      And the file:
      matrix_dirty_0001.c4d

      posted in Cinema 4D Development
      orestiskon
    • Python Tag: Matrix is always dirty? (or vice versa)

      In continuation with my exploration of how to use the dirty state in python, I'm trying to check a Matrix object's dirty state with a python tag.

      If I check the MoData for dirty state, then it's ALWAYS dirty, no matter which flag I use.
      If I check the BaseObject's cache for dirty state, then it's ALWAYS not dirty.

      Am I doing something wrong here?
      My end goal is to get the Matrix' dirty state when its target spline is changing.
      Code and file attached:

      • Checking Matrix' MoData. I'm using the Count flag as the count is definitely not changing under any circumstances, but it still comes out positive.
        Result: Always Dirty
      import c4d
      from c4d.modules import mograph as mo
      
      def main():
          moData = mo.GeGetMoData(op.GetObject())
          if moData.GetDirty(c4d.MDDIRTY_COUNT):
              print "object is dirty"
          else:
              print "not dirty"
      
      • Checking Matrix as BaseObject:
        Result: Always not Dirty
      import c4d
      
      def main():
          obj = op.GetObject()
          if obj.IsDirty(c4d.DIRTYFLAGS_CACHE):
              print "object is dirty"
          else:
              print "not dirty"
      

      matrix_dirty.c4d

      posted in Cinema 4D Development
      orestiskon
    • RE: Dirty State with Python Generator

      Hi Zipit, thanks for the reply.

      The Optimized Cache is off.
      I isolated the dirty check code since I couldn't get that part to work.

      Your example works for a child, if I replace it with a link as in my case, then it doesn't work.

      def main():
          linked_object = op[c4d.ID_USERDATA,2]
          # No linked object
          if linked_object is None:
              return c4d.BaseList2D(c4d.Onull)
          # Return the linked object if it is dirty or if op has not build any caches yet.
          if linked_object.IsDirty(c4d.DIRTYFLAGS_ALL) or op.GetCache() is None:
              # Consume the dirty flag of the linked object.
              linked_object.Touch()
              # Get a clone of the linked object, as we cannot insert the same node twice
              # into the document (Cinema has a mono-hierarchical graph).
              clone = linked_object.GetClone(c4d.COPYFLAGS_NO_HIERARCHY)
              # Center / align the clone to the Python generator object.
              clone.SetMg(c4d.Matrix())
              print "Build cache"
              return clone
          # Otherwise return the cache.
          else:
              #print "Returned cache"
              return op.GetCache()
      

      Maybe the python generator can only dirty check its children? Or perhaps the links need special handling?

      posted in Cinema 4D Development
      orestiskon