On 10/06/2013 at 10:56, xxxxxxxx wrote:
The CallButton takes many different things: tags, tools, etc..
None of this is documented very well (if at all). So I've had to ask lots of questions about it. And create my own documentation for it.
Here's my personal notes about the CallButton() function in Python:
#These are the various plugin types and their ID's.That are used in the CallButton() function
PLUGINTYPE_ANY=0,
PLUGINTYPE_SHADER=1,
PLUGINTYPE_MATERIAL=2,
PLUGINTYPE_COFFEEMESSAGE=3,
PLUGINTYPE_COMMAND=4,
PLUGINTYPE_OBJECT=5,
PLUGINTYPE_TAG=6,
PLUGINTYPE_BITMAPFILTER=7,
PLUGINTYPE_VIDEOPOST=8,
PLUGINTYPE_TOOL=9,
PLUGINTYPE_SCENEHOOK=10,
PLUGINTYPE_NODE=11,
PLUGINTYPE_LIBRARY=12,
PLUGINTYPE_BITMAPLOADER=13,
PLUGINTYPE_BITMAPSAVER=14,
PLUGINTYPE_SCENELOADER=15,
PLUGINTYPE_SCENESAVER=16,
PLUGINTYPE_COREMESSAGE=17,
PLUGINTYPE_CUSTOMGUI=18,
PLUGINTYPE_CUSTOMDATATYPE=19,
PLUGINTYPE_RESOURCEDATATYPE=20,
PLUGINTYPE_MANAGERINFORMATION=21,
PLUGINTYPE_CTRACK=32,
PLUGINTYPE_FALLOFF=33,
PLUGINTYPE_VMAPTRANSFER=34,
PLUGINTYPE_PREFS=35,
#This example executes the Restore Selection button on a Selection Object
#Other buttons code can be found in the "../../resource/res/description/Oselection.h" file
import c4d
from c4d import *
def main() :
obj = doc.GetFirstObject()
c4d.CallButton(obj,c4d.SELECTIONOBJECT_RESTORE) #Executes the "Restore Selection" button
c4d.EventAdd()
if __name__=='__main__':
main()
Tpolygonselection
#This example executes the Restore Selection button on a Polygon Selection Tag
#Other buttons code can be found in the "../../resource/res/description/Tpolygonselection.h" file
import c4d
def main() :
obj = doc.GetActiveObject()
if obj is None: return False
tags = obj.GetTags()
for tag in tags:
if tag.GetType() == c4d.Tpolygonselection: #A Polygon Selection Tag
tag.SetBit(c4d.BIT_ACTIVE)
c4d.CallButton(tag,c4d.POLYGONSELECTIONTAG_COMMAND1) #Execute the Restore Selection button
c4d.EventAdd()
if __name__=='__main__':
main()
#This example executes the Restore Selection button on a Edge Selection Tag
#Other buttons code can be found in the "../../resource/res/description/Tedgeselection.h" file
#This uses a message to call to and execute the button
#R13++ only
import c4d
def main() :
obj = doc.GetActiveObject()
edgetag = obj.GetFirstTag() #The first tag should be an edge Selection Tag
dc = {}
dc['id'] = c4d.DescID(c4d.EDGESELECTIONTAG_COMMAND1)
edgetag.Message(c4d.MSG_DESCRIPTION_COMMAND, dc) #instead of simulating the button click, send a message to the tag, which should be thread safe
c4d.utils.SendModelingCommand(c4d.MCOMMAND_EDGE_TO_SPLINE, [obj]) #Converts the selected edges to a spline object
if __name__=='__main__':
main()
#This script executes the mirror tool options
#Only works in R13+
import c4d
from c4d import gui
def main() :
c4d.CallCommand(1019953)
tool=doc.GetAction()
tool=c4d.plugins.FindPlugin(tool, c4d.PLUGINTYPE_TOOL)
c4d.CallButton(tool, c4d.ID_CA_MIRROR_TOOL)
c4d.EventAdd()
if __name__=='__main__':
main()
#This is the shorter version
c4d.CallButton(c4d.plugins.FindPlugin(tool,c4d.PLUGINTYPE_TOOL), c4d.ID_CA_MIRROR_TOOL)
#This script executes the Naming tool options
#Only works in R13+
import c4d
from c4d import gui
def main() :
c4d.CallCommand(1019952)
tool=doc.GetAction()
tool=c4d.plugins.FindPlugin(tool, c4d.PLUGINTYPE_TOOL)
tool[c4d.ID_CA_JOINT_NAMING_REPLACE] = "Cube" #Set the text to replace
tool[c4d.ID_CA_JOINT_NAMING_REPLACE_WITH]= "fdsdf" #Set the new text
c4d.CallButton(tool, c4d.ID_CA_JOINT_NAMING_REPLACE_APPLY)
c4d.EventAdd()
if __name__=='__main__':
main()
#This code executes the Apply button from the "Apply,NewTransformation,Reset" options
import c4d
from c4d import plugins
def main() :
movedObj = doc.SearchObject("Sphere")
targetObj = doc.SearchObject("Cube")
c4d.CallCommand(c4d.ID_MODELING_TRANSFER_TOOL) #Launch the Transfer tool
tool = plugins.FindPlugin(doc.GetAction(), c4d.PLUGINTYPE_TOOL)
if tool is not None:
tool[c4d.MDATA_TRANSFER_OBJECT_LINK] = targetObj
c4d.CallButton(tool, c4d.MDATA_APPLY)
c4d.EventAdd()
if __name__=='__main__':
main()
#This example shows how to execute the buttons in the multishader shader
#Other ID's can be found in: ..\..\..\CINEMA 4D R13\modules\mograph\res\description\xmg_multi.h
import c4d
def main() :
mat = doc.GetFirstMaterial() #Get the material
shdr = mat[c4d.MATERIAL_COLOR_SHADER] #Get the shader in the color channel
c4d.CallButton(shdr, c4d.MGMULTISHADER_ADD) #Adds a new shader to the list
c4d.CallButton(shdr, c4d.MGMULTISHADER_CLEAR) #Removes the last shader from the list
c4d.EventAdd()
if __name__=='__main__':
main()
#This executes the "Copy From IRR" button in the render settings
import c4d
def main() :
rdata = doc.GetActiveRenderData()
c4d.CallButton(rdata, c4d.RDATA_FROMIRR)
c4d.EventAdd()
if __name__=='__main__':
main()
I also have lots of notes on how to execute various types of buttons in C++ too.
I had to bug Matthias with a lot of silly questions to compile them. If anyone wants them. I'll post them too. Because they aren't in the docs.
Between my C++ notes and my Python notes. I can usually (but not always) figure out how to execute almost any button.
-ScottA