Karamba3D get local coordinate system of element in C#

Hello,

I have been trying to find a way to retrieve the plane representing the local coordinate system of an element using C# (looking for the same output as the GH-component Disassemble Element - LCoSys). I hope somebody could help me!

I found several leads in the API documentation:

  • the method “BuilderElement.disassembleElement”. This seems to return the things I need, but I have no clue how this BuilderElement class relates to the ModelElement class-elements that I can grab from Models.Model.Elements(). How do I access the BuilderElement properties and methods for ModelElement objects?
  • I found that the ElementState class has a property called .Coosys. But there doesn’t seem to be a method like “GetElementStates”. Only thing I found is the .GetCrossSectionsStates_OLD, that returns objects of class ElementState_OLD. This does work but considering the “OLD” extension I have the feeling this is not the way to go.
  • I also tried this piece of code, but it returns Null Planes:

var model = modelIn as Model;
IEnumerable elem = model.Elements();
List listofPlanes = new List();
foreach (ModelElement e in elem)
{
Vector3? vecNullX = e.x_ori;
Vector3 vec3X = vecNullX.GetValueOrDefault();
Vector3d vec3dX = vec3X.Convert();

  Vector3? vecNullY = e.y_ori;
  Vector3 vec3Y = vecNullY.GetValueOrDefault();
  Vector3d vec3dY = vec3Y.Convert();
  
  Plane myPlane = new Plane(new Point3d(0, 0, 0), vec3dX, vec3dY);
  listofPlanes.Add(myPlane);
}
A = listofPlanes;

Hello @Mike_van_Houtum_ZJA,
here is an example how it can be done:
DeriveLocalCoordinateSystem_scripted.gh (10.9 KB)
This part of the Karamba3D API certainly needs to be refactured and better documented.
– Clemens

Thank you so much for the swift response!