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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Limit the number of executions of an object plugin.

    Cinema 4D SDK
    3
    5
    908
    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.
    • mfersaouiM
      mfersaoui
      last edited by m_adam

      Hello,
      I'm creating an object plugin that not need to be opened more then one time. I'm searching how to limit the open of an object plugin to only one time. I had tried via GetState() but it doesn't work.

      def get_all_objects(op, filter, output):
          while op:
              if filter(op):
                  output.append(op)
              get_all_objects(op.GetDown(), filter, output)
              op = op.GetNext()
          return output
      	
      class MyObject(c4d.plugins.ObjectData):  
          def GetVirtualObjects(self, op, hierarchyhelp):
      	doc = documents.GetActiveDocument()
      	search = get_all_objects(doc.GetFirstObject(), lambda x: x.CheckType(MY_OBJECT_ID), [])    
      		
      	if len(search) :			
      	     ...
      
      	return op.GetCache(hierarchyhelp)
      

      Thank you.

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @mfersaoui,

        It was not clear for us when you said " need to be opened more than one time" do you mean that you should have only one Object instance in the current document? in all scene?
        If that's the case you can search if there is already an object existing, and return False to the ObjectData.Init so the object will not be created.

        If it's not that then please be more specific.

        Finally, I would like to point you to in order to set up correctly a topic (I've done it for you this time, but please do it for the next one).

        • How to Post Questions especially the tagging part.
        • Q&A New Functionality.

        If you have any question, please let me know.
        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        mfersaouiM 1 Reply Last reply Reply Quote 0
        • mfersaouiM
          mfersaoui @m_adam
          last edited by

          Hi @m_adam,
          Yes I want to open only one Object instance in all scene.
          Thank you.

          Below solution :

          def get_all_objects(op, filter, output):
              while op:
                  if filter(op):
                      output.append(op)
                  get_all_objects(op.GetDown(), filter, output)
                  op = op.GetNext()
              return output
          
          def Init(self, node):
              doc = documents.GetActiveDocument()
              search = get_all_objects(doc.GetFirstObject(), lambda x: x.CheckType(MY_OBJECT_ID), [])    
              if len(search) 
                  return False
              return True
          
          def GetVirtualObjects(self, op, hierarchyhelp):
              ...
          
          1 Reply Last reply Reply Quote 0
          • S
            s_bach
            last edited by

            Hello,

            never use GetActiveDocument() in a generic function of a NodeData based plugin ( ObjectData etc.). Only use GetActiveDocument() in reaction to some user interaction in the UI.

            In certain scenarios there is no active document (e.g. Team Render Client, Command Line Renderer), so calling this function will return nothing.

            To get the BaseDocument that stores a given object, use GetDocument() . But that only works after an object has been inserted into the BaseDocument .

            See BaseDocument Manual.

            Alternatively, you could catch the message c4d.MSG_MENUPREPARE which is sent to the object when the user creates the object from the GUI. There you can do the check and return False if the object should not be created.

            See NodeData::Message() Manual and MSG PLUGINS.

            best wishes,
            Sebastian

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            mfersaouiM 1 Reply Last reply Reply Quote 0
            • mfersaouiM
              mfersaoui @s_bach
              last edited by

              @s_bach Sorry, I just saw your message. the replies notifications was disabled.
              Thank You!

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