I’m trying to create a simple python script to loop through a selection of crvs and check for minimum clearance between them. Basically simulating the CrvDeviation tool, but running it between all curves at once.
Could anyone take a look at the attached and help me understand where I’m going wrong?
AFAIK, the script works fine.
But rs.CurveDeviation may not be the right tool.
I edited the script so that it tells us whether CurveDeviation works or not.
Running it on your curves makes it fail most of the times here.
import rhinoscriptsyntax as rs
import random
import math
allowedDev = rs.GetReal("What is the minimum distance allowed?")
inputCrvs = rs.GetObjects("Select Curves to Test", 4, True, True)
for curve in inputCrvs:
rs.UnselectAllObjects()
selCurve = rs.SelectObject(curve)
compCrvs = rs.InvertSelectedObjects()
for otherCrv in compCrvs:
deviation = rs.CurveDeviation(curve, otherCrv)
if deviation:
curvePoint = rs.EvaluateCurve(curve, deviation[3])
otherCrvPoint = rs.EvaluateCurve(otherCrv, deviation[4])
if deviation[5] < allowedDev:
rs.AddLine(curvePoint, otherCrvPoint)
else:
print( 'CurveDeviation failed' )
Ah … wait.
I think now I see a problem in the script.
When, after the script has drawn the first line, it runs rs.InvertSelection,
then also the lines drawn by the script are selected, and then checked by rs.CurveDeviation.
I’m pretty sure there’s something wonky in the first For loop. I am new to Python and I imagine there’s a better way to cycle through a group, one item at a time…