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

    Automatically add effector object into In-/Exclusion User Data

    Cinema 4D SDK
    2
    5
    676
    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,
      How to automatically add effector object into In-/Exclusion User Data when the object that contain In-/Exclusion User Data is selected and I add new effector, like as Cloner object.

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

        Hi @mfersaoui, first all please or the next topic, use the Q&A New Functionality and read How to Post Questions, I've setup your topic correctly but please do it for the next time.

        Regarding your issue as background this is not the cloner that is listening for insertion of an effector, but the effector through the message (MSG_MENUPREPARE) which is responsible for adding himself in the currently selected object.

        So if you want to do this, the proper solution could be to create a SceneHook in order to a tracks scene change and new addition, but this can't be done in python since scenehook are not supported.
        So I'm afraid the only way you have is to create a MessageData plugin in order to react to EVMSG_CHANGE and iterate yourself into the scene to find what's new.

        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 mfersaoui

          @m_adam Thank you,
          Now I'm searching for how to add an Object to an In-Exclude user data. I tried with the following code but this doesn't work.

          import c4d
          
          def main():    
              effectors = op[c4d.ID_USERDATA,2]   # In/Exclude User Data
              plain = doc.GetFirstObject() # Plain object (Effector)
              effectors.InsertObject(plain, 1)
                  
              c4d.EventAdd()
          if __name__=='__main__':
              main()
          
          M 1 Reply Last reply Reply Quote 0
          • mfersaouiM
            mfersaoui
            last edited by mfersaoui

            @mfersaoui said in Automatically add effector object into In-/Exclusion User Data:

            import c4d

            def main():
            effectors = op[c4d.ID_USERDATA,2] # In/Exclude User Data
            plain = doc.GetFirstObject() # Plain object (Effector)
            effectors.InsertObject(plain, 1)
            c4d.EventAdd()
            if name=='main':
            main()

            Here is the solution for how to add an Object to an In-Exclude user data.

            import c4d
            
            def main():    
            
                plain = doc.GetFirstObject() # Plain object (Effector)
                
                inexclude = c4d.InExcludeData() #Create an InExcludeData class instance
                inexclude.InsertObject(plain,1)
                
                op[c4d.ID_USERDATA,2] = inexclude
                    
                c4d.EventAdd()
            if __name__=='__main__':
                main()
            
            1 Reply Last reply Reply Quote 0
            • M
              m_adam @mfersaoui
              last edited by

              @mfersaoui said in Automatically add effector object into In-/Exclusion User Data:

              @m_adam Thank you,
              Now I'm searching for how to add an Object to an In-Exclude user data. I tried with the following code but this doesn't work.

              import c4d
              
              def main():    
                  effectors = op[c4d.ID_USERDATA,2]   # In/Exclude User Data
                  plain = doc.GetFirstObject() # Plain object (Effector)
                  effectors.InsertObject(plain, 1)
                      
                  c4d.EventAdd()
              if __name__=='__main__':
                  main()
              

              The actual issue is that effectors = op[c4d.ID_USERDATA,2] perform a copy of the InExcludeData so that means you have to reassign the data correctly after it since you don't do the change directly from the InExcludeData of the BaseContainer.
              op[c4d.ID_USERDATA,2] = effector

              Cheers,
              Maxime.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

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