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

    Slow response from FilterPluginList()

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 533 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/04/2014 at 11:30, xxxxxxxx wrote:

      Hi
      I made small concept of realtime-switch command for simple brush tool
      Based at py-tag at PointOp.

      It simply switches mode between smear and if Shift pressed button - for smooth mode in brush tool

      import c4d  
      from c4d import plugins  
      from c4d.gui import GetInputState  
        
      def lkmtest() :  
        bc = c4d.BaseContainer()      
        rs = GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, bc)    
        if rs and bc[c4d.BFM_INPUT_VALUE]:  
            return True      
        return False  
      def shft_pressed() :   
        bc = c4d.BaseContainer()      
        rs = GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_SHIFT, bc)    
        if rs and bc[c4d.BFM_INPUT_VALUE]:  
            return True      
        return False  
      def main() :  
        actidtool = doc.GetAction()  
        toolPlugins = plugins.FilterPluginList(c4d.PLUGINTYPE_TOOL, True)  
        if actidtool == 1016202:           
            for plugin in toolPlugins:  
                if plugin.GetName()=="Brush":                  
                    while lkmtest() :  
                        if shft_pressed() :  
                            plugin[c4d.MDATA_BRUSH_MODE]=c4d.MDATA_BRUSH_MODE_SMOOTH  
                            c4d.EventAdd()  
                            break  
                        else:   
                            plugin[c4d.MDATA_BRUSH_MODE] = c4d.MDATA_BRUSH_MODE_SMEAR  
                            c4d.EventAdd()  
                            break
      

      Small question how can to replace FilterPluginList?
      findPlugin does not work, seems

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

        On 12/04/2014 at 23:10, xxxxxxxx wrote:

        FindPlugin works
        another version, switch between smooth and surface modes

        import c4d  
        from c4d import plugins  
        from c4d.gui import GetInputState  
          
        def lkmtest() :  
          bc = c4d.BaseContainer()      
          rs = GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, bc)    
          if rs and bc[c4d.BFM_INPUT_VALUE]:  
              return True      
          return False  
        def shft_pressed() :   
          bc = c4d.BaseContainer()      
          rs = GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_SHIFT, bc)    
          if rs and bc[c4d.BFM_INPUT_VALUE]:  
              return True      
          return False  
        def main() :  
          actidtool = doc.GetAction()  
          if actidtool == 1016202:  
              tool = plugins.FindPlugin(actidtool, c4d.PLUGINTYPE_TOOL)        
              while lkmtest() :  
                  if shft_pressed() :  
                      tool[c4d.MDATA_BRUSH_MODE]=c4d.MDATA_BRUSH_MODE_SMOOTH  
                      tool.Message(c4d.MSG_TOOL_RESTART)  
                      c4d.EventAdd()  
                      break  
                  else:   
                      tool[c4d.MDATA_BRUSH_MODE] = c4d.MDATA_BRUSH_MODE_SURFACE  
                      tool.Message(c4d.MSG_TOOL_RESTART)  
                      c4d.EventAdd()  
                      break
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 13/04/2014 at 07:36, xxxxxxxx wrote:

          Is this code being used in a pyton tag. Or in your own tool plugin?
          If you're using it in a python tag. It's not working properly for me in R13.
          The problem is I'm not allowed to change a tool's attribute while the LMB is being held down.
          So what happens is the mode doesn't change until after I release the LMB. And that's too late.

          Does it work differently in later versions?
          Or are you maybe using this in a plugin instead?

          -ScottA

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

            On 13/04/2014 at 08:13, xxxxxxxx wrote:

            It works at R15
            Planning to make complex tool for tag- or tool-plugin for pyAPI
            And maybe port to CAPI or i do nothing, just for fun and improving of experience with pyAPI(i'm not programmer)

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

              On 13/04/2014 at 09:38, xxxxxxxx wrote:

              OK. Thanks.
              I guess they added multi-threading for the python tag in R15. Because it doesn't work in R13.

              FYI. Just a heads up.
              If you use c4d.EventAdd() in a python tag's code. Then you're already running in an infinite loop.
              So you don't need to use while loops to check for key presses. Using "If" statements will be enough.
              Using while loops like that, when you're already running inside of a loop, can slow down your code execution.

              -ScottA

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

                On 13/04/2014 at 10:26, xxxxxxxx wrote:

                Scott, thank you for a heads up!
                > >Using "If" statements will be enough
                found, it did not work
                that i put while, while we work with mouse and we can switch to smooth

                I removed events in second version and really speeds up

                (sorry for my english)

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