What’s the easiest way to get information on sub curves in a polycurve. Is using ExtractPolyCurveSegment to get a copy then deleting the copy like in the script below the only way?
Thanks Mark.
Option Explicit
'Script written by <insert name>
'Script copyrighted by <insert company name>
'Script version 19 June 2015 17:27:41
Call Main()
Sub Main()
Dim Curve, i, count, strObject
Curve = Rhino.GetObject("Select polyCurve", 4, True)
If IsNull(Curve) Then Exit Sub
If Not Rhino.IsPolyCurve(Curve) Then Exit Sub
count = Rhino.PolyCurveCount(Curve)
For i = 0 To count - 1
strObject = Rhino.ExtractPolyCurveSegment(Curve, i)
If Rhino.IsArc(strObject) Then
Rhino.Print("Curve " & i & " is an arc")
End If
If Rhino.IsLine(strObject) Then
Rhino.Print("Curve " & i & " is a line")
End If
Call Rhino.DeleteObject(strObject)
Next
End Sub
Probably. With vbRhinoscript, you don’t have many possibilities to look as sub-level geometry without actually re-creating it and adding it to the document - via explode or duplicate or extract…
If you were to use Python, you could get at the sublevel objects via RhinoCommon and report their individual characteristics without actually having to extract or explode anything.
An easier way with your script instead of using ExtractPolyCurveSegment might be to just use ExplodeCurves with delete set to no, then iterate through the results, and delete the array of exploded segments afterwards with DeleteObjects…
This might give you somewhat different (more reliable?) results, as IIRC polycurves can be composed of sub polycurves, so extracting a top-level segment might still yield another polycurve and not a line/arc/spline segment… Haven’t checked that though… Explode should get you to the lowest-level segments immediately.
Mitch I’ve redone the test script using ExplodeCurves but I’m not sure how to test it. I’ve tried joining 2 polycurves but the first script gives the same results as using ExplodeCurves. So how do you get a polycurve with sub polycurves?
I used your ExplodeQuestion.3dm file from another thread and I see the difference between the scrips now. The script from my first post only sees 2 curves. Using the script below I get all 19 curves.
Option Explicit
'Script written by <insert name>
'Script copyrighted by <insert company name>
'Script version 19 June 2015 17:27:41
Call Main()
Sub Main()
Dim Curve, i, count, strObject, arrCurves, arrPoint
Curve = Rhino.GetObject("Select polyCurve", 4, True)
If IsNull(Curve) Then Exit Sub
If Rhino.IsPolyCurve(Curve) Then
arrCurves = Rhino.ExplodeCurves(Curve, False)
i = 0
Else
Exit Sub
End If
For Each strObject In arrCurves
arrPoint = Rhino.CurveMidPoint(strObject)
If Rhino.IsArc(strObject) Then
Rhino.AddTextDot "Curve " & i & " is an arc", arrPoint
ElseIf Rhino.IsLine(strObject) Then
Rhino.AddTextDot "Curve " & i & " is a line", arrPoint
Else
Rhino.AddTextDot "Curve " & i & " is a curve", arrPoint
End If
Call Rhino.DeleteObject(strObject)
i = i + 1
Next
End Sub
if you set intType to 0 you get the equivalent of the _What command, using a value of 3 instead returns an equivalent of the _List command. But it can be painful to filter the required information out from that large string returned.