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 error: type mismatch in parameter. string required

It seems that there is a problem that I cant figure out

line 37 has the mentioned problem:

arrPts(Ubound(arrPts)) = Rhino.CurveEndPoint(strParent)

The version is rhino 4

any help appreciated

Views: 1511

Replies to This Discussion

It looks to me like you need to trap the error: 'What if Rhino.PointCompare never returns True?' strParent never gets assigned a value.

Hi Georgios,

Can you post both your .RVB file and your .3DM file?

Thanks,

 -- Dale

Here you go Dale

it is really important that you check it on rhino 4

thank you in advance

Attachments:

One problem is here:

Dim arrSort : arrSort = Rhino.SortNumbers(arrNames)

A layer name is a string, not a number. So you need to convert the string to a number using either CDbl or CInt. Also the "Default" layer won't convert to a useful number.

 -- Dale 

Dale I am quiet new at rhinoscript. I made this code with a friend and I can quiet follow you. It would be great if you could edit the code yourself and send it to me. And then explain me what you did at your post so that I learn from it.

Thanks for your time

Attachments:

Dear Chris this seems to be really helpful!

but what was the version you used? I both load it at rhino 4, 5 and got errors at both of them!

I edited this in Rhino5. (Version 5 SR4 (5.4.30510.16565)   What errors did you get?  It might still be buggy.  I just cleaned it up to work with a subset of your curves.  Your full curve set seemed to have some orphaned leaves (lines that didn't go back to the ground by any path).

I tried it at rhino 4 SR9 and Rhino 5 SR3 but got errors at both!

Rhino 5 SR3 gave me this:

Type mismatch in parameter. String required

Line: 61

Char:4

Line 61:

arrPts(Ubound(arrPts)) = Rhino.CurveStartPoint(strParent)

The attached .rvb works with the attached .3dm.  It does not work with your previously posted untitled.3dm file.   The .rvb requires that the tree lines have an inherent logical order, hence it will not work on any random set of lines. 

Attachments:

oh I see! Thanks for everything Chris

RSS

Translate

© 2021   Created by McNeel Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service