I’m wondering if anyone has experienced this problem before.
I have created custom Grasshopper components that have private instances of other classes stored on them. This is super useful because it allows complex information (such as lists, dictionaries, classes, etc) to be saved and loaded with the GH file by writing/reading the data as JSON via chunks. Storing this data on the component is absolutely necessary for what I’m doing.
I just realized, through some debugging, that when you click Draw Full Names, it runs through the whole canvas and creates new instances of each component, this time drawing them with the full names. By doing this, all of the data that was stored on the initial component is lost. The sweep of the canvas does not transfer any of the private fields over. And this appears irrecoverable. Unchecking Draw Full Names appears to do the same thing.
Now, I understand from reading a few other posts that the implementation of Draw Full Names is a huge hack. But it also breaks these types of custom components.
Question #1: How does Draw Full Names create a new instance of each component? Is there some sort of Copy function on a component that can be overridden that returns a new instance? Or does it simply find the type and call the constructor? If it is as simple as overriding a Copy function, that would be fantastic.
Question #2: If I can’t override a component-specific Copy function, can I override the method that is called when Draw Full Names is handled? At a canvas level? I don’t want to override how a component itself is drawn. I want to handle this event in such a way that, when Draw Full Names is clicked, I can catch it before it loops through all of the components and creates new instances. This way, I can ensure that, at least for my components, the private fields are appropriately transferred. I feel like the answer to this would be no, as it doesn’t seem like it could be plug-in specific.
Question #3: Is there a reason why new instances of the components are created in the first place? Like I said, I understand the implementation was hacky, but creating new instances seems odd. I would never have realized this had I not put a breakpoint in my constructor and watched it get it after clicking Draw Full Names.
Thanks for any info!