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

    Calling a Tool (Naming Tool) and Modify the Parameters

    Cinema 4D SDK
    r20 python
    3
    7
    1.4k
    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.
    • B
      bentraje
      last edited by

      Hi,

      I want to rename a joint chain using the naming tool. Here is the script:

      import c4d
      
      nTool = c4d.CallCommand(1019952)
      nTool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "_L_"
      nTool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH] = "_R_"
      

      However, it gives me an error of:

      Traceback (most recent call last):
        File "scriptmanager", line 4, in <module>
      TypeError: 'NoneType' object does not support item assignment
      

      From the previous topics, I think the reason is CallCommand actually returns a NoneType. My problem is how do I modify naming tool after or store it in a variable so I can modify it accordingly.

      Thank you for looking at my problem.

      1 Reply Last reply Reply Quote 0
      • mikeudinM
        mikeudin
        last edited by

        @bentraje said in Calling a Tool (Naming Tool) and Modify the Parameters:

        CallCommand

        This method didn't returns any value.

        Checkout my python tutorials, plugins, scripts, xpresso presets and more
        https://mikeudin.net

        1 Reply Last reply Reply Quote 1
        • B
          bentraje
          last edited by

          Hi @mikeudin
          Thanks for the response. I'm not sure I get your response.

          Yes, it returns none. Is there a way to modify the settings of the naming tool?

          I also tried the following:

          import c4d
          
          nTool = c4d.GetCommandName(1019952)
          nTool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "_L_"
          nTool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH] = "_R_"
          
          

          or

          import c4d
          
          nTool =1019952
          nTool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "_L_"
          nTool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH] = "_R_"
          
          

          However, it still gives me an error.

          1 Reply Last reply Reply Quote 0
          • C4DSC
            C4DS
            last edited by C4DS

            You need to obtain the tool's data in order to be able to modify/set it.
            The callcommand just activates the tool.

            import c4d
            
            def main():
            
                # activate the command
                c4d.CallCommand(1019952)
            
                # change its settings
                nTool = c4d.plugins.GetToolData(doc, 1019952)
                nTool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "_L_"
                nTool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH] = "_R_"
            
            # Execute main()
            if __name__=='__main__':
                main()
            
            1 Reply Last reply Reply Quote 2
            • B
              bentraje
              last edited by

              @C4DS

              Thanks for the response. The GetToolData was new to me.
              Forgive me for asking again but is there a way to also script the Replace Name Button

              Here is the code is far

              import c4d
              
              def main():
              
                  # activate the command
                  c4d.CallCommand(1019952)
              
                  # change its settings
                  nTool = c4d.plugins.GetToolData(doc, 1019952)
                  nTool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "_L_"
                  nTool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH] = "_R_"
                  c4d.CallButton(nTool, c4d.ID_CA_JOINT_NAMING_REPLACE_APPLY) # This line errors out. 
              
              # Execute main()
              if __name__=='__main__':
                  main()
              

              It gives an error of TypeError: argument 1 must be c4d.BaseList2D, not c4d.BaseContainer

              Under the the Script log, whenever I click the button it returns this line
              c4d.CallButton(tool(), c4d.ID_CA_JOINT_NAMING_REPLACE_APPLY)

              So I was just thinking to replace the tool() with jus the variable nTool but I guess I was wrong

              Is there a way around this?

              Thank you

              1 Reply Last reply Reply Quote 0
              • C4DSC
                C4DS
                last edited by

                In the above code "nTool" is a BaseContainer, that won't work.

                I also found the following in the legacy forum

                import c4d
                
                def main():
                    
                    toolID = 1019952
                    c4d.CallCommand(toolID) 
                
                    tool=c4d.plugins.FindPlugin(toolID, c4d.PLUGINTYPE_TOOL)  
                    tool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "_L_" 
                    tool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH]= "_R_"
                    c4d.CallButton(tool, c4d.ID_CA_JOINT_NAMING_REPLACE_APPLY)  
                    
                    c4d.EventAdd()
                
                

                Another take on modifying the settings, since the "tool" returned from FindPlugin is a BasePlugin which is derived from BaseList2D, exactly what we need for the CallButton

                1 Reply Last reply Reply Quote 2
                • B
                  bentraje
                  last edited by

                  @C4DS

                  Works as expected. Phew! I never knew it is this complicated.

                  Thanks again. Have a great day ahead!

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