With reference to this previous post on an unsupported command for detecting self-intersecting curves, I’d like to do the same thing but without adding any points to the Rhino Document. I would just need a True/False output (True - there is a self-intersection, False - there is none), and no other outputs (the unsupported command adds points to the intersection locations, and this is not necessary for my script).
I am aware that I can run the command using the rs.Command(macro) function. While this does return a True/False based on the existence of the intersections, I cannot retrieve the points added to the intersections. Is there a Python scripting way to go about this (I’m completely only scripting in the RhinoPython editor)? What other workarounds are possible?
You could try modifying Mitch’s script by removing the part that adds points.
Option Explicit
'Script written by Mitch
'Version Friday, 01 June 2012
Call SelSelfIntersectingCrvs()
Sub SelSelfIntersectingCrvs()
Dim arrCrvs,strCrv,arrSIPts,strGroup,res,tol
tol = Rhino.UnitAbsoluteTolerance()
arrCrvs = Rhino.ObjectsByType(4)
If IsArray(arrCrvs) Then
Call Rhino.UnselectAllObjects()
Call Rhino.EnableRedraw(False)
For Each strCrv In arrCrvs
res = Rhino.CurveCurveIntersection(strCrv,, tol)
If IsArray(res) Then
Call Rhino.SelectObject(strCrv)
arrSIPts = AddSIPoints(res)
strGroup = Rhino.AddGroup
Call Rhino.AddObjectsToGroup(arrSIPts, strGroup)
Call Rhino.AddObjectToGroup(strCrv, strGroup)
End If
Next
End If
Call Rhino.EnableRedraw(True)
End Sub
Function AddSIPoints(arr)
Dim arrPts(),i,n
i = -1
For n=0 To Ubound(arr, 1)
i = i + 1
ReDim Preserve arrPts(i)
arrPts(i) = Rhino.AddPoint(arr(n, 1))
If arr(n, 0) = 2 Then
i = i + 1
ReDim Preserve arrPts(i)
arrPts(i) = Rhino.AddPoint(arr(n, 2))
End If
Next
Call Rhino.SelectObjects(arrPts)
AddSIPoints = arrPts
End Function
Thanks @Helvetosaur, @ Terry_Chappell and @AndersDeleuran for the suggestions. Both Intersection.CurveSelf (where I’d need to look for the Rhino Curve in the Object Table first) and rs.CurveCurveIntersection (where I can just wait for a None or List output) seem to fit what I’m looking for, which is an indicator of whether a curve is self-intersecting.
(All these solutions work for self-intersecting Polylines, but I’m working on a different approach for a self-intersecting polygon made up of separate curves where two or more intersect.)