Hi everyone, I feel like I’m missing something obvious. I’m trying to create a component that serializes a list of Speckle objects and sends them to my api to perform some calculations.
How do I convert the Speckle objects, that are all from the BuiltElements objects, to Speckle Base objects?
Alright, but how do I interpret the ‘object’ as a GH_SpeckleBase? I will need to cast it to that class first to access the “Value” attribute I assume. However, I’m having trouble locating that class.
GH_SpeckleBase is our own wrapper for Base classes, and that lives on the connector project itself, so it’s not easy to access from another project.
My suggestion would be to just check if it is a GH_Goo<Base> instead, which is the direct parent of GH_SpeckleBase.
var shape_list = new List<object>();
if(!DA.GetDataList(0, shape_list)) return;
// Now shape_list is of objects, could be anything really at this point
for (var shape in shape_list) {
// Check for valid cast in a one-liner condition
if ( shape is GH_Goo<Base> baseGoo ) {
// If it's a GH_Goo<Base> it's value is directly typed so the following should work 👇🏼
Base actual_base = baseGoo.Value;
Console.WriteLine(actual_base.speckle_type);
continue;
}
// The object is not a Base object, do whatever with it, such as displaying a warning
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Object must be a Speckle Base Object")
}
Do note that I wrote this code directly on the forum text editor so there may be a typo or 2… but I hope you get the gist of it!
Let me know if that doesn’t work, we’ll be happy to look further into your use-case to enable what you want to achieve