Recomputing all the solution

Hi there,
I am looping inside a Base object converting the geometries, applying the translation and converting back to Speckle, and updating the object.
The problem I am having is that if I change the value of the translation the object is not updating, I tried expiring the component but I have to recompute the entire solution to have the changes.
Any suggestions? (8.3 KB)

Some examples of this type could be useful for a quick start and help to dig in the documentation and the structure, if they already exist I didn’t find them :slight_smile:

1 Like

It looks like using ShalloCopy solved the problem, and looking at your code I was able to traverse the object model, but not completely, I am missing one hierarchical level, and I don’t see how it happen, because I see it is passing all the members.
Here is the code. (8.3 KB)

Thanks for the help!

1 Like

Hi Mirco, just had a quick look.

I think in order to go thrugh all nested levels you’d need a recursive function.

recursiveFun (obj){
	if(obj is List)
		foreach(subObj in obj)


In regards to having to use the ShallowCopy I think that’s a limitation of GH, @AlanRynne might be able to suggest better alternatives!

As an additional thought, if you kept your data as a data tree before applying the translation you wouldn’t need the C# script at all, and could use native GH components to apply it. You could then convert them to Speckle afterwards…

Ciao Matteo, thank for the message.
I am using a recursive function to dig into the object, but I’ll take a better look.

Regarding this point.
Probably I posted a wrong example, but the team is working with modularised grasshopper definitions that only take an SpeckleObject as input they do some operations and they spit out the SpeckleIObject updated.
So I would like to avoid to explode the object using ExpandSpeckleObject operate on all the geometries and re-compose the object when, I have an unique transformation to do.
This is what I am talking

The central part is where the transformation happen but to operate on that I have to find all the geometries and re-composing , this also mean that if the object change this definition has to adjust for the changes, instead if I travers the model and operating to all the geometry at once it will remove this definition and potential errors in adjusting the definition or re-composing object with the new changes.
But every ideas or advice are welcome.

Ah ok! I based my answer on the sample gh script :slight_smile:

I think you mean Base here :wink: anyways, we’d need to understand a bit more about your use case to suggest a better workflow!

In general:

  • Speckle classes are DTO (data transfer objects), designed as simple data containers used when transferring data from A to B
  • Grasshopper is a data wrangling tool designed to work with its native types

So, typically this is what I’d recommend:

  • data is generated somewhere > data is sent to GH & converted to native via Speckle > data is transformed > data is converted back to Speckle and sent out

For this process to be more efficient you could also look at creating your own Kit and specific components that handle your custom data types.

  • data is generated somewhere > data is sent to GH & converted to native via Speckle > data is transformed > data is converted back to Speckle and sent out

and this exactly the process is happanening into the GH C# node, data will be received, the component will traverse the object, converting to native, applying a transformation, converting back to Speckle and sent to the next step.
I am just bringing all the steps into one node instead of exploding everything as shown in the screenshot.
But I am happy to have a conversation on the workflow :wink:

For traversing the model, I used the same code you are using for converting to native in Grasshopper, but maybe is due to the data tree that I am feeding, I’ll check it.
Regarding the Kit is something I was thinking about when the project will be more mature, but I started to look at the possibility.

I think you mean Base here :wink: anyways,

Yeah sorry, I like to be creative with the names :rofl:

Ciao Mirco!

Nice to see you are also on Speckle! :slight_smile:
I had a quick look at your definition.
It seems that you are modifying the original input speckle object. I agree with @teocomi to always use ShallowCopy to ensure the gh cascade workflow.

If you print the type of member.Value:

Speckle.Core.Models.Base objBase = B as Speckle.Core.Models.Base;
    foreach (dynamic member in objBase.GetMembers().ToList())
// ..........
      if(member.Value is IList)
        foreach(dynamic item in member.Value)
          if(!converter.CanConvertToNative(item as Speckle.Core.Models.Base)) continue;
          var element = converter.ConvertToNative(item);
          var backToSpeckle = converter.ConvertToSpeckle(element);
          objBase[member.Key] = backToSpeckle;

…you see something is going wrong. You should have all Lists but you have Plane objects there.

The Origin of your Planes are not updated for 2 reasons

  1. because you are changing the original object
  2. because you are re-assigning to what was a list, the value of its last list item (plane).

(if you add a list with more than 1 value to the grids you will notice it!)

I hope this helps.
The workflow you mention, in general, is possible! :slight_smile:


Thanks Tabe! Yes, and @sonomirco happy to schedule a call to have a better look at your workflow if you’d like :boom:

Ciaoo @iltabe
Sorry guyes, I didn’t update the conversation yesterday, but the problem was in one line of code, I wasn’t capturing the result of the recursion :rofl:
So now all the steps in the green box are captured into that single component.

Probably this is not necessary, because you know a better way to extract the geometries modified and update the Base, but this is what I was describing and trying to simplify. (36.1 KB)

@teocomi happy to have a chat when you want.
@iltabe thanks for the message and we should catch up at some point :wink:

1 Like

Awesome, thanks for sharing this!

After our conversation, I opened a ticket to include the traverse function in Core (or maybe Objects)?

Not sure what the best place would be, but feel free to keep an eye on this issue and add your comments if you have them :slight_smile:

1 Like