Setting model parameters

Setting model parameters

jeremiahrose
Enthusiast Enthusiast
1,196 Views
1 Reply
Message 1 of 2

Setting model parameters

jeremiahrose
Enthusiast
Enthusiast

I am using the API to sketch many circles like this:

circle = sketch.sketchCurves.sketchCircles.addByCenterRadius(center, 10)

However, what I actually want to do is set each circle's radius to equal a user parameter called "userRadius". If I was doing this in the UI, I would sketch the circle and enter the string "userRadius" into the radius input box, but the addByCenterRadius function does not accept a string.

 

I'm aware that you can use the ModelParameters object to get an individual parameters by calling "itemByName", but this isn't useful at all because I do not know the name of the parameter. And I can't find a way to get the parameter name ("d1" "d22" "d76" etc) from the circle object.

How do I create an object and set its dimensions to equal a user parameter in the API? How do I create a model parameter? How do I find the model parameters associated with a particular object if all I have is the object as a variable?

 

Thanks!
Jerry

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

jeremiahrose
Enthusiast
Enthusiast
Accepted solution

Figured it out. I needed to add a SketchRadialDimension to the SketchCircle, then access the ModelParameter from there and set it's expression:

# create a SketchCircle with a placeholder radius. centerPoint is a Point3D
circle = sketch.sketchCurves.sketchCircles.addByCenterRadius(centerPoint, 1)
# create a SketchRadialDimension to constrain the circle's radius. textPoint is the position of the dimension's text.
rd = sketch.sketchDimensions.addRadialDimension(circle, textPoint, True)
# Set the expression of the parameter
rd.parameter.expression = 'userRadius'
0 Likes