I am writing a small script that will serve as a quick-access popup dialog for certain functions in C4D, using Python (relevant documentation). These functions include adding primitives, etc, and the popup itself is imported as a user script and bound to a keyboard shortcut for ease-of-use.
As the script is growing I am wanting to add a method to quickly add tags to selected objects when an option from the popup is selected, however I am having trouble executing the commands/functions necessary from within the script.
Here is a stripped back example of the script:
from c4d import gui
# Define Menu Item IDs
IDM_MENU_TITLE = c4d.FIRST_POPUP_ID
IDM_MENU1 = c4d.FIRST_POPUP_ID+1
IDM_DROPDOWN1 = c4d.FIRST_POPUP_ID+4
# Menu Creation
menu = c4d.BaseContainer()
menu.InsData(IDM_MENU_TITLE, 'Popup Dialog &d&')
add_tag_to_objs = c4d.BaseContainer()
add_tag_to_objs.InsData(1, 'Add Protection Tag') # This tag is arbitrary
dropdown_menu = c4d.BaseContainer()
dropdown_menu.InsData(1, 'Add Objects/Mograph')
dropdown_menu.InsData(c4d.Ocube, 'CMD') # Adds a Cube Primitive
dropdown_menu.InsData(1018544, 'CMD') # Adds a Cloner Object
# Show Popup Dialog
result = gui.ShowPopupDialog(cd=None, bc=menu, x=c4d.MOUSEPOS, y=c4d.MOUSEPOS)
When executed this returns the following result:
Accessing the commands that add a Cloner or Cube was simple, one can simply open the script log, add an object to the scene and then take the resulting .CallCommand() ID outputted in the log and add it to the script with the .InsData() function (as shown above). When adding tags, however, the resulting script log shows several commands being executed, in a way that I can't figure out how to replicate with .InsData() :
c4d.CallCommand(100004788, 50018) # New Tag
As a result, I can see it being necessary to define a function that loops through the selected objects in the scene whilst adding the relevant tags to them. However I cannot figure out firstly what this function should look like, and secondly how to execute it when clicking the 'Add Protection Tag' option from the popup script?
I'm still fairly new to Python scripting and C4D in general so detailed/commented answers would be much appreciated- but I'll take all the help I can get! Thanks in advance!