Edges with same geomerical parameters

Edges with same geomerical parameters

Anonymous
Not applicable
898 Views
6 Replies
Message 1 of 7

Edges with same geomerical parameters

Anonymous
Not applicable

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.

0 Likes
Accepted solutions (1)
899 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
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?
0 Likes
Message 3 of 7

liujac
Alumni
Alumni
Accepted solution

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

Message 4 of 7

Anonymous
Not applicable
Thank you, Jack, for yours code.
0 Likes
Message 5 of 7

ekinsb
Alumni
Alumni

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:
        app = adsk.core.Application.get()
        ui = app.userInterface

        faceSelect = ui.selectEntity('Select first face', 'Faces')
        face1 = adsk.fusion.BRepFace.cast(faceSelect.entity)
        faceSelect = ui.selectEntity('Select second face', 'Faces')
        face2 = adsk.fusion.BRepFace.cast(faceSelect.entity)

        # Check to see if any of the edges of face 1 connect to face 2.
        testEdge = adsk.fusion.BRepEdge.cast(None)
        isConnected = False
        for testEdge in face1.edges:
            if isConnected:
                break
            
            testFace = adsk.fusion.BRepFace.cast(None)
            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
0 Likes
Message 6 of 7

Anonymous
Not applicable
Ekinsb, This will not work if faces include in two different bodies.
0 Likes
Message 7 of 7

ekinsb
Alumni
Alumni
You're correct. I missed that requirement in your original problem statement. Jack's solution is the best for that.

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes