Create Driven Sketch Dimension Using API

Create Driven Sketch Dimension Using API

scruffmeister
Participant Participant
351 Views
1 Reply
Message 1 of 2

Create Driven Sketch Dimension Using API

scruffmeister
Participant
Participant

Is there a way to create a driven sketch dimension using the API?

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

kandennti
Mentor
Mentor
Accepted solution

Hi @scruffmeister .

 

I have modified the sample script here to add a driven dimension.

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        
        design = app.activeProduct

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

        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        sketch: adsk.fusion.Sketch = sketches.add(xyPlane)

        # Draw some circles.
        circles = sketch.sketchCurves.sketchCircles
        circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2)
        circle2 = circles.addByCenterRadius(adsk.core.Point3D.create(8, 3, 0), 3)

        # Add a circle at the center of one of the existing circles.
        circle3: adsk.fusion.SketchCircle = circles.addByCenterRadius(circle2.centerSketchPoint, 4)

        # Create driven dimension.
        txtPoint: adsk.core.Point3D = circle3.geometry.center.copy()
        txtPoint.translateBy(
            adsk.core.Vector3D.create(
                circle3.radius, 0, 0
            )
        )

        sktDims: adsk.fusion.SketchDimensions = sketch.sketchDimensions
        sktDims.addDiameterDimension(
            circle3,
            txtPoint,
            False
            )

        sketch.areDimensionsShown = True

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

 

Switching an already existing driving dimension to a driven dimension can be done by changing the isDriving property.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-e2826f33-f155-4c12-9ac2-b5ef2f052ea3 

0 Likes