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? MovingTest.gh (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
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. MovingTest.gh (8.3 KB)
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…
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.
I think you mean Base here 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
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.
Nice to see you are also on Speckle!
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())
{
//...........
Print(member.Value.GetType().ToString());
// ..........
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);
element.Transform(xform);
var backToSpeckle = converter.ConvertToSpeckle(element);
objBase[member.Key] = backToSpeckle;
}
}
}
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
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.