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: 

add constraint to projections with API

3 REPLIES 3
Reply
Message 1 of 4
grosfaignan
242 Views, 3 Replies

add constraint to projections with API

hi 

i have the following error when i try to create constraint between sketch projections and sketch line with api :

 

Failed:
Traceback (most recent call last):
  File "C:/Users/charl/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/NewScript1/NewScript1.py", line 79, in run
    coincidentConstraint = constraints.addCoincident(projectionsP3.item(0),lastFret )
  File "C:/Users/charl/AppData/Local/Autodesk/webdeploy/production/4c84784f9b312b4c6ccb78d46529ebb70d7a5a09/Api/Python/packages\adsk\fusion.py", line 20327, in addCoincident
    return _fusion.GeometricConstraints_addCoincident(self, point, entity)
RuntimeError: 2 : InternalValidationError : sketch == msketch

 

anyone know what does it mean ?

3 REPLIES 3
Message 2 of 4
kandennti
in reply to: grosfaignan

Hi @grosfaignan .

 

I don't think anyone can answer this question because there is too little information.

If you want to reach the goal, please provide the code and f3d data you tried.

Message 3 of 4
grosfaignan
in reply to: kandennti

there is the code :

 

 

 

import adsk.core, adsk.fusion, traceback
import math

defaultBoltName = 'FretBoard 1'
defaultHeadDiameter = 7
defaultBodyDiameter = 10.4
defaultHeadHeight = 24.5
defaultBodyLength = 24.5
defaultCutAngle = 30.0 * (math.pi / 180)
defaultChamferDistance = 4
defaultFilletRadius = 22

# global set of event handlers to keep them referenced for the duration of the command
handlers = []
app = adsk.core.Application.get()
if app:
    ui = app.userInterface

newComp = None

def createNewComponent():
    # Get the active design.
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    rootComp = design.rootComponent
    allOccs = rootComp.occurrences
    newOcc = allOccs.addNewComponent(adsk.core.Matrix3D.create())
    return newOcc.component

def run(context):
    try:
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        
        if not design:
            ui.messageBox('It is not supported in current workspace, please change to MODEL workspace and try again.')
            return


        # 1) Create a new sketch.
        global newComp
        newComp = createNewComponent()
        sketches = newComp.sketches
        xyPlane = newComp.xYConstructionPlane
        xzPlane = newComp.xZConstructionPlane
        sketch = sketches.add(xyPlane)
        sketch.name='MainFrame'
        constraints = sketch.geometricConstraints


        p1 = sketch.sketchPoints.add(adsk.core.Point3D.create(-50, 50, 0))
        p2 = sketch.sketchPoints.add(adsk.core.Point3D.create(-50, -50, 0))
        p3 = sketch.sketchPoints.add(adsk.core.Point3D.create(50, 50, 0))
        p4 = sketch.sketchPoints.add(adsk.core.Point3D.create(50, -50, 0))

        line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(p1, p2)
        line2 = sketch.sketchCurves.sketchLines.addByTwoPoints(p3, p4)
        line3 = sketch.sketchCurves.sketchLines.addByTwoPoints(p1, p3)
        line4 = sketch.sketchCurves.sketchLines.addByTwoPoints(p2, p4)
        # prevent this module from being terminate when the script returns, because we are waiting for event handlers to fire
        
        #2) add second sketche
        sketch2 = sketches.add(xyPlane)
        sketch2.name='Fretboard_Contour'
        projections = sketch2.project(line1)
        projections = sketch2.project(line2)
        projections = sketch2.project(line3)
        projectionsP3 = sketch2.project(p3)
        projections = sketch2.project(p4)

        # projections = sketch2.project(line4)
        # project1=projections.item(0)
        # project1.isConstruction=True
        # lineBottom = sketch2.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(-5, -100, 0), adsk.core.Point3D.create(5,-100, 0))
        lastFret= sketch2.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(-5, -100, 0), adsk.core.Point3D.create(5,-100, 0))
        coincidentConstraint = constraints.addCoincident(projectionsP3.item(0),lastFret )
        # fb_B = sketch2.sketchDimensions.addDistanceDimension(projections.item(0).endSketchPoint, lineBottom.endSketchPoint, adsk.fusion.DimensionOrientations.VerticalDimensionOrientation, adsk.core.Point3D.create(0, 1, 0))

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

 

error is produced by the 76th line :

coincidentConstraint = constraints.addCoincident(projectionsP3.item(0),lastFret )
Message 4 of 4
kandennti
in reply to: grosfaignan

@grosfaignan .

 

With this modification, the error was avoided.

・・・
        lastFret= sketch2.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(-5, -100, 0), adsk.core.Point3D.create(5,-100, 0))
        # coincidentConstraint = constraints.addCoincident(projectionsP3.item(0),lastFret )
        coincidentConstraint = sketch2.geometricConstraints.addCoincident(projectionsP3.item(0),lastFret )
・・・

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report