Python : Script log | tool presets


#1

I don’t know a thing about python - I was under the impression that I would be able to set some tool options and then create a button to ‘run’ them essentially. At the moment I just used the following - Straight from the script log -

import c4d
from c4d import gui

def main():
    c4d.CallCommand(431000015) # Bevel
    tool()[c4d.MDATA_BEVEL_RADIUS]=10
    tool()[c4d.MDATA_BEVEL_SUB]=0
if __name__=='__main__':
    main()

I’m just wanting to create a couple of presets to apply bevels & extrudes on selected edges / faces etc. Any help would be much appreciated.

Console - NameError: global name ‘tool’ is not defined. << thats one problem along with a few others I’m sure.


#2

Hi Matt,
I think the best place to get accurate and fast scripting advice is the official Maxon Developer support website:

https://developers.maxon.net


#3

You need to declare tool first:

import c4d

def main():
    c4d.CallCommand(431000015) # Bevel4
    tool=doc.GetAction();
    tool=c4d.plugins.FindPlugin(tool, c4d.PLUGINTYPE_TOOL)
    tool()[c4d.MDATA_BEVEL_RADIUS]=10
    tool()[c4d.MDATA_BEVEL_SUB]=0
    c4d.EventAdd();

if __name__=='__main__':
    main()


#4

You could also give my Tool Presets plugin a try: http://blog.niklasrosenstein.com/2015/04/tool-presets/


#5

Thanks Sergey- all sorted now- I had another little play around with it and have the python working with some other tools also. I think I’ll work through codecademy and cineversity - just for a few small task here and there - awesome

developers.maxon.net/ good to know - thanks

I downloaded the tool preset (can’t believe I didn’t google it first) it worked for literally five minutes before I updated to the most recent version of R17 - which had a python update. Then it wouldn’t work - in the plugin manager it is there with a little python badge and a mini x on it. Maybe its me - but I restarted and still the same issue.

Thanks for the help.


#6

Thanks for letting me know, I’ll check that asap.


#7

Please re-download the plugin (in version 2.1), it should work with the latest version of R17 now.


#8

I’m stuck…
I try to get the bevel tool working on a selection of points of a (flat) polygon object. I can change the bevel settings but I can not get the bevel tool “applied” to the points.

The code I am trying now is :

import c4d
from c4d import documents, plugins

def main():
c4d.CallCommand(431000015) # Bevel4
tool = doc.GetAction();
tool = c4d.plugins.FindPlugin(tool, c4d.PLUGINTYPE_TOOL)
tool()[c4d.MDATA_BEVEL_RADIUS]=5
tool()[c4d.MDATA_BEVEL_SUB]=2
tool()[c4d.MDATA_BEVEL_DEPTH]=-1
c4d.EventAdd();

if name==‘main’:
main()

What do I need to add to this?


#9

You’ll need to execute the tool’s Apply button using code like this:

import c4d
from c4d import documents, plugins

def main():
    c4d.CallCommand(431000015) # Bevel4
    tool = doc.GetAction()
    tool = c4d.plugins.FindPlugin(tool, c4d.PLUGINTYPE_TOOL)
    tool()[c4d.MDATA_BEVEL_RADIUS]=5
    tool()[c4d.MDATA_BEVEL_SUB]=2
    tool()[c4d.MDATA_BEVEL_DEPTH]=-1   
    
    #Executes the Apply button
    c4d.CallButton(tool, c4d.MDATA_APPLY)

    c4d.EventAdd()

if __name__=='__main__':
    main()

-ScottA


#10

Thank you for taking the time to look at my c4d problem.

I ‘copy-pasted’ the code you provided and it works the way I need it.
Still so much to learn. Thanks again Mr Scott