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: 

Reference to ModelParameter object in an expression property?

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
598 Views, 4 Replies

Reference to ModelParameter object in an expression property?

After much experimentation, searching of the forum and exploration of the API documentation, I've been unable to answer a pretty simple question: Is it possible to include a reference to a ModelParameter in the expression property of a UserParameter or another ModelParameter? If it is possible, I'd very much like to know how!

 

For example, if I have a ModelParameter whose name property is "D23" and I'd like to add a SketchOffsetDimension whose value is, say, 0.25 times the current value of the "D23" ModelParameter, how can I do that? I'm sure I'm not the first person with this use case, but I simply can't figure out how to make it happen.

 

I'd really appreciate any hints!

4 REPLIES 4
Message 2 of 5
BrianEkins
in reply to: Anonymous

Here's a small example that creates a diameter dimension that is based on an existing parameter named "MyValue".

 

def run(context):
    try:
        app = adsk.core.Application.get()
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        # Create a new sketch.
        sk = root.sketches.add(root.xYConstructionPlane)
        
        # Draw a circle.
        circ = sk.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 5)
    
        # Add a diameter constraint.
        skDim = sk.sketchDimensions.addDiameterDimension(circ, adsk.core.Point3D.create(5,5,0), True)
        
        # Set the expression of the parameter controlling the dimension constraint.
        skDim.parameter.expression = 'MyValue / 4'
    except:
        app.userInterface.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 5
Anonymous
in reply to: BrianEkins

Thanks for responding and for the example code. The use case I'm struggling with is just slightly different. If I understand correctly, in example code, "MyValue" is the name of a UserParameter object. In the case I'm struggling with the reference has to be to a ModelParameter object.

 

Extending the example a little:

 

def run(context):
    try:
        app = adsk.core.Application.get()
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        # Create a new sketch.
        sk = root.sketches.add(root.xYConstructionPlane)

        <A bunch of code that creates two SketchPoint objects, pointOne and pointTwo, 
        from information elsewhere in the design.>

        # Make a driven dimension across the two points of interest 
        dim = sk.sketchDimensions.addDistanceDimension(
            pointOne,
            pointTwo,
            adsk.fusion.DimensionOrientations.AlignedDimensionOrientation,
            adsk.core.Point3D.create(0, 0, 0),
            False)
        
        # Draw a circle.
        circ = sk.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 5)
    
        # Add a diameter constraint.
        skDim = sk.sketchDimensions.addDiameterDimension(circ, adsk.core.Point3D.create(5,5,0), True)
        
        # Set the controlling the dimension constraint to be 1/4 the distance from pointOne to pointTwo.
        skDim.parameter.expression = dim.parameter.name + ' / 4'
    except:
        app.userInterface.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

This doesn't work because, it appears, dim is a ModelParameter, not a UserParameter. Does this make sense?

Message 4 of 5
BrianEkins
in reply to: Anonymous

My sample code will work with either user or model parameters.  The difference with your code is that the parameter you're trying to reference is associated with a driven dimension constraint.  Fusion 360 doesn't support creating a reference to a driven dimension.  If you look at the parameters dialog, you'll find that parameters associated with driven dimensions aren't displayed so you can't try and create any equations using them.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 5
Anonymous
in reply to: BrianEkins

Ah, thanks so much for the clarification. Yes, I do see that if I enter the name of a ModelParameter that's not a driven dimension in the  Modify->Change Parameters dialog I can create an equation involving that. But if I enter the name of the driven dimension's parameter object, the name reference stays red.

 

So, I need to figure out a different way of creating an equation that represents the distance between two SketchPoint objects. I need an equation because, for a parametric model, the distance between the two points is an arbitrary function of parameters that the user could change. A driven dimension looked so appealing for that.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums