How to find automatically created coincident constraint

How to find automatically created coincident constraint

muhaiR2SPM
Participant Participant
476 Views
1 Reply
Message 1 of 2

How to find automatically created coincident constraint

muhaiR2SPM
Participant
Participant

Hi everyone,

 

I am looking for some advise on how to get rid of constraints that are visible in the UI but can not be retrieved via API.

 

The starting point is something like this. A spline which is cut by a line.origin.JPG















Afterwards overlaps are trimmed.

cutoff.jpg













Which creates the following constraints.
coincidentconstraints.JPG
Having those constraints hinders to properly fillet the edge points. Without those constrains everything works as expected. I am not able to find or retrieve the coincident constraints. sketch.geometricConstraints returns no results.

result.JPG

Here is my sample code

 

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    app = adsk.core.Application.get()
    ui = app.userInterface
    design = adsk.fusion.Design.cast(app.activeProduct)

    if not design:
        ui.messageBox('No active Fusion 360 design', 'No Design')
        return

    try:
        # Get the root component of the active design.	
        rootComp = design.rootComponent

        # Cleanup, delete all existing sketches
        sketches = rootComp.sketches
        while sketches.count > 0:
            sketches.item(0).deleteMe()

        # Cleanup, delete all construction planes.
        cnstrionPlanes = rootComp.constructionPlanes
        while cnstrionPlanes.count > 0:
            cnstrionPlanes.item(0).deleteMe()


        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        cnstrionPlanes = rootComp.constructionPlanes
        cnstrionPlaneInput = cnstrionPlanes.createInput()
        cnstrionPlaneInput.setByOffset(xyPlane, adsk.core.ValueInput.createByReal(1))   
        xyCnstrionPlane = cnstrionPlanes.add(cnstrionPlaneInput)
        
         # Create a new sketch on the yz construction plane.	
        sketch: adsk.fusion.Sketch = sketches.add(xyCnstrionPlane)
        sketch.name = 'Segment '
        lines = sketch.sketchCurves.sketchLines

        # Create an object collection for a spline.
        pointsss = adsk.core.ObjectCollection.create()
        pointsss.add(adsk.core.Point3D.create(5,3,0))
        pointsss.add(adsk.core.Point3D.create(7,5,0))
        pointsss.add(adsk.core.Point3D.create(9,3,0))

        # Create the spline.
        spline2 = sketch.sketchCurves.sketchFittedSplines.add(pointsss)        

        # Create line which cuts spline
        line = lines.addByTwoPoints(adsk.core.Point3D.create(4,4,0), adsk.core.Point3D.create(10,4,0))

        # Delete part of line which is within the spline
        line.trim(adsk.core.Point3D.create(7,4,0), True)

        # Get newly created lines
        linePart1 = lines.item(lines.count - 1)
        linePart2 = lines.item(lines.count - 2)

        # Get the spline and trim everything below line
        spline = sketch.sketchCurves.item(sketch.sketchCurves.count-1)
        spline2.trim(adsk.core.Point3D.create(5,3,0), True)

        spline = sketch.sketchCurves.item(sketch.sketchCurves.count-1)
        spline.trim(adsk.core.Point3D.create(9,3,0), True)
        spline = sketch.sketchCurves.item(sketch.sketchCurves.count-1)

        # I CANNOT FIND ANY COINCIDENT CONSTRAINT EITHER IN SPLINE NOR IN LINEPARTS

        # Delete all constraints available
        sketch.geometricConstraints.item(0).deleteMe()
        sketch.geometricConstraints.item(0).deleteMe()
        sketch.geometricConstraints.item(0).deleteMe()

        print(str(spline.startSketchPoint.geometry.x) + " " + str(spline.startSketchPoint.geometry.y) + " " + str(spline.startSketchPoint.geometry.z))
        print(str(spline.endSketchPoint.geometry.x) + " " + str(spline.endSketchPoint.geometry.y) + " " + str(spline.endSketchPoint.geometry.z))

        print(str(linePart1.startSketchPoint.geometry.x) + " " + str(linePart1.startSketchPoint.geometry.y) + " " + str(linePart1.startSketchPoint.geometry.z))
        print(str(linePart1.endSketchPoint.geometry.x) + " " + str(linePart1.endSketchPoint.geometry.y) + " " + str(linePart1.endSketchPoint.geometry.z))


        print(str(linePart2.startSketchPoint.geometry.x) + " " + str(linePart2.startSketchPoint.geometry.y) + " " + str(linePart2.startSketchPoint.geometry.z))
        print(str(linePart2.endSketchPoint.geometry.x) + " " + str(linePart2.endSketchPoint.geometry.y) + " " + str(linePart2.endSketchPoint.geometry.z))


        sketch.sketchCurves.sketchArcs.addFillet(spline, spline.startSketchPoint.geometry, linePart2, linePart2.endSketchPoint.geometry, .6)
        sketch.sketchCurves.sketchArcs.addFillet(spline, spline.endSketchPoint.geometry, linePart1, linePart2.startSketchPoint.geometry, .6)


    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

Thank you very much 🙂

0 Likes
Accepted solutions (1)
477 Views
1 Reply
Reply (1)
Message 2 of 2

BrianEkins
Mentor
Mentor
Accepted solution

The coincident constraints the user interface is showing you don't exist.  There aren't two points, one for each curve, tied together by a coincident point, but there is a single point shared by the curve and the line. To make them independent, a new sketch point needs to be created, and one of the curves switches to using it. The UI shows a coincident constraint to indicate the curves share a point, and this provides the UI to separate the curves so they no longer share a point.

 

When trimming curves, like in your case, or if you move a point on top of another point, Fusion will change the geometry so there is a single point and the curves share that point. The API supports this with the SketchPoint.merge method. I thought the API also supported breaking the curves apart so they don't share the point, like deleting the imaginary coincident constraint does in the UI. However, I don't see it and believe that functionality is missing. The only alternative I currently see is to delete the curve and re-create it using the same coordinates without merging the endpoints. The biggest downside is if there are dimensions or other constraints to the geometry you deleted and re-created because you'll lose that when you delete the curve.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com