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
    • Login

    Python script for Rectangle Selection with options

    General Talk
    3
    4
    648
    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.
    • T
      Tennet
      last edited by Manuel

      Hi! I've tried to create a simple Python-script for switching to selections tools using my own "personal" selection settings.. but it doesn't work as I want it to.

      For example, when I select the 'Rectangle selection' tool, then I want "Tolerant Selection" to be checked by default. And 'Only Select visible' should be off.. but it doesn't work. The script doesn't change these settings if they are set to something else before.

      My script looks like this (below). Would really appreciate if someone could help me with the correct code for this (I don't understand programming, I only copy and paste the code from the Script Log..). Or point me in a direction where I can learn it. Many thanks! 🙂

      import c4d
      from c4d import documents, plugins
      #Welcome to the world of Python
      
      def main():
      
          c4d.CallCommand(12139) # Points
          c4d.CallCommand(200000084) # Rectangle Selection
          tool()[c4d.MDATA_SELECTION_TOLERANCE] = True
          tool()[c4d.MDATA_SELECTION_VISIBLE] = False
      
      
      if __name__=='__main__':
          main()
          c4d.EventAdd()()
      
      1 Reply Last reply Reply Quote 0
      • R
        rb_rodrigo
        last edited by

        Hi! always look at the python console to see where its pointing the error. if your code isnt correct it should print something

        here the fixed code.
        please compare them.

        import c4d
        from c4d import gui
        
        # Main function
        def main():
            c4d.CallCommand(12139) # Points
            c4d.CallCommand(200000084) # Rectangle Selection
            tool()[c4d.MDATA_SELECTION_TOLERANCE] = True
            tool()[c4d.MDATA_SELECTION_VISIBLE] = False
        
        # Execute main()
        if __name__=='__main__':
            main()
        
        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by

          hi,

          you didn't paste the function tool(). As @rb_rodrigo said you should always open the console (shift + F10) and have a look there. You should see something like thisNameError: global name 'tool' is not defined

          showing that you forgot to define the function tool()

              def tool():
                  return c4d.plugins.FindPlugin(doc.GetAction(), c4d.PLUGINTYPE_TOOL)
          

          your final script should look like this :

          import c4d
          from c4d import documents, plugins
          #Welcome to the world of Python
          def tool():
              return c4d.plugins.FindPlugin(doc.GetAction(), c4d.PLUGINTYPE_TOOL)
          
          def main():
          
              c4d.CallCommand(12139) # Points
              c4d.CallCommand(200000084) # Rectangle Selection
              tool()[c4d.MDATA_SELECTION_TOLERANCE] = True
              tool()[c4d.MDATA_SELECTION_VISIBLE] = False
          
          
          if __name__=='__main__':
              main()
          

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 1
          • T
            Tennet
            last edited by Tennet

            Hi Manuel and @rb_rodrigo,

            Many thanks for the tips about the Python console and help with the code. I'm a beginner (not even that!) in scripting, so much appreciated. It works as expected now!

            Cheers,
            Frederik

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