On 26/10/2014 at 11:40, xxxxxxxx wrote:
Please, if some one can help with this code.
The issue : Every time I change a any property of the object created with this plugin, the materials get created again.
I'm new on python and c4d sdk, but I've got some help from Sebastian in this forum and I've able to achieve this code. Please, can some one help me?
------------- _ myPlugin.pyp ----------------_
import os
import sys
import c4d
from c4d import gui, plugins, bitmaps, documents
PLUGIN_ID = // I CANNOT PUBLIC THIS //
def CreateMaterialTag(name, color, light) :
# doc
doc = documents.GetActiveDocument()
#Add Mat
myMat = c4d.BaseMaterial(5703)
myMat[c4d.MATERIAL_COLOR_COLOR] = color
myMat.SetName(name)
doc.InsertMaterial(myMat)
return myMat
def GenSoftBox(op) :
if not op: return
# cube
cube = c4d.BaseObject(c4d.Ocube)
# insert cube into op
cube.InsertUnder(op)
#mat1
myTag1 = c4d.TextureTag()
myTag1[c4d.TEXTURETAG_MATERIAL] = CreateMaterialTag("SoftBoxBlack",c4d.Vector(0.01,0.01,0.05), False)
cube.InsertTag(myTag1)
# ADD TO SCENE
c4d.EventAdd()
class myPlugin(plugins.ObjectData) :
def __init__(self) :
self.SetOptimizeCache(True)
def GetVirtualObjects(self, op, hierarchyhelp) :
# Disabled the following lines because cache flag was set
# So the cache build is done before this method is called
dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
if dirty is False: return op.GetCache(hierarchyhelp)
def Init(self, op) :
GenSoftBox(op)
return True
def Message(self, node, type, data) :
if type==c4d.MSG_DESCRIPTION_COMMAND:
if data['id'][0].id==SB_ON_OFF:
print "Pushed button with command ID"
return True
def main() :
bmp = c4d.bitmaps.BaseBitmap()
dir, file = os.path.split(__file__)
fn = os.path.join(dir,"res","icon.tif")
bmp.InitWith(fn)
try:
result = plugins.RegisterObjectPlugin(
id = PLUGIN_ID,
str = "myPlugin",
g = myPlugin,
description = "myDescription",
info = c4d.PLUGINFLAG_SMALLNODE | c4d.OBJECT_INPUT,
icon = bmp
)
if (result) :
print "Plugin initialized."
except:
exctype, value = sys.exc_info()[:2]
c4d.gui.MessageDialog(value)
print str(value)
if __name__ == "__main__":
main()
I remarked the code where should look at, I believe I missing the method where the GenSoftBox() method should be called, but I really dont know what to do!!
Any help will be appreciated!! Cheers!!
BTW Sorry about my bad english.