Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for
Show  only  | Search instead for
Did you mean:

## Edges with same geomerical parameters

6 REPLIES 6
SOLVED
Message 1 of 7
559 Views, 6 Replies

## Edges with same geomerical parameters

Hello,

It need check, if edges is same (they have Equal start, end points and another geometric parameters). This Edges are located in different bodies and faces.  What is the easiest way to do this?

Thanks, Vitaut.

6 REPLIES 6
Message 2 of 7
The main task is to check whether the connections of the two surfaces. And I think that it is necessary to compare the edges. What parameters are enough to compare to make sure that the geometry of the two edges is the same?
Message 3 of 7

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.
curveOne = curveOne.asNurbsCurve

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:
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

Message 4 of 7
Thank you, Jack, for yours code.
Message 5 of 7

I was just looking at your question again, and if I read it correctly there is a simpler way than comparing the geometry, although that will work.

If all you want to do is to find out if two surfaces are connected you can use the topology of the B-Rep structure to do that.  A face has edges, but edges are shared between faces.  The edge that you see connected two faces is a single edges that is shared by both of those faces.  Here's a little test script that demonstrates that.

```def run(context):
try:
ui = app.userInterface

faceSelect = ui.selectEntity('Select first face', 'Faces')
faceSelect = ui.selectEntity('Select second face', 'Faces')

# Check to see if any of the edges of face 1 connect to face 2.
isConnected = False
for testEdge in face1.edges:
if isConnected:
break

for testFace in testEdge.faces:
if testFace == face2:
isConnected = True
break

if isConnected:
ui.messageBox('The faces are connected.')
else:
ui.messageBox('The faces are NOT connected.')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))```

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 7