Hi everyone, I am trying to learn how to code python by modifying the maxon scripts.
I have this basic script working as a plugin. It makes the object editable and moves the anchor point. I am trying to figure out a way to make this work with a button click instead of just clicking on the script to run it.
Can you please help me get one or two buttons to work with this code? Thank you for any guidance!
import c4d
import os
def load_bitmap(path):
path = os.path.join(os.path.dirname(file), path)
bmp = c4d.bitmaps.BaseBitmap()
if bmp.InitWith(path)[0] != c4d.IMAGERESULT_OK:
bmp = None
return bmp
import c4d
from c4d import gui
class MakeEditableAnchor(c4d.plugins.CommandData):
PLUGIN_ID = 1058020
PLUGIN_NAME = 'MakeEditableAnchor'
PLUGIN_INFO = 0
PLUGIN_ICON = load_bitmap('res/icons/makeeditableanchor.jpg')
PLUGIN_HELP = ''
def Register(self):
return c4d.plugins.RegisterCommandPlugin(
self.PLUGIN_ID, self.PLUGIN_NAME, self.PLUGIN_INFO, self.PLUGIN_ICON,
self.PLUGIN_HELP, self)
def Execute(self, doc):
gui.MessageDialog('Hello World!')
c4d.CallCommand(12236) # Make Editable
op = doc.GetActiveObject()
#op = doc.SearchObject("obj1")
ps = op.GetAllPoints() #Points in Local coordinates List
m = op.GetMg() #Object Global Matrix
center = op.GetMp() #Local coordinates center: https://tinyurl.com/wed88cn
rad = op.GetRad() # Geometry radius: https://tinyurl.com/tb6vn64
center -= c4d.Vector(0,rad.y,0) #Move down axis to lowest point. Comment this line to keep axis in a center
center *= m #Convert to Global coordinates center
new_m = c4d.Matrix(m) #Copy matrix
new_m.off = center #Change its center
loc_m = ~new_m * m #Get local matrix
op.SetAllPoints([loc_m.Mul(p) for p in ps])
op.SetMg(new_m)
op.Message(c4d.MSG_UPDATE)
c4d.EventAdd()
# Execute main()
return True
if name == 'main':
MakeEditableAnchor().Register()