Hide child of Object plugin
-
On 04/12/2017 at 02:55, xxxxxxxx wrote:
Hi,
unfortunately I saw gr4ph0s post too late and as I had written this already, I thought I'd post it nevertheless...
First, please note, the following is not possible in the same way with the Python Generator object, as the Python generator object is not registered with the OBJECT_INPUT flag.
You don't need to hide objects used as input for your ObjectData generator, explicitly. Instead register your ObjectData Generator plugin with the additional OBJECT_INPUT flag.
And then, when retrieving the caches from the input objects (e.g. in GetVirtualObjects()), these need to be marked as "touched", which is done by so called dependency lists (BaseObject functions NewDependenceList(), AddDependence(), CompareDependenceList(), TouchDependenceList()). Luckily you usually don't have to worry about these, because there's a convenience function, which basically does everything (test for changes (dirty state), return clones of input caches and mark input objects as touched) for you: GetAndCheckHierarchyClone(). Check out gr4ph0s last code snippet above for an example.This topic is also discussed in these threads:
CSTO on a Cloner
NBIT_HIDEEXCEPTVIEWSELECTAlready linked to by gr4ph0s, the BaseObject Manual in our C++ docs may also be an interesting read.
-
On 04/12/2017 at 07:39, xxxxxxxx wrote:
Thanks guys! I tested this code in my test plugin and now I included it in the main plugin. As you can see, it already works like a charm since I'm not forced to manually hide its child object by affecting its visibility flags. And cache is optimized pretty well.
Thanks again! -
On 04/12/2017 at 08:19, xxxxxxxx wrote:
Another question regarding this part of the code:
#select faces
bs = clonedObj.GetPolygonS()
bs.Select(0)when this code is included in the object plugin, it works when I'm in object/model mode but when I attempt to select the polygon mode it hides my object plugin if it's also selected. is this a bug?
-
On 05/12/2017 at 09:33, xxxxxxxx wrote:
Can you please post a bit more code? Or tell us, in which of the above examples you are working?
I'd recommend to stick with gr4ph0s' second example as it's "more complete". The first example seems to assume the input object is already a PolygonObject, which it is clearly not in your video.
Do you get any error messages on the Console? -
On 05/12/2017 at 09:47, xxxxxxxx wrote:
No, I'm not getting any errors in the console. And I'm making object editable from the plugin but this problem occurs even if I manually making it editable.
- """
- Test Plugin 0.1
- Coptright: Merk Vilson (www.patreon.com/merkvilson)
- Name-US: Test Plugin
- Description-US: Creates Test Plugins
- """
- import c4d
- from c4d import plugins
- import os
- TESTPLUGIN_ID = 1000001 #Temporary ID
- TESTPLUGIN_VALUE = 10000 #Real Slider
- class Testplugin(c4d.plugins.ObjectData) :
- def Init(self, node) :
- self.InitAttr(node, float, [TESTPLUGIN_VALUE])
- node[TESTPLUGIN_VALUE] = 10.0
- return True
- def GetVirtualObjects(self, op, hh) :
- #Get Child
- first = op.GetDown()
- if not first: return
- dic = op.GetAndCheckHierarchyClone(hh, first, c4d.HIERARCHYCLONEFLAGS_ASPOLY, False)
- if not dic["dirty"] and not op.IsDirty(c4d.DIRTY_DATA) and op.GetCache() :
- return op.GetCache().GetClone()
- obj = dic["clone"]
- #Make Editable
- res = c4d.utils.SendModelingCommand(command = c4d.MCOMMAND_CURRENTSTATETOOBJECT,
- list = [obj],
- mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
- bc = c4d.BaseContainer(),
- doc = obj.GetDocument())
- #Select faces
- bs = obj.GetPolygonS()
- bs.Select(0)
- #Extrude
- settings = c4d.BaseContainer()
- settings[c4d.MDATA_EXTRUDE_OFFSET] = op[10000]
- res = c4d.utils.SendModelingCommand(command = c4d.ID_MODELING_EXTRUDE_TOOL,
- list = [obj],
- mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
- bc = settings,
- doc = obj.GetDocument())
- return obj
- if __name__ == "__main__":
- bmp = c4d.bitmaps.BaseBitmap()
- dir, file = os.path.split(__file__)
- fn = os.path.join(dir, "res", "icon.tif")
- bmp.InitWith(fn)
- result = plugins.RegisterObjectPlugin(id = TESTPLUGIN_ID,
- str = "Test Plugin",
- g = Testplugin,
- description = "Otestplugin",
- info = c4d.OBJECT_GENERATOR | c4d.OBJECT_POLYGONOBJECT | c4d.OBJECT_INPUT,
- icon = bmp)
Download plugin: https://www.dropbox.com/s/nb80fnnxe3s77n5/Test Plugin 0.2.rar?dl=0
-
On 06/12/2017 at 04:42, xxxxxxxx wrote:
Hi,
the issue is with the registration of your ObjectData plugin. You set the OBJECT_POLYGONOBJECT flag. This flag should not be set, your ObjectData is a generator, not a simple polygon object.
Our documentation is a bit weak here, but these flags OBJECT_POLYGONOBJECT and OBJECT_POINTOBJECT just need to be used in rare cases. For example see the objectdata_latticeplanemodifier, while being a modifier, the cage is a point object.
-
On 06/12/2017 at 05:05, xxxxxxxx wrote:
Thank you! The problem is solved
Seems like C++ has better examples than python.
Are there any good courses for C++/C4D? Something like 'Python Scripting in Cinema 4D from FXPHD' -
On 06/12/2017 at 10:33, xxxxxxxx wrote:
I'm not aware of anything like the FXPHD Python tutorial for C++.
We have a bunch of links here. And well, of course these forums. Of course we can't teach C++ programming itself here, but we have a very knowledgeable and helpful community. In the end our measly SDK Support Team might also be able to help out once in a while. -
On 11/12/2017 at 19:05, xxxxxxxx wrote:
Hello again
I'm using this code by gr4ph0s in my object plugin:def GetVirtualObjects(self, op, hh) :
first = op.GetDown()
if not first: returndic = op.GetAndCheckHierarchyClone(hh, first, c4d.HIERARCHYCLONEFLAGS_ASPOLY, False)
if not dic["dirty"] and not op.IsDirty(c4d.DIRTY_DATA) and op.GetCache() :
return op.GetCache().GetClone() #Do not know why op.GetCache() fail sometime but returning a cloned works like a charm !#If we are here that mean something has changed so we need to rebuild everythings.
obj = dic["clone"]
#Do some stuff on your Obj for example an extrude, Keep in mind
#select faces
bs = obj.GetPolygonS()
bs.Select(0)#Extrude
settings = c4d.BaseContainer() # Settings
settings[c4d.MDATA_EXTRUDE_OFFSET] = 50.0 # Length of the extrusionres = c4d.utils.SendModelingCommand(command = c4d.ID_MODELING_EXTRUDE_TOOL,
list = [obj],
mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
bc = settings,
doc = obj.GetDocument())return obj
I read in docs that GetAndCheckHierarchyClone will generate new cache if something is changed but it constantly generates new cache even if nothing is changed in object plugin or in its child object.
Previously I was using this code:
child = op.GetDown() if not child: return dirty = op.CheckCache(hh) or op.IsDirty(c4d.DIRTY_DATA) or child.IsDirty(c4d.DIRTYFLAGS_DATA) if dirty is False: return op.GetCache(hh)
I tried to apply this code in conjunction with gr4ph0s' version but it hides plugin's child object only if I'm changing something in a hierarchy and if nothing is changed, the child object is visible.
is it possible to optimize the code so it could generate cache only if something in changed?
-
On 12/12/2017 at 11:15, xxxxxxxx wrote:
This goes off topic so I made a new thread about my last question.
https://developers.maxon.net/forum/topic/10513/13964_optimize-getandcheckhierarchyclone