On 15/04/2017 at 11:52, xxxxxxxx wrote:
Hi, everyone!
Recently I build a script that create one null with one layer assigned for the c4d and now I'm trying convert this in plugin. The script runs perfect in my script manager but I have some problems when I try to convert it in plug in.
You can view the plug in code here:
----------------
Code:
import os
import sys
import c4d
from c4d import *
Plugin IDs 1000001-1000010 are reserved for development
PLUGIN_ID = 1000001
class AddNull(c4d.plugins.CommandData) :
def \__init\_\_(self) :
color_Layer=c4d.Vector(1,1,1) # Layer Color
def add_divider(self,name, color) :
root = doc.GetLayerObjectRoot()
LayersList = root.GetChildren()
names=[]
layers=[]
for l in LayersList:
n=l.GetName()
names.append(n)
layers.append((n,l))
if not name in names:
c4d.CallCommand(100004738) # New Layer
LayersList = root.GetChildren()
layer=LayersList[-1]
layer.SetName(name)
layer[c4d.ID_LAYER_COLOR] =color
else:
for n, l in layers:
if n ==name:
layer=l
break
Null = c4d.BaseObject(5140)
Null[c4d.ID_BASELIST_NAME] = "Null_01" #Name of null
Null[c4d.ID_LAYER_LINK] = layer
Null[c4d.NULLOBJECT_DISPLAY] = 14
doc.InsertObject(Null)
c4d.EventAdd()
def Execute(self, doc) :
dialog = None
if self.dialog is None:
self.dialog = add_divider("_Layer01_", color_Layer)
self.add_divider("_Layer01_", color_Layer)
if __name__ == "__main__":
icon = c4d.bitmaps.BaseBitmap()
icon.InitWith(os.path.join(os.path.dirname(__file__), "res", "Icon.tif"))
c4d.plugins.RegisterCommandPlugin(PLUGIN_ID, "Add_Null", 0, icon, "Add_Null", AddNull())
----------------
You can download the script and the plug in here:
I've been seeing some examples and the python SDK but I don't understand where is the issue because I saw different codes structures in examples and work well. It's necessary the "execute" function? Are there other ways to execute the function?
What I'm doing wrong?
I hope you can help me and thanks in advance!.
Cheers.