Hi,
You may get the geometry from edge, it’s a Curve3D object. Check the curve type of the Curve3D object, it can be Line3DCurveType, Arc3DCurveType, Circle3DCurveType, Ellipse3DCurveType, EllipticalArc3DCurveType, or NurbsCurve3DCurveType. Convert curve to NurbsCurve3D if it’s not NurbsCurve3D. Get the data from the NurbsCurve3D. Compare the data.
I wrote the script as below. Select two edges on UI first before running this script.
import adsk.core, adsk.fusion, adsk.cam, traceback
near_zero = 0.000001
def areEdgesEqual(edgeOne, edgeTwo):
curveOne = edgeOne.geometry
curveTwo = edgeTwo.geometry
# convert curve to Nurbs if it's not Nurbs.
if curveOne.curveType != adsk.core.Curve3DTypes.NurbsCurve3DCurveType:
curveOne = curveOne.asNurbsCurve
if curveTwo.curveType != adsk.core.Curve3DTypes.NurbsCurve3DCurveType:
curveTwo = curveTwo.asNurbsCurve
# get data from Nurbs curve
(retValOne, controlPointsOne, degreeOne, knotsOne, isRationalOne, weightsOne, isPeriodicOne) = curveOne.getData()
(retValTwo, controlPointsTwo, degreeTwo, knotsTwo, isRationalTwo, weightsTwo, isPeriodicTwo) = curveTwo.getData()
# compare data
if len(controlPointsOne) != len(controlPointsTwo):
return False
if degreeOne != degreeTwo:
return False
if len(knotsOne) != len(knotsTwo):
return False
if isRationalOne != isRationalTwo:
return False
if len(weightsOne) != len(weightsTwo):
return False
if isPeriodicOne != isPeriodicTwo:
return False
i = 0 # compare from start of sencond curve
for controlPointOne in controlPointsOne:
if not controlPointOne.isEqualTo(controlPointsTwo[i]):
j = len(controlPointsOne) - 1 # compare from end of sencond curve
for controlPointOne in controlPointsOne:
if not controlPointOne.isEqualTo(controlPointsTwo[j]):
return False
j = j - 1
break
i = i + 1
import math
i = 0 # compare from start of sencond curve
for knotOne in knotsOne:
if math.fabs(knotOne - knotsTwo[i]) > near_zero:
j = len(knotsOne) - 1 # compare from end of sencond curve
for knotOne in knotsOne:
if math.fabs(knotOne - knotsTwo[j]) > near_zero:
return False
j = j - 1
break
i = i + 1
i = 0 # compare from start of sencond curve
for weightOne in weightsOne:
if math.fabs(weightOne - weightsTwo[i]) > near_zero:
j = len(weightsTwo) - 1 # compare from end of sencond curve
for weightOne in weightsTwo:
if math.fabs(weightOne - weightsTwo[j]) > near_zero:
return False
j = j - 1
break
i = i + 1
return True
# Select two edges on UI first before run the script
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox('Equal: {}'.format(areEdgesEqual(ui.activeSelections[0].entity, ui.activeSelections[1].entity)))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Thanks,
Jack