Grasshopper

algorithmic modeling for Rhino

Hi,

I'm trying to work with a series of curves in a VB.net component. However, I can't seem to use the Oncurve type. It returns an error saying it is protected.

Any ideas how to work with curves in VB.net or what alternate type I should be using?

Thanks.

Kermin

Views: 618

Replies to This Discussion

Hi Kermin,

OnCurve is an abstract class (MustInherit in VB), you are not allowed to construct it.

OnCurves are only used for generic curves. Use OnNurbsCurve or OnLineCurve or OnArcCurve instead.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi David,

Ok. Good to know. What type should I be using if GH is generating a set of "Polyline Curve"?

When I try to use "OnNurbsCurve", the VB component reports "unable to cast object of type 'RMA.OpenNURBS.Oncurve to type RMA.OpenNurbs.OnNurbsCurve'.

Thanks

Kermin
You can't just use OnNurbsCurve methods on an OnCurve because there's no guarantee that the OnCurve you have is an OnNurbsCurve. All OnNurbsCurves are OnCurves, but all OnCurves are not OnNurbsCurves.

The best way to get an OnNurbsCurve is to use the GetNurbForm method that should be supported by OnCurve and all OnCurve derived classes.
There's also an OnPolylineCurve type in OpenNurbs.

Why do you need to restrict yourself to a specific curve type? If Grasshopper is providing the curve, why not just stick with OnCurve?

You can make duplicates from OnCurves btw. Every OnCurve has a DuplicateCurve() method that returns another curve that is similar to the first one.

If you are making the curve from scratch, then it's easy to determine what flavour of curve it should be.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hmm. This should be pretty straightforward for the more advanced crowd.

1. GH produces a set of polylines (really a set of joined straight line segments)
2. I pass this as a flat list into a VB component.
3. I want to run through that list and for example compute the centriod of the closed polyline or find the max/min xyz value along its length but in order to do that, I need to deal with a specific polyline at a time.
4. Thus


for i as int32 = 0 to IncomingListOfPolylines.count-1
dim currentcurve as new xxxx
Currentcurve = IncomingListOfPolylines.item(i)

'do something with currentcurve
next i

I've tried xxxx as
OnPolyline
OnNurbsCurve
OnArcCurve

but no luck. The only way I've been successful in bringing the polyline in is as an exploded polyline and then I deal with a set of OnLine which is ok but not great.

Thanks.
None of those have worked because declaring the target variable as the type that you need will not automatically convert the curve. You need to manually do this in order to have something that is usable. As I mentioned before, the GetNurbsForm method will work to get you a nurbs curve, so things would look like this.

Dim currentCurve as New OnNurbsCurve()
IncomingListOfPolylines(i).GetNurbsForm(currentCurve)

You also have other options here. If you really want a OnPolyLine representation of the curve, you can use the IsPolyLine method that's supported by OnCurve and pass in an ArrayOn3dPoint. From there you can work either directly from the points or create an OnPolyLineCurve and go from there.
Kermin,

one big mistake is here:

dim currentcurve as new xxxx


The polyline curve already exists, you do not need to make a new one.

All you need to do is:

For i As Int32 = 0 To List.Count -1
Dim crv As OnCurve = List(i)
'Do something with crv
Next

-or-

For Each crv As OnCurve in List
'Do something with crv
Next

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Ok.
Thanks. I'll keep the above in mind.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service