Syntax for LineToBeam in C#

Hi All,

I am just starting out at digging through the Karamba namespace/api.
And i am running into an issue i cannot solve:
(i have also posted this to the grasshopper3d.com forum, but this place seems to be better suited)

I would like to generate a beam from a polyline inside a C# component, and then export these elements to the GH canvas so i can assemble them there. The reason why i do not want to assemble in C# is that i want the GH components to work as building blocks, each generating a part of the structure, but to be reassembled for each project. Imagine each block represents something physical, such as a floor, or columns, or a stability core.

So i am specifically not looking to use k3d.Model.AssembleModel();
I have been able to generate a simple cross section via CroSec_Box() and prevented from it being read as Goo using Karamba.GHopper.CrossSections.GH_CrossSection()

Now I tried to do something similar for the elements using:
var k3d = new KarambaCommon.Toolkit();
k3d.Part.LineToBeam()
but I have not found a way to convert the resulting element into a proper GH element that works on the canvas (results in Goo).

Any tips would be greatly appreciated.
The code of my attempts until now:

private void RunScript(Plane pln, double h, double wTop, double wBot, double tTop, double tWeb, double tBot, object mat_in, System.Object col, Curve crv, int n, ref object D, ref object E, ref object F, ref object G)
{
// check input material
var mat = mat_in as FemMaterial;
if (mat == null)
{
throw new ArgumentException(“The input in ‘mat_in’ is not of type Karamba.Materials.FemMaterial!”);
}

// initialize karamba
var logger = new MessageLogger();
var k3d = new KarambaCommon.Toolkit();

//Create Karamba Crossection
var cs = new CroSec_Box("family", "name", "country", null, mat, h / 10, wTop / 10, wBot / 10, tTop / 10, tBot / 10, tWeb / 10, 0, 0);
cs.calculateProperties();
var croSec_out = new Karamba.GHopper.CrossSections.GH_CrossSection(cs);

//Create points and lines
var p0 = new Point3(0, 0, 0);
var p1 = new Point3(0, 0, 5);
var p3List = new List <Point3>();
p3List.Add(p0);
p3List.Add(p1);
var L0 = new Line3(p0, p1);

// line to beam
var nodes = new List<Point3>();

string info = ("test");

//Attempt 1 at creating beam:
var elems1 = k3d.Part.LineToBeam(new List<Line3>(){L0}, new List<string>(){ "B1" }, new List<CroSec>(), logger, out nodes);
//var elems1_out = new Karamba.GHopper.Elements.GH_Element(elems1);

// attempt 2 at creating beam:
var elems2 = k3d.Part.LineToBeam(new List<Line3>{L0}, new List<String>(){"B2"}, new List<CroSec>(), logger, out nodes, true, 0.1, new List<Vector3>(), new List<System.Drawing.Color>(), new List<Point3>(), true, true);
//var elems2_out = new Karamba.GHopper.Elements.GH_Element(elems2);

//attempt 3 at creating beams:
var list1 = new List<Line3>();
var list2 = new List<List<Line3>>();
list1.Add(L0);
var builderBeams = new List<BuilderBeam>();
LineToBeam.solve(new List<Point3>(), list2, true, true, 0.0, new List<Vector3>(), new List<string>{"B1"}, new List<System.Drawing.Color>(), new List<CroSec>(), true, out nodes, out builderBeams, out info);

// attempts 4 and 5.
//var elems4 = Karamba.Factories.FactoryPart.LineToBeam(new List<Line3>(){L0}, new List<string>(){"B2"}, new List<CroSec>(), logger, out nodes);
//var elems5 = Karamba.Factories.FactoryPart.LineToBeam(new List<Line3> {c0}, new List<String>(){"B2"}, new List<CroSec>(), logger, out nodes, true, 0, new List<Vector3>(),new List<System.Drawing.Color>(), new List<Point3>(), true, true);

//Output
D = elems1;
E = cs;
F = croSec_out;
G = builderBeams;

}

Hi @Joriss,
the concept behind the K3D elements is this: There are BuilderElements which are used to set up the model by plugging them into the Assemble-component. Based on these ModelElements get created which form part of the model.
The BuilderElements are those which can be wrapped via GH_Element. See this definition:
BuilderBeam_cp.gh (13.5 KB).
By the way: In Karamba3D 2.2.0 it is possible to feed the LineToBeam-component with polylines and splines.
– Clemens

Hello Clemens,

thanks for your quick response. You make it sounds so easy :smiley:
It works great now, thanks again.

Hi @cp1 ,
I have been busy building structures using the method you have described earlier, but i have run into a a question i cannot solve.
Previously I applied the crossection using: BuilderBeam.crosec = CroSec_Box;
and I applied an eccentricity using: CroSec_Box.ecce_loc = Vector3;
Now i want to change the orientation of my builderbeams, but cannot find the right class to change.
Do i need BuilderElementOrientation?
Could you give me a hint? Thanks in advance!

Hi @Joriss,
this should work:

beam = (BuilderBeam)beam.Clone();
var ori = beam.Ori.Writer;
ori.XOri = oris[0];
ori.YOri = oris[1];
ori.ZOri = oris[2];
ori.Alpha = dalpha;
beam.Ori = ori.Reader;

where oris[0…2] are the new local X-, Y-, Z-axes in global coordinates, dalpha the angle of rotation in rad about the local X-axis.

– Clemens

Hey Clemens,

Thanks for the quick response. I am I happy I asked, wouldn’t have been able to figure that out. it works like a charm now.

Thanks again, Joris