Grasshopper

algorithmic modeling for Rhino

Hi,
I would like to do a deep copy of D_Element class in output of GH component.
It always works only for first time (until I call GrasshoperUnloadPlugin command from Rhino console for other debugging).
In the attached pictures there is error message (solution exception) and main part of code.
Could anyone advise me where is the problem?
Thanks a lot!

Lukas

Views: 1429

Replies to This Discussion

Hi Lukáš,

my first guess would be that this is caused by the assembly Donkey.dll being loaded from byte arrays. This effectively makes the Runtime think it is having to deal with two different blocks of code (which it is, in fact, as every time an assembly is loaded from bytes it is considered independent).

I'd need a little more info to be able to help further... who is loading the Donkey.dll assembly? How? Is Grasshopper COFF loading enabled?

Thanks,

- Giulio
_______________
giulio@mcneel.com

PS: This touches the topic sideways: can I ask why you chose to use serialization for deep copying? Serialization like this is often used for data persistence or crossing AppDomains, but not very often to duplicate data inside the same application.

Hi Giulio,

thanks for your replay!

When debugging a code I have COFF byte arrays checked and I use Unload command to reload GH to see the changes.

I load Donkey.dll (gha) from added library (see the picture).

When I uncheck COFF in developer settings, the error disappeared but I can't debug the code (see the changes) until Rhino is restarted.

Do you know where can be the problem?

Do you know another way how to debug code? (without error)

_________________________

I find many examples for deep copy used serialization in C#, so I decided to try to do it this way.

http://stackoverflow.com/questions/129389/how-do-you-do-a-deep-copy...

I am planning to use Prototype pattern (to copy full object before changing it) which uses DeepCopy.

http://patterns.cs.up.ac.za/

Finally, I'm solving this problem:

I have an object (D_Structure) which has two Lists (collections). In the List (A) there are Nodes and in the List (B) there are Elements. Every element in List (B) contains a local List (C) (list of Nodes) which are the references of  the nodes in (A) List.

I need to Clone Nodes (A) List and don't lose the references (links) in Element local List (C). Prototype pattern solves this problem with DeepCopy. This Copies the whole instance of prototyped (D_Strutrure) class with preserved references. (picture below on the left)

So after Copy/Clone I can move the Node in (A) List and affect the Element in (B) List.

If I don't solve the problem with DeepCopy I'm thinking about another way how to do it. The picture above isn't UML diagram, but I hope it will be sufficient for understanding.

The difference from the previous one is in List (C). There aren't Nodes references any more, but it contains Integers which are the Indices of Nodes in List (A).

To link List (A) and List (C) after Cloning I need to update the variable in the Element which refers to Cloned Structure instance (does not refer to old instance). In Element using this value I can find Cloned Node in List (A) (Element instance can't get Nodes from List(A) without this value).

I think I can do it with Copy Constructor: Element(Structure this, Element elementToCopy) when cloning Elements.

Is there any interface (to implement) to solve DeepCopy or Cloning T objects in GH?

What do you think about the problem and the second way (picture on the right)? Any ideas how to do it in a different way in GH?

Thanks a lot!

Lukas

I think you are using VS2008 from the image of the text editor. This means that this video will help you. You need to make Rhino start while being controlled by VS and then you can use Edit-and-Continue. The COFF checkbox is then off.

---

I think I miss the purpose of serialization... If you are using this only in Grasshopper, isn't it enough to simply implement ICloneable on your D_Element class? I might miss the purpose of this, though.

IGH_Goo has a Duplicate() method you must implement, and this needs to make the deep copy of your object. If you implement ICloneable, you just call Clone(). Of course even easier things would be possible, like using a copy constructor, or more complex, like using serialization.

- Giulio
_______________
giulio@mcneel.com

Thanks again!

What you mean is that new Rhino always starts after rebuilding the code? I don't understand "use Edit-and-Continue". :(

To test the code I usually use some geometry from Rhino. So there is a lot of mouse clicking when you need to restart Rhino and open it with needed geometry and create testing script in Grasshopper. This is the reason why I prefer another way of debugging with COFF enabled. (maybe I can do some script to load all needed files)

---

Regarding the DeepCopy problem:

If there is the problem with debugging, it seems that I'll give up the idea of sterilization.

Some programmers recommended me the second way (use Index from List(A) in List(C)) to have a better control over the code.

---

If you like, I'll try to explain the problem which occurred in the fist way: 

This is the code how I implement Duplicate method in Structure.

I'm afraid without using serialization (with my knowledge) I can handle only this two unsatisfactory ways which are explained below. The difference between them is how they implement the Clone method.

[1] new Duplicated List (C) refers to old List(A)

[2] method Duplicates two independent new Lists without linked references between them. To link the references you must compare each Node in (C) Lists with each Node in List(A) (performance-demanding task) what I want to avoid.

The sterilization (used as DeepCopy) maintains the references between (A) and (C) Lists. (doted line) 

Edit and Continue is explained here.
Sorry, I do not understand the explanation with the figure. A sample? Or I just PM you...

- Giulio
______________
giulio@mcneel.com

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service