Possible for Python generator object to get a message when a linked object changes in any way?
-
I have a Python plugin (ObjectData, Generator type) that has a couple of LINK elements in the UI where the user can drag in objects from the scene. I use these objects as "templates" for the several objects I create myself in the plugin.
This works fine, if I drag in a text or text spline object, I get the desired text objects, same font, size etc. Everything works as expected!
However, if the user changes something in the referenced object, I am not notified, and thus can not update my own object. As a simple example - when the user changes the text height of the linked text object, I want to know, so I can tell C4D that I now must also update my object.
I could not find any information about this, but I am perhaps just using the wrong terminology when searching.
Could someone please push me in the right direction?
Thanks!
-
Just to be very specific - my GetVirtualObjects is rerun when the user changes the object, i.e. drags in a new object, or clears the one that was there.
But if the user changes some properties of the linked object, nothing changes. If I change one of the other properties of my object, however, it is updated.
-
Hello @Havremunken,
Thank you for reaching out to us. Your Generator object's
main
function should be called when you change the data container of the linked object. We recently talked about this subject, evaluation of object dirtiness and links, in this thread.The reason this is happening for you, is probably because you have 'Optimize Cache' enabled. See the video below to understand the difference.
-
Hi Ferdinand,
Many thanks for your thorough response! I am reading through your links and learning a lot. I think the right approach for me would be to stop using the simplified caching, and then add a check to see if my linked object is dirty. I'll try this and if it works as elegantly as it seems to, I shall be one very happy dev.
-
Hey @Havremunken,
In a Python Generator object just turning off the cache optimization and then doing nothing is a valid option.
In an object plugin which is shipped to customers one should never do that because when every plugin would do that, Cinema 4D would come to a crawl. But for a singular privately used object plugin or a Python generator, one usually can just ignore the performance penalty. It is only when you plan on creating dozens or even hundreds of unique instances of your object, or when constructing a singular cache is already quite expensive, that you really have to optimize your cache building for such a 'private' plugin.
Cheers,
Ferdinand -
Hi Ferdinand,
Yeah, I'll need to do dirty checking for sure. Not because I am shipping this to any customers (unless I can find a good licensing framework ), but because the nature of my plugin is to create quite a few objects; We could easily reach 100s or even 1000s of objects, depending on the situation.
So I implemented primitive dirty checking from one of the links you provided, and this helps a LOT with the performance - as you're mentioning, just ignoring the cache and recreating everything every time GetVirtualObjects is called would effectively kill Cinema 4D. Especially when fiddling with parameters, as the algorithm to layout all the objects I am creating is quite intensive.
So I'm using your code from this topic https://developers.maxon.net/forum/topic/14936/difficulties-to-dedect-the-right-message-data/2 to make sure I do proper dirty checking for my own generator and all linked objects before I decide to return the cache or generate all objects again. I'm not done yet, but early tests seem pretty promosing.
Now if only there was a simple way to split the large python file into multiple files, then bundle them all together for one giant python file so I wouldn't have to mess with module paths. 1000 line code files get old real fast.
Thanks again!
-