<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Trouble passing ValueInput as argument to features in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014131#M18295</link>
    <description>&lt;P&gt;Try this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;hubCircles.addByCenterRadius(origin, userParams.itemByName("strawDia").value)&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Apr 2017 07:07:22 GMT</pubDate>
    <dc:creator>JeromeBriot</dc:creator>
    <dc:date>2017-04-13T07:07:22Z</dc:date>
    <item>
      <title>Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014048#M18294</link>
      <description>&lt;P&gt;I'm creating some UserParameters, and trying to pass them as arguments during creation of various shapes and features. When passing them, I use ValueInput.createByString("nameOfParameter"). This isn't working (error messages below). It works in the GUI. Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # Get the root component of the active design
        rootComp = design.rootComponent
        
        #defining userParams
        userParams = design.userParameters
        userParams.add("strawDia", adsk.core.ValueInput.createByString("10 mm"), "mm", "")
        userParams.add("noOfPegs", adsk.core.ValueInput.createByString("3"), "", "") 
                
        origin = adsk.core.Point3D.create(0, 0, 0)
        
        #first sketch, central hub
        hubSketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
        hubCircles = hubSketch.sketchCurves.sketchCircles
        hubCircles.addByCenterRadius(origin, adsk.core.ValueInput.createByString("strawDia"))
        
        #uMag = adsk.core.UnitsManager
        #print(uMag.isValidExpression("strawDia*2", "mm"))
        
        

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;&lt;P&gt;To see if it was getting evaluated correctly, I tried to use evaluateExpression and isValidExpression, but it always tells me I have the wrong type/number of arguments despite me adhering to the specification in the documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot use any of the ValueInput creation methods, not even createByReal. Only sending an actual double seems to work.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-04-13 at 11.16.06 AM.png" style="width: 402px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/344314iC0FC67A95C2C735C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2017-04-13 at 11.16.06 AM.png" alt="Screen Shot 2017-04-13 at 11.16.06 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-04-13 at 10.14.20 AM.png" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/344315iC9841DBF267025CB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2017-04-13 at 10.14.20 AM.png" alt="Screen Shot 2017-04-13 at 10.14.20 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could I pointed to what I'm missing?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 05:53:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014048#M18294</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-04-13T05:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014131#M18295</link>
      <description>&lt;P&gt;Try this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;hubCircles.addByCenterRadius(origin, userParams.itemByName("strawDia").value)&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Apr 2017 07:07:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014131#M18295</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2017-04-13T07:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014321#M18296</link>
      <description>&lt;P&gt;Okay, this works, but now if I change the value of strawDia under 'Change User Parameters', the model doesn't update automatically. How do I pass strawDia such that anytime it is modified, the whole model is recomputed and redrawn, just like in the GUI? Or in C++ parlance, how do I pass by reference and not by value?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 09:12:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014321#M18296</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-04-13T09:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014551#M18297</link>
      <description>&lt;PRE&gt;ui.commandDefinitions.itemById('FusionComputeAllCommand').execute()&lt;/PRE&gt;&lt;P&gt;is your friend to force a recmputation&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 11:37:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014551#M18297</guid>
      <dc:creator>designingberlin</dc:creator>
      <dc:date>2017-04-13T11:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014567#M18298</link>
      <description>&lt;P&gt;Add a dimension and link it to the parameter:&lt;/P&gt;&lt;PRE&gt;        origin.x = 1.0
        dim = hubSketch.sketchDimensions.addDiameterDimension(hubCircles.item(0), origin)
        dim.parameter.expression = "strawDia"&lt;/PRE&gt;&lt;P&gt;And as you specify diameter instead of radius, my previous answer should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;hubCircles.addByCenterRadius(origin, 0.5*userParams.itemByName("strawDia").value)&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Apr 2017 11:47:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7014567#M18298</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2017-04-13T11:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7020226#M18299</link>
      <description>&lt;P&gt;This seems to be workable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But why do you change the x-coordinate of origin? Without it, I get an error saying input argument is invalid. What is the text point/dimension text mentioned in the docs?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, after using your code, the circle becomes of size strawDia, while I've assigned the expression "strawDia*2* to it.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 05:31:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7020226#M18299</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-04-17T05:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7020300#M18300</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;swagath.sivakumar a écrit&amp;nbsp;:&lt;BR /&gt;&lt;P&gt;But why do you change the x-coordinate of origin? Without it, I get an error saying input argument is invalid. What is the text point/dimension text mentioned in the docs?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;To add diameter dimension, you need to specify a point that is not the origin of the circle. Read this thread : &lt;A href="https://forums.autodesk.com/t5/api-and-scripts/possible-bug-in-adddiameterdimension/m-p/5457810" target="_self"&gt;Possible bug in addDiameterDimension&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;swagath.sivakumar a écrit&amp;nbsp;:&lt;BR /&gt;&lt;P&gt;Also, after using your code, the circle becomes of size strawDia, while I've assigned the expression "strawDia*2* to it.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Sorry but I don't understant what you mean.&lt;BR /&gt;What value is represented by strawDia ? A diameter or a radius ?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 07:36:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7020300#M18300</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2017-04-17T07:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7020378#M18301</link>
      <description>&lt;P&gt;strawDia is a diameter, but the component I'm creating is not the straw. So all the measurements for this component are proportional to what the straw diameter will be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, thank you for the tip regarding dimensions. The cylinder radii in my model are now completely parametric. Any idea how I can do the same for pattern arguments? Right now, I'm passing a user parameter's value for the countU of a pattern like so:&lt;/P&gt;&lt;PRE&gt;userParams = design.userParameters
userParams.add("noOfPegs", adsk.core.ValueInput.createByString("3"), "", "")
noOfPegs = userParams.itemByName("noOfPegs")


circularFeats = rootComp.features.circularPatternFeatures
circularFeatInput = circularFeats.createInput(inputEntities, zAxis)
circularFeatInput.quantity = adsk.core.ValueInput.createByReal(noOfPegs.value) #&amp;lt;------------------------------- here
circularFeatInput.totalAndle = adsk.core.ValueInput.createByString('360 deg')
circularFeat = circularFeats.add(circularFeatInput)&lt;/PRE&gt;&lt;P&gt;I'm also wanting to use strawDia similarly to set some extrude distances:&lt;/P&gt;&lt;PRE&gt;#make circle for profile, create extrude input, blah blah

extrusionInput.setDistanceExtent(True, adsk.core.ValueInput.createByReal(strawDia.value*1.5))
extrusion = extrudes.add(extrusionInput)&lt;/PRE&gt;&lt;P&gt;I need the measurements to automatically update whenever strawDia changes. Solving this would completely solve my doubt. And thank you, you've been really helpful so far!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 09:23:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7020378#M18301</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-04-17T09:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7020822#M18302</link>
      <description>&lt;P&gt;You can deal with the ModelParameters collection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified the CircularPattern feature API sample available &lt;A href="http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-4C69401B-CDB7-41A2-BA92-19A904B15BB7" target="_self"&gt;here&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        # Create a document.
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
 
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # Define user parameters
        userParams = design.userParameters
        
        if userParams.itemByName("strawDia"):
            userParams.itemByName("strawDia").deleteMe()
        if userParams.itemByName("noOfPegs"):
            userParams.itemByName("noOfPegs").deleteMe()
            
        userParams.add("strawDia", adsk.core.ValueInput.createByString("10 mm"), "mm", "")
        userParams.add("noOfPegs", adsk.core.ValueInput.createByString("3"), "", "") 

        # Get the root component of the active design.
        rootComp = design.rootComponent
        
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)
        sketchCircles = sketch.sketchCurves.sketchCircles
        centerPoint = adsk.core.Point3D.create(10, 0, 0)
        circle = sketchCircles.addByCenterRadius(centerPoint, userParams.itemByName("strawDia").value)

        centerPoint.x = 1.0
        dim = sketch.sketchDimensions.addDiameterDimension(sketchCircles.item(0), centerPoint)
        dim.parameter.expression = "strawDia"        
        
        # Get the profile defined by the circle.
        prof = sketch.profiles.item(0)

        # Create an extrusion input
        extrudes = rootComp.features.extrudeFeatures
        extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        
        # Define that the extent is a distance extent of 5 cm.
        distance = adsk.core.ValueInput.createByReal(5)
        extInput.setDistanceExtent(False, distance)

        # Create the extrusion.
        ext = extrudes.add(extInput)
        
        # Get the body created by extrusion
        body = rootComp.bRepBodies.item(0)
        
        # Create input entities for circular pattern
        inputEntites = adsk.core.ObjectCollection.create()
        inputEntites.add(body)
        
        # Get Y axis for circular pattern
        yAxis = rootComp.yConstructionAxis
        
        # Create the input for circular pattern
        circularFeats = rootComp.features.circularPatternFeatures
        circularFeatInput = circularFeats.createInput(inputEntites, yAxis)
        
        # Set the quantity of the elements
        circularFeatInput.quantity = adsk.core.ValueInput.createByReal(userParams.itemByName("noOfPegs").value)
        
        # Set the angle of the circular pattern
        circularFeatInput.totalAngle = adsk.core.ValueInput.createByString('180 deg')
        
        # Set symmetry of the circular pattern
        circularFeatInput.isSymmetric = False
        
        # Create the circular pattern
        circularFeat = circularFeats.add(circularFeatInput)
        
        # Link feature properties withg user parameters
        for param in rootComp.modelParameters:
            if param.role=="AlongDistance":
                param.expression = "1.5*strawDia"
            if param.role=="countU":
                param.expression = "noOfPegs"
                
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;&lt;P&gt;It's up to you to find the correct parameter in the modelParameters list.&lt;/P&gt;&lt;P&gt;I checked the role property in the code above but it could be different in more complex model.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 14:16:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7020822#M18302</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2017-04-17T14:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble passing ValueInput as argument to features</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7021226#M18303</link>
      <description>&lt;P&gt;Here's a version of your original program that I believe does what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # Get the root component of the active design
        rootComp = design.rootComponent

        #defining userParams
        userParams = design.userParameters
        param = userParams.add("strawDia", adsk.core.ValueInput.createByString("10 mm"), "mm", "")
        diaValue = param.value
        userParams.add("noOfPegs", adsk.core.ValueInput.createByString("3"), "", "") 
                
        origin = adsk.core.Point3D.create(0, 0, 0)
        
        hubSketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
        
        # Draw the circle.
        hubCircles = hubSketch.sketchCurves.sketchCircles
        circle = hubCircles.addByCenterRadius(origin, diaValue/2)

        # Add a dimnension constraint to control the size.
        dims = hubSketch.sketchDimensions
        txtPnt = adsk.core.Point3D.create(origin.x + diaValue*.5, origin.y + diaValue*.5, 0)
        diaDim = dims.addDiameterDimension(circle, txtPnt, True)        
        diaDim.parameter.expression = param.name
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Apr 2017 16:54:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/trouble-passing-valueinput-as-argument-to-features/m-p/7021226#M18303</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2017-04-17T16:54:50Z</dc:date>
    </item>
  </channel>
</rss>

