<?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 autofavorite named model parameters in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9743328#M10815</link>
    <description>&lt;P&gt;Works great, thank you!&amp;nbsp; This Add-in should be made more widely available.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 12 Sep 2020 01:49:39 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-09-12T01:49:39Z</dc:date>
    <item>
      <title>Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9733393#M10805</link>
      <description>&lt;P&gt;It's really nice that model parameters such as sketch dimensions, extrude distances etc. can be named on the fly by typing a new name, the equal sign, and then the desired value.&amp;nbsp; However to then get these named model parameters to show in a popup list when typing a parameter in, it must be dug up and favorited in the Change Parameters tool.&amp;nbsp; I was just curious if there might be any scripting possibility to automatically favorite all custom named model parameters?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 14:43:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9733393#M10805</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-07T14:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9733755#M10806</link>
      <description>&lt;P&gt;I just thought exact the same thing. I have no experience in making custom scripts for fusion but will follow this thread with interest.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 20:09:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9733755#M10806</guid>
      <dc:creator>Olle_Eriksson</dc:creator>
      <dc:date>2020-09-07T20:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9736650#M10807</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'Parameter.isFavorite' is a read/write property.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2ab75499-ce0d-4744-b6c5-e5a6fb4ac6cc" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2ab75499-ce0d-4744-b6c5-e5a6fb4ac6cc&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        des  :adsk.fusion.Design = _app.activeProduct

        # init UserParamete
        length = adsk.core.ValueInput.createByString("1 cm")
        prm = des.userParameters.add('test', length, 'cm', 'hoge')

        # Favorite
        prm.isFavorite = True

        _ui.messageBox('Done')
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 09 Sep 2020 03:44:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9736650#M10807</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2020-09-09T03:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9736689#M10808</link>
      <description>&lt;P&gt;Sorry, I misunderstood.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # get ModelParameter
        prm = getModelParameter_itemByName('test')

        # Favorite
        if prm:
            prm.isFavorite = True

        _ui.messageBox('Done')
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def getModelParameter_itemByName(
    targetName :str) -&amp;gt; adsk.fusion.ModelParameter:

    des  :adsk.fusion.Design = _app.activeProduct

    prm = adsk.fusion.ModelParameter.cast(None)
    for comp in des.allComponents:
        prm = comp.modelParameters.itemByName(targetName)
        if prm:
            return prm
    
    return prm&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 09 Sep 2020 04:18:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9736689#M10808</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2020-09-09T04:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9738899#M10809</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt; for the script!&amp;nbsp; I've never tried scripting before with Fusion and don't know python, but pasted your script into a newly created script in Visual Studio, saved it then ran it in Fusion.&amp;nbsp; After a little while a dialog box appeared that said "Done" and click ok.&amp;nbsp; However after I tried naming a new system variable, it does not appear that it automatically gets favorited &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp; Any suggestions?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2020 01:54:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9738899#M10809</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-10T01:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9739006#M10810</link>
      <description>&lt;P&gt;Try making the 'test' part the name of the desired parameter.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;・・・
        # get ModelParameter
        prm = getModelParameter_itemByName('test')
・・・&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2020 03:22:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9739006#M10810</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2020-09-10T03:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9740447#M10811</link>
      <description>&lt;P&gt;Hello&amp;nbsp;@Anonymous&amp;nbsp;I think maybe what you were looking for was a script that would determine if the parameter had ANY user defined name?&amp;nbsp; Here is another example where I assume any name that is not a "d" followed by an integer is something custom and then will add it as a favorite.&amp;nbsp; Also FYI&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4117691"&gt;@Olle_Eriksson&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;Nice script though&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt;&amp;nbsp;!&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Author - Patrick Rainsberry
# Description - Simple script to make favorites out of named parameters

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None

    # This is not nnecessary but makes code complete work better
    app: adsk.core.Application
    document: adsk.fusion.FusionDocument
    parameter: adsk.fusion.Parameter
    
    try:
        
        # Get various application objects
        app = adsk.core.Application.get()
        ui  = app.userInterface
        document = app.activeDocument
        design = document.design
        all_params = design.allParameters
        
        # Lets count the number of favorites added
        count = 0

        # Iterate over all parameters in the design 
        # Note: Intentionally verbose to make it easier to follow.
        for parameter in all_params:
            is_named_parameter = True
            
            # Check if first character is not a "d"
            if parameter.name[0] == 'd':
                # Check if the rest of the name is not a positive integer
                if parameter.name[1:].isdigit():
                    is_named_parameter = False
            
            # Check if it has a user defined name
            if is_named_parameter:
                
                # Only increment count if it wasn't already a favorite
                if not parameter.isFavorite:
                    count += 1
                
                # Set the parameter as a favorite
                parameter.isFavorite = True              

        # Feedback message, uses Python Format String
        ui.messageBox(f'All done! {count} parameters added to favorites')
    
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 10 Sep 2020 16:28:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9740447#M10811</guid>
      <dc:creator>prainsberry</dc:creator>
      <dc:date>2020-09-10T16:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9740772#M10812</link>
      <description>&lt;P&gt;Thanks a lot, I will try this in the next day or so when I am at my computer.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2020 19:08:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9740772#M10812</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-10T19:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9743270#M10813</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2549199"&gt;@prainsberry&lt;/a&gt; the script works great!&amp;nbsp; My only last question is if it might be possible to somehow make this an Add-on continuously running in the background?&amp;nbsp; Perhaps it could detect when the model parameter count changed?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 00:08:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9743270#M10813</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-12T00:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9743291#M10814</link>
      <description>&lt;P&gt;Here is a quick way to do that.&amp;nbsp; Basically it will check after every command.&amp;nbsp; It's a little over the top in how often it would run, but it is such a quick execution you probably won't really notice it.&amp;nbsp; &amp;nbsp;Just create a new addin and paste this in:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#Author-Patrick Rainsberry
#Description-Continuously monitors Model Parameters for changes to name and then adds parameter to favorites.  

import adsk.cam
import adsk.core
import adsk.fusion
import traceback

# Global variable used to maintain a reference to all event handlers.
handlers = []


def check_favorites():
    # This is not necessary but makes code complete work better
    app: adsk.core.Application
    document: adsk.fusion.FusionDocument
    parameter: adsk.fusion.Parameter

    # Get various application objects
    app = adsk.core.Application.get()
    document = app.activeDocument
    design = document.design
    all_params = design.allParameters

    # Lets count the number of favorites added
    count = 0

    # Iterate over all parameters in the design
    # Note: Intentionally verbose to make it easier to follow.
    for parameter in all_params:
        is_named_parameter = True

        # Check if first character is not a "d"
        if parameter.name[0] == 'd':
            # Check if the rest of the name is not a positive integer
            if parameter.name[1:].isdigit():
                is_named_parameter = False

        # Check if it has a user defined name
        if is_named_parameter:

            # Only increment count if it wasn't already a favorite
            if not parameter.isFavorite:
                count += 1

            # Set the parameter as a favorite
            parameter.isFavorite = True


# Event handler for the commandTerminated event.
class MyCommandTerminatedHandler(adsk.core.ApplicationCommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args):
        event_args = adsk.core.ApplicationCommandEventArgs.cast(args)

        # Will check favorites after every command completes for anything except the select command.
        if event_args.commandId != "SelectCommand":
            check_favorites()


def run(context):
    global handlers
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        onCommandTerminated = MyCommandTerminatedHandler()
        ui.commandTerminated.add(onCommandTerminated)
        handlers.append(onCommandTerminated)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def stop(context):
    global handlers
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        for handler in handlers:
            ui.commandTerminated.remove(handler)
        ui.messageBox('Stopped Favorites addin')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 12 Sep 2020 00:36:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9743291#M10814</guid>
      <dc:creator>prainsberry</dc:creator>
      <dc:date>2020-09-12T00:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9743328#M10815</link>
      <description>&lt;P&gt;Works great, thank you!&amp;nbsp; This Add-in should be made more widely available.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 01:49:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9743328#M10815</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-12T01:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9744316#M10816</link>
      <description>&lt;P&gt;This is really great! Makes the new feature of naming parameters as you dimension actually useful. Greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 10:19:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9744316#M10816</guid>
      <dc:creator>Olle_Eriksson</dc:creator>
      <dc:date>2020-09-13T10:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9744512#M10817</link>
      <description>&lt;P&gt;Your script seems to work perfectly so far as an add-in. I'm looking forward to using it more with the direct dimension naming.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2549199"&gt;@prainsberry&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Sep 2020 15:19:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9744512#M10817</guid>
      <dc:creator>ritste20</dc:creator>
      <dc:date>2020-09-13T15:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Script to autofavorite named model parameters</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9890282#M10818</link>
      <description>&lt;P&gt;I was just made aware of an issue with this that caused the file to become "edited" constantly.&amp;nbsp; &amp;nbsp;The issue is that regardless of whether the named parameter was already a favorite I "set" the flag anyway.&amp;nbsp; I think that is essentially telling Fusion that something "changed" in the file.&amp;nbsp; I just made one tiny change to the code and I think it should solve the problem.&amp;nbsp; &amp;nbsp;Basically moving the last line of the check favorites function into the if statement.&amp;nbsp; &amp;nbsp;You may want to update your code if you are using this.&amp;nbsp; Here is the updated version:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#Author-Patrick Rainsberry
#Description-Continuously monitors Model Parameters for changes to name and then adds parameter to favorites.  

import adsk.cam
import adsk.core
import adsk.fusion
import traceback

# Global variable used to maintain a reference to all event handlers.
handlers = []


def check_favorites():
    # This is not necessary but makes code complete work better
    app: adsk.core.Application
    document: adsk.fusion.FusionDocument
    parameter: adsk.fusion.Parameter

    # Get various application objects
    app = adsk.core.Application.get()
    document = app.activeDocument
    design = document.design
    all_params = design.allParameters

    # Lets count the number of favorites added
    count = 0

    # Iterate over all parameters in the design
    # Note: Intentionally verbose to make it easier to follow.
    for parameter in all_params:
        is_named_parameter = True

        # Check if first character is not a "d"
        if parameter.name[0] == 'd':
            # Check if the rest of the name is not a positive integer
            if parameter.name[1:].isdigit():
                is_named_parameter = False

        # Check if it has a user defined name
        if is_named_parameter:

            # Only increment count if it wasn't already a favorite
            if not parameter.isFavorite:
                count += 1

                # Set the parameter as a favorite
                parameter.isFavorite = True


# Event handler for the commandTerminated event.
class MyCommandTerminatedHandler(adsk.core.ApplicationCommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args):
        event_args = adsk.core.ApplicationCommandEventArgs.cast(args)

        # Will check favorites after every command completes for anything except the select command.
        if event_args.commandId != "SelectCommand":
            check_favorites()


def run(context):
    global handlers
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        onCommandTerminated = MyCommandTerminatedHandler()
        ui.commandTerminated.add(onCommandTerminated)
        handlers.append(onCommandTerminated)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def stop(context):
    global handlers
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        for handler in handlers:
            ui.commandTerminated.remove(handler)
        ui.messageBox('Stopped Favorites addin')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 21:31:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/script-to-autofavorite-named-model-parameters/m-p/9890282#M10818</guid>
      <dc:creator>prainsberry</dc:creator>
      <dc:date>2020-11-23T21:31:14Z</dc:date>
    </item>
  </channel>
</rss>

