SOLVED Calling a Tool (Naming Tool) and Modify the Parameters

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.

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.

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()

@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

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

@C4DS

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

Thanks again. Have a great day ahead!