<?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: Creating parameters with script problem in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9680922#M11030</link>
    <description>&lt;P&gt;Assuming that the ScrewDiameter is a number, you need to use ValueInput.createByReal to create the value that you use to save the parameter. You can’t store the number directly.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ScrewDiameterParam.add('ScrewDiameter', ValueInput.createByReal(ScrewDiameter), 'in', '')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/hobbyistmaker/silvanus/blob/develop/lib/generatebox/save.py" target="_blank" rel="noopener"&gt;Here’s some code&lt;/A&gt;&lt;SPAN style="font-family: inherit; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;"&gt; that I’m using for something similar.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 09 Aug 2020 02:58:23 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-08-09T02:58:23Z</dc:date>
    <item>
      <title>Creating parameters with script problem</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9680672#M11029</link>
      <description>&lt;P&gt;My first try at scripting so please bear with me.&lt;/P&gt;&lt;P&gt;I have gone through the forum and tried lots of different examples, but nothing seem to work.&lt;/P&gt;&lt;P&gt;I am reading a csv file and then trying to create some user parameters.&lt;/P&gt;&lt;P&gt;I am reading the file ok and get the correct values, but when I try to create the parameters, BOOM:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;This is the code in question:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;cnt&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;file&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;open&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'C:/Users/bradb/AppData/Roaming/Autodesk/Autodesk&amp;nbsp;Fusion&amp;nbsp;360/API/Scripts/SHCStest/SHCS-IMPERIAL.csv'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;for&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;line&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;file:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;#&amp;nbsp;Get&amp;nbsp;the&amp;nbsp;values&amp;nbsp;from&amp;nbsp;the&amp;nbsp;csv&amp;nbsp;file.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pieces&amp;nbsp;=&amp;nbsp;line.split(&lt;/SPAN&gt;&lt;SPAN&gt;','&lt;/SPAN&gt;&lt;SPAN&gt;)&l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=&amp;nbsp;pieces[&lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HeadFillet&amp;nbsp;=&amp;nbsp;pieces[&lt;/SPAN&gt;&lt;SPAN&gt;6&lt;/SPAN&gt;&lt;SPAN&gt;]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;#&amp;nbsp;Create&amp;nbsp;user&amp;nbsp;parameters&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;#&amp;nbsp;Set&amp;nbsp;the&amp;nbsp;parameters.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ScrewDiameterParam&amp;nbsp;=&amp;nbsp;design.userParameters&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ScrewDiameterParam.add(&lt;/SPAN&gt;&lt;SPAN&gt;'ScrewDiameter'&lt;/SPAN&gt;&lt;SPAN&gt;,&amp;nbsp;ScrewDiameter,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;'in'&lt;/SPAN&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Being new I am not sure how to track down the proper syntax, arguments, etc&amp;nbsp; in the documentation.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any help is appreciated.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you in advance.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Brad&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 08 Aug 2020 19:17:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9680672#M11029</guid>
      <dc:creator>brad.bylls</dc:creator>
      <dc:date>2020-08-08T19:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating parameters with script problem</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9680922#M11030</link>
      <description>&lt;P&gt;Assuming that the ScrewDiameter is a number, you need to use ValueInput.createByReal to create the value that you use to save the parameter. You can’t store the number directly.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ScrewDiameterParam.add('ScrewDiameter', ValueInput.createByReal(ScrewDiameter), 'in', '')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/hobbyistmaker/silvanus/blob/develop/lib/generatebox/save.py" target="_blank" rel="noopener"&gt;Here’s some code&lt;/A&gt;&lt;SPAN style="font-family: inherit; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;"&gt; that I’m using for something similar.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Aug 2020 02:58:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9680922#M11030</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-09T02:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating parameters with script problem</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9681350#M11031</link>
      <description>&lt;P&gt;There was supposed to be a picture showing the error message. Here is the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="description"&gt;&lt;FONT color="#FF0000"&gt;in method 'UserParameters_add', argument 3 of type 'adsk::core::Ptr&amp;lt; adsk::core::ValueInput &amp;gt; const &amp;amp;'&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="stack-trace"&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;File "&lt;A title="Ctrl + click to follow link" target="_blank"&gt;c:\users\bradb\appdata\local\autodesk\webdeploy\production\d2d901e2ef5ae5c384b4ac001a48c4e37589dc43\api\python\packages\adsk\fusion.py&lt;/A&gt;", line 31754, in add return _fusion.UserParameters_add(self, *args) File "&lt;A&gt;c:\Users\bradb\AppData\Roaming\Autodesk\Autodesk&lt;/A&gt; Fusion 360\API\Scripts\SHCStest\SHCStest.py", line 30, in &amp;lt;module&amp;gt; ScrewDiameterParam.add('ScrewDiameter', ScrewDiameter, 'in', '')&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 09 Aug 2020 20:04:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9681350#M11031</guid>
      <dc:creator>brad.bylls</dc:creator>
      <dc:date>2020-08-09T20:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating parameters with script problem</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9681355#M11032</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;I tried it, but an error message said 'ValueInput not created'&lt;/P&gt;&lt;P&gt;I also looked at your code and found nothing similar.&lt;/P&gt;&lt;P&gt;I am a newbe and must be missing something.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Aug 2020 20:08:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9681355#M11032</guid>
      <dc:creator>brad.bylls</dc:creator>
      <dc:date>2020-08-09T20:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating parameters with script problem</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9681368#M11033</link>
      <description>&lt;P&gt;I wasn't thinking when I replied to you. I'm guessing that when you are reading the file, the ScrewDiameter is being read as a string, in which case, you need to use ValueInput.createByString instead of createByReal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;cnt = 0
file = open('C:/Users/bradb/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Scripts/SHCStest/SHCS-IMPERIAL.csv')
for line in file:
   # Get the values from the csv file.
    pieces = line.split(',')

    if pieces[0] == '1/2-13':
        ScrewDiameter = pieces[1]
        HeadDiameter = pieces[2]
        HexSize = pieces[4]
        TapDrill = pieces[5]
        HeadFillet = pieces[6]            
        
        # Create user parameters
        # Set the parameters.

        ScrewDiameterParam = design.userParameters
        ScrewDiameterParam.add('ScrewDiameter', ValueInput.createByString(ScrewDiameter), 'in', '')
 &lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 09 Aug 2020 20:18:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9681368#M11033</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-09T20:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating parameters with script problem</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9684998#M11035</link>
      <description>&lt;P&gt;That didn't work, but I finally tracked down some code that did.&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?caas=caas/discussion/t5/Fusion-360-API-and-Scripts/csv-script/td-p/5925524.html" target="_blank"&gt;https://help.autodesk.com/view/fusion360/ENU/?caas=caas/discussion/t5/Fusion-360-API-and-Scripts/csv-script/td-p/5925524.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thank you for the input.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 13:18:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/9684998#M11035</guid>
      <dc:creator>brad.bylls</dc:creator>
      <dc:date>2020-08-11T13:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating parameters with script problem</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/10939686#M11036</link>
      <description>&lt;P&gt;Since this was the closest answer to a question I struggled with I thought I would add to it.&amp;nbsp; The api example reading from the CSV works if you want to do that, but I was wanting to just create a parameter directly.&amp;nbsp; Without getting into user inputs here is the basic code.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)

        #retParam = design.userParameters.itemByName('Size')
        #ui.messageBox(retParam.expression)
        widthValueInput = 5.0
        inputUnits = 'mm'
        widthValuePass = widthValueInput / 10
        widthValue = adsk.core.ValueInput.createByReal(widthValuePass)
        design.userParameters.add('width',widthValue,inputUnits,'')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; I left the retParam in there commented out because I used that to find if a parameter was in the design and then I returned the expression from that back to the user.&amp;nbsp; I thought it might be helpful for anyone trying to do this.&amp;nbsp; I did leave an input value(even though the code isn't prompting the user) and the widthValuePass is converting it from cm to mm before using ValueInput.createByReal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps someone!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 16:56:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/10939686#M11036</guid>
      <dc:creator>MattPerez314</dc:creator>
      <dc:date>2022-02-09T16:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating parameters with script problem</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/10939832#M11037</link>
      <description>&lt;P&gt;Thanks for the input.&lt;/P&gt;&lt;P&gt;This is what I ended up doing.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;# Create user parameters
	userParams = des.userParameters
	MOLDparam = userParams.add('Mold_Exists', adsk.core.ValueInput.createByString('Exists'), '', 'Exists')
	TCPparam = userParams.add('TCP_thickness', adsk.core.ValueInput.createByReal(numPlateTCPthickness), 'in', 'TCP Plate Thickness')
	Aparam = userParams.add('A_thickness', adsk.core.ValueInput.createByReal(numPlateAthickness), 'in', 'A Plate Thickness')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;And then used this to update the model parameters using the User Parameters&lt;/P&gt;&lt;LI-CODE lang="general"&gt;# Modify model parameters
	# TCP plate
	extent_1 = plateTCPext.extentOne
	extent_2 = plateTCPext.extentTwo
	distanceMP_1 = extent_1.distance
	distanceMP_2 = extent_2.distance
	distanceMP_1.expression = 'TCP_thickness + A_thickness'
	distanceMP_2.expression = 'A_thickness * -1'&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 09 Feb 2022 17:46:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/creating-parameters-with-script-problem/m-p/10939832#M11037</guid>
      <dc:creator>brad.bylls</dc:creator>
      <dc:date>2022-02-09T17:46:39Z</dc:date>
    </item>
  </channel>
</rss>

