Changing Object Props. / was: I quit,... [SOLVED]
-
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, documentsPLUGIN_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 myMatdef 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 Truedef 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 Truedef 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.
-
On 26/10/2014 at 12:00, xxxxxxxx wrote:
Hi,
download the sdk there are several example plugins, for example the Py-RoundedTube, which is an object plugin. I started with those and it was really helpful.
I guess your function should better be placed at GetVirtualObjects().Best wishes
Martin -
On 27/10/2014 at 02:36, xxxxxxxx wrote:
Hello,
to help us understand your issue please share more information about what you are trying to do.
An object's
Init()
[URL-REMOVED] function is not meant to be used to edit the document. It is supposed to be used to define default parameter values etc. when a new instance of this object was created. For different reasons multiple instances of an object can exist (so Init() may be called multiple times).Also, a generator plugin typically does not create objects by making them child objects of itself. A generator creates virtual child objects in
GetVirtualObjects()
[URL-REMOVED]. These virtual child objects are re-created every time the generator object becomes dirty. To use your object as a generator you must set the OBJECT_GENERATOR flag inRegisterObjectPlugin ()
[URL-REMOVED].Since GetVirtualObjects() creates virtual child objects you should not create materials in that context because creating materials means to edit the document (which you should not do in this function, see
Important Threading Information
[URL-REMOVED] andThreading
[URL-REMOVED]). So you should create the materials based on some user interaction (like pressing a button etc.).As Martin said, please take a look at the
RoundedTube example
[URL-REMOVED].best wishes,
Sebastian
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.