Grasshopper

algorithmic modeling for Rhino

Hello everyone!

I've written this code and I'm stuck

Option Explicit

Call Main()
Sub Main()

Dim arrLines : arrLines = Rhino.GetObjects("",4)
Dim strLine, i : i = 0
Dim arrNames : arrNames = arrLines
For Each strLine In arrLines
arrNames(i) = CInt(Rhino.ObjectLayer(strLine))
i = i+1
Next

Call rhino.EnableRedraw(False)
Dim arrSort : arrSort = Rhino.SortNumbers (arrNames)

Dim arrLeafs : arrLeafs = Rhino.ObjectsByLayer(arrSort(Ubound(arrSort)))
Dim arrPaths : arrPaths = arrLeafs
Dim strLeaf
For Each strLeaf In arrLeafs
ReDim arrPts(0)
arrPts(0) = Rhino.CurveEndPoint(strLeaf)
Dim strLeafName : strLeafName = Rhino.ObjectLayer(strLeaf)
Dim j : j = CInt(strLeafName)
Dim strCurrentBranch : strCurrentBranch = strLeaf
Dim arrParLeafs, strParent
Do
If j > 0 Then
arrParLeafs = Rhino.ObjectsByLayer(CStr(j-1))
For i = 0 To Ubound(arrParLeafs)
If Rhino.PointCompare (Rhino.CurveStartPoint(strCurrentBranch),Rhino.CurveEndPoint(arrParLeafs(i))) Then
strParent = arrParLeafs(i)
Exit For
End If
Next
ReDim Preserve arrPts(Ubound(arrPts)+1)
arrPts(Ubound(arrPts)) = Rhino.CurveEndPoint(strParent)
strCurrentBranch = strParent
j = j - 1
ElseIf j = 0 Then
arrParLeafs = Rhino.ObjectsByName(0)
For i = 0 To Ubound(arrParLeafs)
If Rhino.PointCompare (Rhino.CurveStartPoint(strCurrentBranch),Rhino.CurveEndPoint(arrParLeafs(i))) Then
strParent = arrParLeafs(i)
Exit For
End If
Next
ReDim Preserve arrPts(Ubound(arrPts)+1)
arrPts(Ubound(arrPts)) = Rhino.CurveStartPoint(strParent)
strCurrentBranch = strParent
j = -1
Else
Exit Do
End If
Loop

Call Rhino.AddCurve(arrPts)

Next
rhino.EnableRedraw(True)

End Sub

when I run the code it says:It seems that there is a problem with CInt that I cant figure out

Views: 712

Replies to This Discussion

anyone???

This isn't really the forum for RhinoScript questions. However if the error is about CInt() on line 10, then this:

arrNames(i) = CInt(Rhino.ObjectLayer(strLine))

is most likely the problem.

Are you trying to convert a layer name into an integer? If so, that may well fail if the layername is not a text representation of some valid integer.

Remove the CInt() call from that line and you're good to go.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Dear David you were right! It skipped that problem! Do you know where I can ask for some help?

I got another one

The Rhino developer forums are the best place for RhinoScript questions. Our support forums have changed recently and I don't actually keep track of that, but this seems like a good place to start:

http://v5.rhino3d.com/forum/categories/rhinoscript/listForCategory

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Incidentally if the error message claims line 37, it's helpful if you tell everyone what line 37 is in your script. Make it bold or something.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks a lot David

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service