Grasshopper

algorithmic modeling for Rhino

Hi all

I have a tricky problem about GH_Structure.

I've created my custom type GH_ITest inheriting GH_Goo interface. After that I've implemented my custom component Test.cs (see the attached file for the code).

But a problem arise:

1 - if I try to connect the first data tree all seems good;

2 - when I try to connect the second input i receive this error message:

it seems that SKL is a IGH_Goo type but from SKL I have the following output: a GH_ITest object (see the code at the end of the post).

I don't understand what I'm missing.

It's quite complicated for to be clear but I hope that someone could recognize the problem.

Thanks

P

List<GH_ITest> skl = new List<GH_ITest>();

// retrieve data for component
if (!DA.GetData(0, ref sk)) { return; }
DA.GetData(1, ref run);

// collect SketchLine3D
if (sk.Value.SketchLines.Count > 0)
{
for (int i = 1; i <= sk.Value.SketchLines.Count; i += 1)
{

SketchLine l = sk.Value.SketchLines[i];

skl.Add(new GH_ITest(l));

dm.Add(String.Format("SketchLine {0}", l.Length));
}
}

// output data
DA.SetDataList(0, dm);
DA.SetDataList(1, skl);

Views: 720

Attachments:

Replies to This Discussion

I *think* when you're dealing with custom goo types you *also* have to create your own param type as GH_Param<YourGooType> and then add that parameter, rather than relying on generic parameter. a Param_Generic returns data of type IGH_Goo; if you wanted to you could also probably harvest the data into a GH_Structure of IGH_Goo and then cast to your more specific type. I could be wrong about the above but this is what my gut says, hope it helps!

Thank you Andrew. My guts have the same feeling. This is exactly what I'm doing right now.

But I would like to get a more complete way to manage my data. Do you have a clear example to implement a GH_Param? It could be very helpful

P

Hi Paolo,

Generic parameter will work, but it would be much nicer to add your own type. The SDK documentation (downloadable via the GH help menu) has example code for creating your own goo and parameter types.

Perfect. Thanks

Hi

it seems that is working after the creation of the custom parameter.

Another question: When is it necessary to register the paramenter?

When I need to insert my object inside the component I use pManager.AddParameter in this way:

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddParameter(new GH_IPSketchLine(), "SketchLine", "SKL", "SketchLine", GH_ParamAccess.tree);
}

But I have to register the parameter every time the component output the result?


protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{

// Is this the correct way every time?????

pManager.RegisterParam(new GH_IPSketchLine(), "SketchLine", "SKL", "SketchLine inside the PlanarSketch", GH_ParamAccess.list);

// or this????

pManager.AddParam(new GH_IPSketchLine(), "SketchLine", "SKL", "SketchLine inside the PlanarSketch", GH_ParamAccess.list);
}

I think it's AddParam. But "RegisterOutputParams" is only called once, not "every time the component outputs the result" - so it shouldn't be an issue. 

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service