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: 

How to set sketch dimensions using parametric expression

1 REPLY 1
SOLVED
Reply
Message 1 of 2
leomichine.ca
72 Views, 1 Reply

How to set sketch dimensions using parametric expression

I'm looking for a way to make a created model more parametric by defining some global parameters and then using them to specify dimensions for features and sketches. It seems to be trivial for features using 

ValueInput.createByStgring, however, it looks like sketch dimensions would only accept float values. Is there a way to use string expressions when defining sketch dimensions like it is possible through the UI?
1 REPLY 1
Message 2 of 2

hi,

 

In the following code snippet you can find how to set a user parameter, and then use it to constraint the distance between two sketch points:

    DISTANCE_PARAMETER_NAME = "points_distance"

    # to create a new user parameter
    dist_par = des.userParameters.add(DISTANCE_PARAMETER_NAME, adsk.core.ValueInput.createByString("40 mm"), "mm","")

    # to create a new sketch and 2 points on it
    sk = root.sketches.add(root.xYConstructionPlane)
    sk.areDimensionsShown = True
    sp1 = sk.sketchPoints.add(adsk.core.Point3D.create(1,1,0))
    sp2 = sk.sketchPoints.add(adsk.core.Point3D.create(10,0,0))

    # to add a distance dimension between the two points
    sld = sk.sketchDimensions.addDistanceDimension(
        sp1, 
        sp2, 
        adsk.fusion.DimensionOrientations.AlignedDimensionOrientation,
        sk.sketchPoints[0].geometry,
        True)
    
    # to set the parameter expression with the user parameter on first step
    sld.parameter.expression = DISTANCE_PARAMETER_NAME

 

You will see that updating the user parameter value, the points are moved to meet the distance required.

 

Regards,

Jorge Jaramillo

Software Engineer

 

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