Grasshopper

algorithmic modeling for Rhino

Hi ,

I'm developing a component with c # and I need to create a model as input (like 

componenet ModelDissemble.)

I need help ://

Thank youu 




Views: 1947

Replies to This Discussion

maybe a start:

this component takes a model, and transfers the eccentricities from the cross sections to the beams they are assigned to.

//Import SDK and Framework namespaces
using Rhino;
using Rhino.Geometry;
using Rhino.Collections;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using GH_IO;
using GH_IO.Serialization;

using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Linq;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Runtime.InteropServices;

using Karamba.Tests;
using Karamba.UIWidgets;
using Karamba.Utilities;
using Karamba.Utilities.Mappings;
using Karamba.Utilities.Mappings.Components;
using Karamba.Utilities.Components;
using Karamba.Elements;
using Karamba.CrossSections.Components;
using Karamba.CrossSections;
using feb;
using Karamba.Models;
using Karamba.Results.Components;
using Karamba.Loads.Components;
using Karamba.Exporters;
using Karamba.KDTreeCZ;
using Karamba.Models.Components;
using Karamba.Readers;
using Karamba.CrossSections.Deprecated;
using Karamba.Loads;
using Karamba.Algorithms.Deprecated;
using Karamba.Algorithms.Components;
using Karamba.Utilities.AABBTrees;
using Karamba.Materials;
using Karamba.Elements.Components;
using Karamba.Results.Deprecated;
using Karamba.Models.Deprecated;
using Karamba.Results;
using Karamba.Exporters.Deprecated;
using Karamba.Materials.Deprecated;
using Karamba.Elements.Deprecated;
using Karamba.Supports.Components;
using Karamba.Materials.Components;
using Karamba.Supports;
using Karamba.Licenses;
using Karamba.Nodes;
using Karamba.Supports.Deprecated;


//Code generated by Grasshopper(R) (except for RunScript() content and Additional content)
//Copyright (C) 2013 - Robert McNeel & Associates
[System.Runtime.CompilerServices.CompilerGenerated()]
public class Script_Instance : GH_ScriptInstance //IGH_ScriptInstance
{
#region Members
/// <summary>List of error messages. Do not modify this list directly.</summary>
private List<string> __err = new List<string>();

/// <summary>List of print messages. Do not modify this list directly, use the Print() and Reflect() functions instead.</summary>
private List<string> __out = new List<string>();

/// <summary>Represents the current Rhino document.</summary>
private RhinoDoc doc = RhinoDoc.ActiveDoc;

/// <summary>Represents the Script component which maintains this script.</summary>
private IGH_ActiveObject owner;

/// <summary>Represents the number of times that RunScript has been called within this solution.</summary
private int runCount;
#endregion

#region Utility functions
/// <summary>Print a String to the [Out] Parameter of the Script component.</summary>
/// <param name="text">String to print.</param>
private void Print(string text)
{
__out.Add(text);
}

/// <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
/// <param name="format">String format.</param>
/// <param name="args">Formatting parameters.</param>
private void Print(string format, params object[] args)
{
__out.Add(string.Format(format, args));
}

/// <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
/// <param name="obj">Object instance to parse.</param>
private void Reflect(object obj)
{
__out.Add(GH_ScriptComponentUtilities.ReflectType_CS(obj));
}

/// <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
/// <param name="obj">Object instance to parse.</param>
private void Reflect(object obj, string method_name)
{
__out.Add(GH_ScriptComponentUtilities.ReflectType_CS(obj, method_name));
}
#endregion

/// <summary>
/// This procedure contains the user code. Input parameters are provided as regular arguments,
/// Output parameters as ref arguments. You don't have to assign output parameters,
/// they will be null by default.
/// </summary>


private void RunScript(System.Object model, ref object Elems, ref object CroSecs, ref object A)
{
Karamba.Models.Model _m = model as Karamba.Models.Model;

Dictionary<string, Karamba.CrossSections.CroSec> cs_mapper = new Dictionary<string, Karamba.CrossSections.CroSec>();

List<Karamba.Elements.GrassElement> my_elems = new List<Karamba.Elements.GrassElement>();
Karamba.Elements.GrassElement my_grass_elem = null;
//int i = 0;

A = _m;


for (int i = 0; i < _m.elems.Count; i++)
//foreach (Karamba.Elements.ModelElement elem in _m.elems)
{
Karamba.Elements.ModelElement elem = _m.elems[i];
my_grass_elem = (Karamba.Elements.GrassElement) elem.clonedGrassElement();

Karamba.Elements.ModelBeam beam = elem as Karamba.Elements.ModelBeam;
if (beam != null) {
// it is a beam or truss
Karamba.CrossSections.CroSec cs = beam.crossection;
if (cs.hasEccent) {
// transfer the cross section's ecc to the actual beam
my_grass_elem.ecce_loc += cs.ecce_loc;
}

if (!cs_mapper.ContainsKey(cs.name))
{
cs = (Karamba.CrossSections.CroSec) cs.Clone();
cs.clearBeamIds();
cs.ecce_loc = new Vector3d(0.000001, 0, 0);
//cs.hasEccent = false;
cs_mapper[cs.name] = cs;
}
else
{
cs = cs_mapper[cs.name];
}
//cs.AddBeamId(elem.id);
cs.AddBeamId(i.ToString());
}

my_elems.Add(my_grass_elem);
//i++;
}


List<Karamba.CrossSections.CroSec> my_crosecs = new List<Karamba.CrossSections.CroSec>();
foreach (Karamba.CrossSections.CroSec cs in _m.crosecs) {
if ((!(cs is Karamba.CrossSections.CroSec_Beam)) && (cs != null)) {
my_crosecs.Add(cs);
}
}
my_crosecs.AddRange(cs_mapper.Values);

List<Karamba.Elements.GH_Element> out_gh_elems = new List<Karamba.Elements.GH_Element>();
foreach(Karamba.Elements.GrassElement elem in my_elems) {
out_gh_elems.Add(new GH_Element(elem));
}
Elems = out_gh_elems;

List<Karamba.CrossSections.GH_CrossSection> out_gh_cs = new List<Karamba.CrossSections.GH_CrossSection>();
foreach(Karamba.CrossSections.CroSec croSec_ in my_crosecs) {
out_gh_cs.Add(new GH_CrossSection(croSec_));
}
CroSecs = out_gh_cs;


}

//<Custom additional code>

//</Custom additional code>

}

Hi Robert, 

I have a similar question. I am modelling a component which retrieves certain CroSec properties. 

this is working until now: 

private void RunScript(object CroSec, ref object h, ref object b, ref object t, ref object A, ref object Ay, ref object Az, ref object Wely, ref object Welz, ref object Wply, ref object Wplz, ref object iy, ref object iz)
{
Karamba.CrossSections.CroSec_Beam cs = CroSec as Karamba.CrossSections.CroSec_Beam;
h = cs.height * 100.0; // height in cm
//b = cs.
//t = cs.
A = cs.A * 10000.0; // area in cm2
Ay = cs.Ay * 10000.00; // shear area y in cm2
Az = cs.Az * 10000.00; // shear area z in cm2
Wely = cs.Wely_lower * 1000000.00;// moment of resistance y in cm3
Welz = cs.Welz * 1000000.00;// moment of resistance z in cm3;
Wply = cs.Wply * 1000000.00;// plastic moment of resistance y in cm3;
Wplz = cs.Wplz * 1000000.00;// plastic moment of resistance z in cm3;
iy = cs.iy * 100.00;// radius of gyration in cm
iz = cs.iz * 100.00;// radius of gyration in cm;
}

You see that b and t are still undefined. Is there a way to retrieve the width and thickness of a square or rectangular cross section? 

Thanks

Lara

the basic cross section class does not have all properties of all different types.

you have to check if your object is of type I or Box or whatever, then you can access the members.

the script below is a script i used for checking different properties and correct naming (in my sample), you see i try to cast the objects and then see if it is null or valid ..!

private void RunScript(List<object> CroSec, double ctBiegung, double ctDruck, double ctKragarm, double Thickness, ref object Naming_, ref object Thickness_, ref object ctFail, ref object isBoxOrI, ref object h_, ref object b_, ref object ts_, ref object tg_, ref object madeNames)
{
List<int> failCtLst = new List<int>();
List<int> maxThick = new List<int>();
List<int> isBoxOrILst = new List<int>();
List<int> namingFailList = new List<int>();
List<string> madeNameList = new List<string>();

List<double> h__ = new List<double>();
List<double> b__ = new List<double>();
List<double> ts__ = new List<double>();
List<double> tg__ = new List<double>();

int failed = 0;
int isBoxOrI_ = 0;
int failedThick = 0;
int failedNaming = 0;
string madeName = "";

double h___ = 0;
double b___ = 0;
double ts___ = 0;
double tg___ = 0;

for(int i = 0; i < CroSec.Count(); i++)
{
object item = CroSec[i];
failed = 0;
isBoxOrI_ = 0;
failedThick = 0;
failedNaming = 0;
madeName = "";
Karamba.CrossSections.CroSec_I cs_i = item as Karamba.CrossSections.CroSec_I;
if (cs_i != null)
{
if (cs_i.name.Length > 0)
{
if ((cs_i.name.Substring(0, 2) == "I ") || (cs_i.name.Substring(0, 2) == "WI"))
{
double h = cs_i.height;
double b = cs_i.uf_width;
double tg = cs_i.uf_thick;
double ts = cs_i.w_thick;

h___ = h;
b___ = b;
ts___ = ts;
tg___ = tg;

// Steg
if ((h - 2 * tg) / ts >= ctBiegung) failed = 1;

// Flansche I-Träger
if ((b - 1.9 * ts) / tg / 2 >= ctKragarm) failed = 1;

// sheet metal thicknesses
if ((ts > Thickness) || (tg > Thickness)) failedThick = 1;

// naming
if (cs_i.name.Substring(0, 2) == "I ")
{
madeName = cs_i.name.Substring(0, 2) + (1000 * h).ToString() + "_" + (1000 * b).ToString() + "_" + (1000 * ts).ToString() + "_" + (1000 * tg).ToString();
if (cs_i.name != madeName) failedNaming = 1;
}
if (cs_i.name.Substring(0, 3) == "WI ")
{
madeName = cs_i.name.Substring(0, 3) + (1000 * h).ToString() + "_" + (1000 * b).ToString() + "_" + (1000 * ts).ToString() + "_" + (1000 * tg).ToString();
if (cs_i.name != madeName) failedNaming = 1;
}

isBoxOrI_ = 1;
}
}
}

if (isBoxOrI_ == 0)
{
failed = 0;
failedThick = 0;
failedNaming = 0;
madeName = "";
Karamba.CrossSections.CroSec_Box cs_box = item as Karamba.CrossSections.CroSec_Box;
if (cs_box != null)
{
if (cs_box.name.Length > 0)
{
if ((cs_i.name.Substring(0, 2) == "WB") || (cs_i.name.Substring(0, 2) == "IB"))
{
double h = cs_box.height;
double b = cs_box.uf_width;
double tg = cs_box.uf_thick;
double ts = cs_box.w_thick;

h___ = h;
b___ = b;
ts___ = ts;
tg___ = tg;

// Steg
if ((h - 2 * tg) / ts >= ctBiegung) failed = 1;

// Flansche Boxträger
if ((b - 2 * ts) / tg >= ctDruck) failed = 1;

if ((ts > Thickness) || (tg > Thickness)) failedThick = 1;

// naming
if (cs_box.name.Substring(0, 3) == "WB ")
{
madeName = cs_box.name.Substring(0, 3) + (1000 * h).ToString() + "_" + (1000 * b).ToString() + "_" + (1000 * ts).ToString() + "_" + (1000 * tg).ToString();
if (cs_box.name != madeName) failedNaming = 1;
}
if (cs_box.name.Substring(0, 3) == "IB ")
{
madeName = cs_box.name.Substring(0, 3) + (1000 * h).ToString() + "_" + (1000 * b).ToString() + "_" + (1000 * (ts / 1.5)).ToString() + "_" + (1000 * tg).ToString();
if (cs_box.name != madeName) failedNaming = 1;
}

isBoxOrI_ = 1;
}
}
}
}


failCtLst.Add(failed);
isBoxOrILst.Add(isBoxOrI_);
maxThick.Add(failedThick);
namingFailList.Add(failedNaming);
madeNameList.Add(madeName);

h__.Add(h___);
b__.Add(b___);
ts__.Add(ts___);
tg__.Add(tg___);
}

ctFail = failCtLst;
isBoxOrI = isBoxOrILst;
h_ = h__;
b_ = b__;
ts_ = ts__;
tg_ = tg__;
Thickness_ = maxThick;
Naming_ = namingFailList;
madeNames = madeNameList;
}

Okay thanks!

hi robert 

I return to the example you have given me to run it but I got this error:

1:Object reference not set to an instance of an object (line 132)

***

line 132 : for (int i = 0; i < _m.elems.Count; i++)

What is the problem ?

i dont know exactly, but i remember having trouble with the *.COFF array option toggle in this context somehow. toggling it + restarting GH (with grasshopperunloadplugin command) helped me back then.

try to reduce the script, resp. test its functions step by step..! with VS you can also debug and look at the variables' values within VS..!

hello I have a similar problem I have been loading and downloading the * .COFF array option from GH with GrasshoppperDeveloperSettings but it still does not work (for the case of Rhinoceros 5 and karamba 1.2.2) see blue image, for Karamba 1.3 and Rhinoceros 6 when downloading the * .COFF array option of GH can not be assembled in karamba.gha file, but I can assemble it when I load the * .COFF array option from GH. in Rhinoceros there is no option grasshopperunloadplugin, the error that appears when I assemble the file karamba.gha (loading the * .COFF array option of GH) is the one shown in the yellow image in Karamba 1.3 for Rhinoceros 6. it knows how I can solve this, thanks in advance.

you need the following assembly reference, as you might know:

Attachments:

thank youu Robert :)

hi Robert,

I have a problem with karamba dll I can not add :/

this is the error message:

"karamba.dll could not be added ,please make sure that the file is accessible and that is a valid assembly Com component "

thank you !

hm .. have you added karamba.gha not karamba.dll?

hi Robert,

Can you help me to solve this problem :///

thank you 

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service