Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Register
    • Login

    C4D crashes when removing node via MSG_MENUPREPARE

    Cinema 4D SDK
    python
    3
    3
    472
    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.
    • merkvilsonM
      merkvilson
      last edited by

      What am I doing wrong? Need to remove the node under certain circumstances via MSG_MENUPREPARE but it crashes the C4D.
      Is it possible to somehow bypass this behavior? Is this a bug?

      
      import c4d
      import os
      
      
      class OBug_Check(c4d.plugins.ObjectData):
      
          def Message(self, node, type, data):
              if type == c4d.MSG_MENUPREPARE:
                  node.Remove()
      
              return True
      
      
      if __name__ == "__main__":
          c4d.plugins.RegisterObjectPlugin(id=1000003,
                                           str="Bug Check",
                                           g=OBug_Check,
                                           description="OBug_Check",
                                           info=c4d.OBJECT_GENERATOR,
                                           icon=None)
      
      bacaB 1 Reply Last reply Reply Quote 0
      • bacaB
        baca @merkvilson
        last edited by

        Hi @merkvilson ,
        try to add check for main thread scope:

            def Message(self, node, type, data):
                if c4d.threading.GeIsMainThread() and type == c4d.MSG_MENUPREPARE:
                    node.Remove()
        
        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by

          Hi @merkvilson I would say what you are trying to do is not well supported and MSG_MENUPREPARE was never designed for the current node to be removed.

          The correct way to do so, is to return False within your NodeData.Init method, this way the object is not created and therefor you do not have to remove it.

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

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