Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Event for when the OM changes?

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 532 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      On 12/03/2013 at 16:51, xxxxxxxx wrote:

      Hey kids,

      I need to clean up some widgets and Basedraw stuff if/when someone deletes any objects in the OM.  This is for an ObjectData plugin.  I CAN check it in GVO but would hate to do that every cycle which seems like a waste.  Is there a document message to handle so I can have it do cleanup only when any object is deleted in the OM?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 12/03/2013 at 16:54, xxxxxxxx wrote:

        To be more specific, for example one of the things I need to do is erase references in an In_Ex list if it's parent has been deleted.  Here is what I am doing below.  I made a lil method to check if there is NONE and erase it and do some recursion to do it again until all the objects in the list are 'real'.  This works fine.  Just looking for some optimization.  Maybe there are Description flags I should be setting to do this automatically so I don't even have to do it in code?

        My code I'm using (called every GVO cycle) :

        def cleanList(self, camlist) :
                    for i in xrange(camlist.GetObjectCount()) :
                        if camlist.ObjectFromIndex(self.__doc, i) == None:
                            camlist.DeleteObject(i)
                            self.cleanList(camlist)

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 12/03/2013 at 17:11, xxxxxxxx wrote:

          c4d.plugins.nodedata.free() might be what you are looking for.

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 12/03/2013 at 17:21, xxxxxxxx wrote:

            Is this not used for when your plug-in itself is being deleted?  Looking for a message that tells me when any object (not my plug-in object) is being deleted (or changed in any way) so I can do some cleanup without having to do cleanup of my in_ex list on every cycle.

            In the same way I modify a lot of parameters only when the Update Message is sent so I'm not doing it all the time, only when people change something.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 12/03/2013 at 18:13, xxxxxxxx wrote:

              My 2c:
              K.I.S.S. and only optimize what really need optimizing.

              if not obj:
              is slightly faster than
              if obj == None:

              But even faster is not to do any check at all:
              try: except:

              And remove the thing that will build up
              any except/errors, in this case a faulty
              In/Ex List, that will be read for every cycle
              giving an error for every cycle (See print below).
              I.o.w, refresh the In/Ex List and do a break.

              So for example:

                
              for o in xrange(liscount) :   
                   listobj = inexlist.ObjectFromIndex(doc,o)   
                   try:   
                        #do things with your listobj   
                        listobj.Message(c4d.MSG_UPDATE)   
                   except:   
                        inexlist.DeleteObject(o)   
                        myplugin[c4d.MY_LIST] = inexlist # rebuild a correct list   
                        myplugin.Message(c4d.MSG_UPDATE)   
                        print 'GONE' # The error is now only printed once   
                        break # start a new cycle only if errors
              

              Cheers
              Lennart

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 12/03/2013 at 21:40, xxxxxxxx wrote:

                Hey, who're you calling S.?  😉

                Thanks, Lennart.  As usual, you are supremely wise with your input.  I forget try/Except even exists.  I'll give it a go.  Like usual, thanks for your time as you've saved my arse a number of times now.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post