Grasshopper

algorithmic modeling for Rhino

hi

here is few lines of my code.

I have a component with Curve as input.

 

protected override void RegisterInputParams(Grasshopper.Kernel.GH_Component.GH_InputParamManager pManager)
{
pManager.Register_CurveParam("crvIn", "CrvIn", "CrvIn");

}

protected override void RegisterOutputParams(Grasshopper.Kernel.GH_Component.GH_OutputParamManager pManager)
{
pManager.Register_CurveParam("crvOut", "crvOut", "crvOut");
}

....

 

protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
{

Rhino.Geometry.Curve crv; //my issue !!

DA.GetData(0, ref crv);

DA.SetData(0, crv);


}

 

Actually I can't assign my variable crv because it 's protected,( no way to write something like " Rhino.Geometry.Curve crv = new Rhino.Geometry.Curve(); ")

but if I write something like

Rhino.Geometry.Polyline crv = new Rhino.geometry.Polyline();

I can assign my variable, but then I have a cast issue between "Curve" and "Polyline" type...

 

So I don't know what to do.

Can someone help please ?

 

 

Views: 1489

Replies to This Discussion

Curve has static creator methods.

 

Use Curve.Create...() or NurbsCurve.create(..)

 

 

Hi raf,

 

you don't have to assign it a real curve. Just assign null and the warning will go away. GetData will replace the crv value anyway, so anything you assign to it before you call GetData will be pointless:

 

Curve crv = null;

if (!DA.GetData(0, ref crv)) { return; }

 

Technically, the GetData function should use out instead of ref, but changing this now would result in every component library out there no longer working.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

ok thanks David.

Now I  have another issue... :(

Basically I have a Curve crv which is actually a polyline that I want to explode into lines and then get start points of these lines.

But I don't know why but I have no access to method like

crv.DuplicateSegments;

 

So I thought to convert my Curve to Polycurve and then use Explode method, but I even don't know and understand how to "convert" Curve to Polycurve.

 

So I am bit confused, and it seems nobody as such issue so again any help will be welcome :)

Curve is the abstract base class for all curve types in Rhino (lines, polylines, arcs, circles, nurbscurves, polycurves) and thus doesn't offer any methods that would apply only to Polylines, or Nurbscurves, or Arcs. If you know that your input is only ever polyline-shaped, you can use the TryGetPolyline() method to create a polyline that looks just like your curve. If however the curve contains non-linear segments, this will probably fail.

 

Don't use the ToPolyline() method as that will basically create a new polyline curve through the original curve in a process akin to Meshing.

 

There's other ways to approach this problem as well. You could for example convert your Curve into a NurbsCurve using the ToNurbsCurve() method. Conversion from any Rhino curve type to NurbsCurves always preserves shape (though it might change the parameterization and thus affect the third derivative onwards). Once you have a NurbsCurve you can easily find the kinks in it by testing the knot-vector for multiple knots.

 

A third option is to use methods like GetNextDiscontinuity() which is available directly off Rhino.Geometry.Curve. This allows you to find kinks of all sorts (G0, G1, G2 etc.) along the curve, which is basically the same as finding the kinks in a polyline.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

well,

ok I understand that Curve is the abstract class for all curve types in rhino.

what I still don't understand is when I look at the rhinocommon SDK in Curve Members I have some method that I can't access..

when I have 

Curve crv = null;

if (!DA.GetData(0, ref crv)) { return; }

then I don't understand why I can't have 

crv.DuplicateSegments;

but I have access in the C# editor component in grasshopper..

please see the picture enclosed

 

Oh I see. DuplicateSegments is only available when you compile against the Rhino5 version of RhinoCommon. It is not part of the Rhino4 SDK. In Visual Studio you have probably referenced the RhinoCommon.dll that ships with Grasshopper, whereas Grasshopper (when running on Rhino5) will use the new SDK.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

you were right I used the wrong RhinoCommon.dll.

Thanks again for your help !

Do note that when you use methods only available on Rhino5, your components will not run on Rhino4.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

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