algorithmic modeling for Rhino
Hello All,
I am practicing through some basic Rhinocommon VB.Net routines and was wondering if anyone else has encountered the IEnumerator, IEnumberable Members from the System.Collections
. After some research they seem to have quite a bit of potential for iterating through lists of data.
In the listed example below I am attempting to create 2 points, 2 lines and loft a brep through the lines. One of the curve parameters is a System.Collections.Generic.IEnumberable(of Curve)
However I am not quite sure how to define it. Any input would be greatly appreciated.
Many Thanks.
Dim ptL As New List(Of Point3d)
Dim lnL As New List(Of Line)
Dim pt1 As New Point3d(15, 0, 0)
ptL.Add(pt1)
Dim ln1 As New Line(pt1, vector3d.XAxis, x)
lnL.Add(ln1)
Dim pt2 As New Point3d(15, 10, 0)
ptL.Add(pt2)
Dim ln2 As New Line(pt2, vector3d.ZAxis, x)
lnL.add(ln2)
Dim srf As New Brep
srf = Rhino.Geometry.Brep.CreateFromLoft(lnL, ptL(0), ptL(1), Rhino.Geometry.LoftType.Normal, False)
a = srf
B = ln1
c = ln2
Tags:
Dim lines As New List(Of Curve)
lines.Add(New LineCurve(New Line(pt1, vector3d.XAxis, x)))
lines.Add(New LineCurve(New Line(pt2, vector3d.ZAxis, x)))
Dim srf As Brep() = Brep.CreateFromLoft(lines, Point3d.Unset, Point3d.Unset, Lofttype.Normal, False)
If (srf IsNot Nothing) Then surfaces.AddRange(srf)
Let me ask one question related to IEnumerable(Of T).
I attach my script as follows. It is to find projected points to a complex mesh. I used IEnumerable(Of point3d) with the following script. But I can not use the found points for further script because the points can not be converted to a list of point3d which is 'ptms' at the following script. I want to make a list of point3d with the found points.
Please help for the problem.
Thanks for your help in advance.
Jihoon.
Private Sub RunScript(ByVal pts As List(Of Point3d), ByVal terrain As List(Of Mesh), ByRef A As Object)
Dim nlast As Integer = pts.count - 1
Dim vecz As New Vector3d
Dim meshes As IEnumerable(Of Mesh) = terrain
Dim points As IEnumerable(Of Point3d) = pts
Dim ptie As IEnumerable(Of Point3d)
Dim ptms As New List (Of Point3d)
vecz.X = 0
vecz.Y = 0
vecz.Z = 1
For i As Integer = 0 To nlast
ptie = Intersect.intersection.ProjectPointsToMeshes(meshes, points, vecz, 0.001)
Next
ptms=ptie
A = ptms
End Sub
Typing this from the top of my head:
Private Sub RunScript(ByVal pts As List(Of Point3d), _
ByVal terrain As List(Of Mesh), _
ByRef A As Object)
Dim vecz As New Vector3d(0,0,1)
Dim ptms As New List (Of Point3d)
For i As Integer = 0 To pts.count - 1
Dim pp As Point3d() = Intersect.intersection.ProjectPointsToMeshes( _
terrain, pts, vecz, 0.001)
If (pp IsNot Nothing) Then ptms.AddRange(pp)
Next
A = ptms
End Sub
Though I do wonder what good that loop is doing. It's not like you're changing anything inside the loop, it always runs the same data. So I think your ptms probably contains the same data over and over again. I'd just remove the loop altogether and place a single call to ProjectPointsToMeshes()
To elaborate on my code, List(Of Whatever) implements the IEnumerable(Of Whatever) interface. So when a function requests an input of type IEnumerable(Of Whatever) and you have a List(Of Whatever), you can just plug it in directly.
ProjectPointsToMeshes() returns an array of Point3d structures. Now, Point3d() also implements IEnumerable(Of Point3d), so you can safely assign it to your ptie variable. But you cannot assign ptie (IEnumerable(Of Point3d)) to ptms (List (Of Point3d)) because that would require a conversion in the wrong direction. You see Lists are far more specific than IEnumerables. And although every Mitsubishi Colt is a car, not every car is a Mitsubishi Colt.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thank you so much for your detailed explanation.
I will try it again.
Jihoon
So, I rediscovered this thread in an attempt to join a couple of curves.
In order to do so, as you very well know, I need an IEnumerable.
I thought this would work...
Dim crvList as New List (Of Curve)
crvList.Add(tCrv)
crvList.Add(bCrv)
Dim jCurve as Curve = Rhino.Geometry.Curve.JoinCurves(crvList)
But, when I do this, I get some sort of 1-dimensional array error message. I of course cannot tell you exactly what it says because my German is not that good.
I got the part about Lists implementing the interface of IEnumerable, and it made sense until I tried to this.
Can someone please explain this to me!?!
JoinCurves returns an array of curves, so you need to declare jCurve as such:
Dim jCurve As Curve() = Rhino.Geometry.Curve.JoinCurves(crvList)
--
David Rutten
david@mcneel.com
Poprad, Slovakia
thanks!
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by