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;
}