fusion api sketches lines

fusion api sketches lines

grosfaignan
Enthusiast Enthusiast
1,048 Views
3 Replies
Message 1 of 4

fusion api sketches lines

grosfaignan
Enthusiast
Enthusiast

hi there, i need to create some lines in python scripts, then add them length and then add them dimension (placement) from origin, how can i do that ?

 

thanks

0 Likes
1,049 Views
3 Replies
Replies (3)
Message 2 of 4

Rushikesh.kadam
Autodesk
Autodesk

@grosfaignan here are some sample links that demonstrate creating sketch lines and adding sketch dimensions.

Here is another link explaining the sketch dimensions object https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-ea0faa88-65eb-4845-b2ce-22d0640bedf4 .Under the topic Samples, there few more examples related to dimension. 

------------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed.

 




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


Message 3 of 4

Jorge_Jaramillo
Collaborator
Collaborator

Hi @grosfaignan ,

 

Here you have a fragment of python code to create sketch lines and dimension one of them with a user parameter:

app: adsk.core.Application = adsk.core.Application.get()
DISTANCE_PARAMETER = 'distance'
design = adsk.fusion.Design.cast(app.activeProduct)

# 1) user parameter
distParam = design.userParameters.itemByName(DISTANCE_PARAMETER)
if not distParam:
    # create user parameter if not found
    distVal = adsk.core.ValueInput.createByString('35 mm')
    distParam = design.userParameters.add(DISTANCE_PARAMETER, distVal, 'mm', '')

# 2) sketch
rootComp = adsk.fusion.Component.cast(design.rootComponent)
# Create a new sketch on the xy plane.
sketches = rootComp.sketches
sketch = sketches.itemByName('xySketch')
sketch.areDimensionsShown = True  #display dimensions on the sketch
if not sketch:
    # create sketch if not found
    xyPlane = rootComp.xYConstructionPlane
    sketch = adsk.fusion.Sketch.cast(sketches.add(xyPlane))
    sketch.name = 'xySketch'

    # 3) create sketch points
    p1 = sketch.sketchPoints.add(adsk.core.Point3D.create(1, 0, 0))
    p2 = sketch.sketchPoints.add(adsk.core.Point3D.create(3, 1, 0))

    # 4) create 2 lines, sharing p1 as a coincident constraint
    line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(sketch.originPoint, p1)
    line2 = sketch.sketchCurves.sketchLines.addByTwoPoints(p1, p2)

    # 5) add dimension to line1
    sld = sketch.sketchDimensions.addDistanceDimension(sketch.originPoint, p1, adsk.fusion.DimensionOrientations.AlignedDimensionOrientation, adsk.core.Point3D.create(0, 2, 0))

    # 6) get model parameter from the sketch dimension and assign a user parameter to its expression
    modelParam = adsk.fusion.ModelParameter.cast(sld.parameter)
    modelParam.expression = DISTANCE_PARAMETER

 

This is the result:

Captura de pantalla 2022-07-07 112440.png

 

Hope it helps.

Let me know if it works for you.

 

Regards,

Jorge

 

0 Likes
Message 4 of 4

Jorge_Jaramillo
Collaborator
Collaborator
Please correct in the previous code, moving this line :
sketch.areDimensionsShown = True
after
sketch.name = 'xySketch'.
Sorry!!.
0 Likes