How to set sketch dimensions using parametric expression

How to set sketch dimensions using parametric expression

leomichine.ca
Explorer Explorer
358 Views
1 Reply
Message 1 of 2

How to set sketch dimensions using parametric expression

leomichine.ca
Explorer
Explorer

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?
0 Likes
Accepted solutions (1)
359 Views
1 Reply
Reply (1)
Message 2 of 2

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

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