<?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: Script to change parameter values in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904622#M20630</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2549199"&gt;@prainsberry&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Actually it is a reference to the actual body object. &amp;nbsp;So you would do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN&gt;# Get application reference&lt;BR /&gt;app = adsk.core.Application.get()&lt;/SPAN&gt;&lt;BR /&gt;design = app.activeProduct&lt;BR /&gt;&lt;BR /&gt;#Get Root Component&lt;BR /&gt;rootComp &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; design.rootComponent&lt;BR /&gt;&lt;BR /&gt;# Get All bodies in Design&lt;BR /&gt;&lt;/SPAN&gt;bRepBodies_var = rootComp.bRepBodies&lt;BR /&gt;&lt;BR /&gt;# Find the body with a given Name&lt;BR /&gt;body = bRepBodies_var.&lt;STRONG&gt;itemByName&lt;/STRONG&gt;('My body Name')&lt;BR /&gt;&lt;BR /&gt;# Set visibility of the Body&lt;BR /&gt;body.isVisible = True&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That didn't work for me; I'm getting the error: AttributeError: NoneType object has no attribute isVisible. &amp;nbsp;It seems the itemByName()&amp;nbsp;didn't work. &amp;nbsp;Is there a way to list&amp;nbsp;all the bodies it finds? &amp;nbsp;Also, how can I test for NoneType so I know if it found the body or not.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Nov 2015 12:46:23 GMT</pubDate>
    <dc:creator>SGoldthwaite</dc:creator>
    <dc:date>2015-11-12T12:46:23Z</dc:date>
    <item>
      <title>Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904031#M20622</link>
      <description>&lt;P&gt;I've never tried scripts with Fusion 360 and I currently have a need for something which I think should be pretty simple. &amp;nbsp;I have two versions of a part and I have named parameter values setup where I can change about a dozen of them to make the other version of the part. &amp;nbsp;I'd like to be able to switch back and forth between the two versions by running a script that just sets these dozen parameters. &amp;nbsp;Can someone give me an idea on how to do this? &amp;nbsp;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 00:25:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904031#M20622</guid>
      <dc:creator>SGoldthwaite</dc:creator>
      <dc:date>2015-11-12T00:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904045#M20623</link>
      <description>&lt;P&gt;It is fairly simple to edit the user parameters.&amp;nbsp; Model parameters are also possible but a little more difficult because they can be scattered around in various components whereas there is only one set of user parameters for the entire design.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program below changes two user parameters called "Length" and "Height" and depending on how you answer the message box will change them to one of two sets of values.&amp;nbsp; You can change the names to whatever your parameters are called.&amp;nbsp; Setting the expression property is exactly the same as changing it in the dialog and it supports all of the same things.&amp;nbsp; For example you can specify the units as part of the string, i.e. "3 in" or "2 mm".&amp;nbsp; Just "3" will default to 3 of whatever the current design unit is.&amp;nbsp; You can also use equations and reference other parameters.&amp;nbsp; For example, "(3 + Length)/2".&amp;nbsp; If you use the "Scripts and Add-Ins" command to create a new script you can copy the code below and replace the run function in the created code.&amp;nbsp; Then you can run it from the "Scripts and Add-Ins"&amp;nbsp; command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        des = adsk.fusion.Design.cast(app.activeProduct)
        userParams = des.userParameters
        
        if ui.messageBox('Change to configuration one?', 'Parameter Edit', adsk.core.MessageBoxButtonTypes.YesNoButtonType, adsk.core.MessageBoxIconTypes.QuestionIconType) == adsk.core.DialogResults.DialogYes:
            userParams.itemByName('Length').expression = '50'
            userParams.itemByName('Height').expression = '30'
        else:
            userParams.itemByName('Length').expression = '30'
            userParams.itemByName('Height').expression = '20'
            
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))   
&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Nov 2015 00:57:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904045#M20623</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-11-12T00:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904093#M20624</link>
      <description>&lt;P&gt;I forgot about the Design.allParameters property.&amp;nbsp; This returns all of the parameters in design, both Model and User parameters so using that makes it easy to use both.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 02:17:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904093#M20624</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-11-12T02:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904153#M20625</link>
      <description>&lt;P&gt;Thanks. &amp;nbsp;I modify your example and see how it works.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 04:06:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904153#M20625</guid>
      <dc:creator>SGoldthwaite</dc:creator>
      <dc:date>2015-11-12T04:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904174#M20626</link>
      <description>&lt;P&gt;That worked great. I have a follow up question: How can I hide and unhide a body.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 05:10:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904174#M20626</guid>
      <dc:creator>SGoldthwaite</dc:creator>
      <dc:date>2015-11-12T05:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904185#M20627</link>
      <description>You use:
body.isVisible = True or False


Check out this sample:
&lt;A href="https://github.com/tapnair/ShowHidden/blob/master/ShowHidden.py" target="_blank"&gt;https://github.com/tapnair/ShowHidden/blob/master/ShowHidden.py&lt;/A&gt;


Regards,
Patrick Rainsberry</description>
      <pubDate>Thu, 12 Nov 2015 05:33:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904185#M20627</guid>
      <dc:creator>prainsberry</dc:creator>
      <dc:date>2015-11-12T05:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904186#M20628</link>
      <description>&lt;P&gt;is "body" in body.isVislble&amp;nbsp;= True the name of the body? &amp;nbsp;So if my body was named bolt1, I'd use: bolt1.isVisible = true. &amp;nbsp;If so, how do I handle a body where theres a space in the name. &amp;nbsp;Let's say my body is called "Front Bolt"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 05:37:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904186#M20628</guid>
      <dc:creator>SGoldthwaite</dc:creator>
      <dc:date>2015-11-12T05:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904189#M20629</link>
      <description>&lt;P&gt;Actually it is a reference to the actual body object. &amp;nbsp;So you would do something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN&gt;# Get application reference&lt;BR /&gt;app = adsk.core.Application.get()&lt;/SPAN&gt;&lt;BR /&gt;design = app.activeProduct&lt;BR /&gt;&lt;BR /&gt;#Get Root Component&lt;BR /&gt;rootComp &lt;/SPAN&gt;&lt;SPAN class="pl-k"&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; design.rootComponent&lt;BR /&gt;&lt;BR /&gt;# Get All bodies in Design&lt;BR /&gt;&lt;/SPAN&gt;bRepBodies_var = rootComp.bRepBodies&lt;BR /&gt;&lt;BR /&gt;# Find the body with a given Name&lt;BR /&gt;body = bRepBodies_var.&lt;STRONG&gt;itemByName&lt;/STRONG&gt;('My body Name')&lt;BR /&gt;&lt;BR /&gt;# Set visibility of the Body&lt;BR /&gt;body.isVisible = True&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 05:46:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904189#M20629</guid>
      <dc:creator>prainsberry</dc:creator>
      <dc:date>2015-11-12T05:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904622#M20630</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2549199"&gt;@prainsberry&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Actually it is a reference to the actual body object. &amp;nbsp;So you would do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN&gt;# Get application reference&lt;BR /&gt;app = adsk.core.Application.get()&lt;/SPAN&gt;&lt;BR /&gt;design = app.activeProduct&lt;BR /&gt;&lt;BR /&gt;#Get Root Component&lt;BR /&gt;rootComp &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; design.rootComponent&lt;BR /&gt;&lt;BR /&gt;# Get All bodies in Design&lt;BR /&gt;&lt;/SPAN&gt;bRepBodies_var = rootComp.bRepBodies&lt;BR /&gt;&lt;BR /&gt;# Find the body with a given Name&lt;BR /&gt;body = bRepBodies_var.&lt;STRONG&gt;itemByName&lt;/STRONG&gt;('My body Name')&lt;BR /&gt;&lt;BR /&gt;# Set visibility of the Body&lt;BR /&gt;body.isVisible = True&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That didn't work for me; I'm getting the error: AttributeError: NoneType object has no attribute isVisible. &amp;nbsp;It seems the itemByName()&amp;nbsp;didn't work. &amp;nbsp;Is there a way to list&amp;nbsp;all the bodies it finds? &amp;nbsp;Also, how can I test for NoneType so I know if it found the body or not.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 12:46:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5904622#M20630</guid>
      <dc:creator>SGoldthwaite</dc:creator>
      <dc:date>2015-11-12T12:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5905318#M20631</link>
      <description>&lt;P&gt;You changed 'My Body Name" to the name of the body in the design, correct? &amp;nbsp;Note it is case sensitive. &amp;nbsp;The error means that it is not finding the body of that name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can check if an object is "None" in python with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lang-py prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="kwd"&gt;if&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; body &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;is&lt;/SPAN&gt; &lt;SPAN class="kwd"&gt;None&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;BR /&gt;&lt;BR /&gt;# OR:&lt;BR /&gt;&lt;BR /&gt;if body is not None:&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So it would look something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN&gt;# Get application reference&lt;BR /&gt;app = adsk.core.Application.get()&lt;/SPAN&gt;&lt;BR /&gt;design = app.activeProduct&lt;BR /&gt;&lt;BR /&gt;#Get Root Component&lt;BR /&gt;rootComp &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; design.rootComponent&lt;BR /&gt;&lt;BR /&gt;# Get All bodies in Design&lt;BR /&gt;&lt;/SPAN&gt;bRepBodies_var = rootComp.bRepBodies&lt;BR /&gt;&lt;BR /&gt;# Find the body with a given Name&lt;BR /&gt;body = bRepBodies_var.&lt;STRONG&gt;itemByName&lt;/STRONG&gt;('My body Name')&lt;BR /&gt;&lt;BR /&gt;# Set visibility of the Body&lt;BR /&gt;if body is not None:&lt;BR /&gt;   body.isVisible = True&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 17:40:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5905318#M20631</guid>
      <dc:creator>prainsberry</dc:creator>
      <dc:date>2015-11-12T17:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5905324#M20632</link>
      <description>&lt;P&gt;Oh also if the bodies you are looking for are not in the root COmponent and are in a sub component then you would need to call the brep bodies on the component you are interested in not the root component? Maybe this is the problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 17:43:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5905324#M20632</guid>
      <dc:creator>prainsberry</dc:creator>
      <dc:date>2015-11-12T17:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5905329#M20633</link>
      <description>&lt;P&gt;My bodies are not in the root component. &amp;nbsp;That's probably the problem.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 17:46:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5905329#M20633</guid>
      <dc:creator>SGoldthwaite</dc:creator>
      <dc:date>2015-11-12T17:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Script to change parameter values</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5905387#M20634</link>
      <description>&lt;P&gt;Ok here this should work. &amp;nbsp;Kind of long for what you are trying to do but it looks like there is not an itemByName method on components:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;#Author-
#Description-

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        # Get application reference
        app = adsk.core.Application.get()
        design = app.activeProduct
        
        # Get all components in design
        allComponents_var = design.allComponents
        
        # Loop through all components
        for component_var in allComponents_var:
            
            # Find the correct compoenent
            if component_var.name == "My Component":
                
                # Get All bodies in Component
                bRepBodies_var = component_var.bRepBodies
        
                # Find the body with a given Name
                body = bRepBodies_var.itemByName('My Body')
                
                # Set visibility of the Body
                if body is not None:
                    body.isVisible = True

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Nov 2015 18:20:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/5905387#M20634</guid>
      <dc:creator>prainsberry</dc:creator>
      <dc:date>2015-11-12T18:20:17Z</dc:date>
    </item>
    <item>
      <title>Is model entirely computed at every parameter change?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/9536432#M20635</link>
      <description>&lt;P&gt;Like&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2549199"&gt;@prainsberry&lt;/a&gt;&amp;nbsp;&amp;nbsp;I use a set of params (actual number is 13) to configure different versions of my product.&lt;BR /&gt;&lt;BR /&gt;PERFORMANCE PROBLEMS&lt;BR /&gt;When I manually change every single param in the dialog box, model computing automatically starts. This operation takes minutes. Since I have many parameters, when I need to switch from a version to another, I waste a lot of time in waiting for computing operations that are not useful, because they compute a partial configuration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CAN SCRIPTING HELP ME?&lt;/P&gt;&lt;P&gt;Is it possible to make model computing start one time only, that is when I have finished to set up ALL my 13 params?&lt;/P&gt;</description>
      <pubDate>Sun, 24 May 2020 04:32:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/9536432#M20635</guid>
      <dc:creator>luca.giorcelli</dc:creator>
      <dc:date>2020-05-24T04:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is model entirely computed at every parameter change?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/9536442#M20636</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Unfortunately, Fusion doesn't support delaying the compute while you change multiple parameters, either in the UI or the API.  I've been asking for it for years.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 May 2020 04:56:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/9536442#M20636</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2020-05-24T04:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Is model entirely computed at every parameter change?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/9908973#M20637</link>
      <description>&lt;P&gt;There is a workaround to that : move the timeline history marker backwards (up to root if needed), change your parameters, then move back the history marker at the end.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 09:37:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-change-parameter-values/m-p/9908973#M20637</guid>
      <dc:creator>gamelife4dns</dc:creator>
      <dc:date>2020-12-02T09:37:01Z</dc:date>
    </item>
  </channel>
</rss>

