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: 

Anti-Aliasing effect

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
JeromeBriot
3786 Views, 4 Replies

Anti-Aliasing effect

Hello,

 

Is there a way to toggle the state of the Anti-Aliasing effect with the API ?

 

fusion-360-anti-aliasing.png

 

Thanks

4 REPLIES 4
Message 2 of 5
goyals
in reply to: JeromeBriot

You can try below script to do that

 

context = adsk.core.NamedValues.create()
cmdIDName = adsk.core.ValueInput.createByString(“ViewMSAAOnCommand”)
context.add(“CmdId”,cmdIDName)
cmdDef = ui.commandDefinitions.itemById(“ViewDisplayCommand”) cmdDef.execute(context)

 

Only problem with this code is it does not update Fusion UI means check box is not updated in UI but it certainly take effect on display. Thanks



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 5
JeromeBriot
in reply to: goyals

Great! Thank you @goyals 

 

To activate the anti-aliasing:

context = adsk.core.NamedValues.create()
cmdIDName = adsk.core.ValueInput.createByString('ViewMSAAOnCommand')
context.add('CmdId', cmdIDName)
cmdDef = ui.commandDefinitions.itemById('ViewDisplayCommand')
cmdDef.execute(context)

To desactivate the anti-aliasing:

context = adsk.core.NamedValues.create()
cmdIDName = adsk.core.ValueInput.createByString('ViewMSAAOffCommand')
context.add('CmdId', cmdIDName)
cmdDef = ui.commandDefinitions.itemById('ViewDisplayCommand')
cmdDef.execute(context)

Is there a possibility to get the current state of the anti-aliasing effect. So I can restore it to its original state.

 

Message 4 of 5
BrianEkins
in reply to: JeromeBriot

Here's a different approach that lets you get the current state of the Anti-Alias setting and set it to whatever value you want.  Whatever change you make is also reflected in the UI.  It uses the fact that ALL commands are exposed through the API and this command happens to be represented in the UI as a list control.  This uses the API functionality of the list control to get a specific item in the list, check to see if it is checked or not and change its state.

 

def run(Context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        # Get the "Effects" command.
        effectsCmdDef = ui.commandDefinitions.itemById('ViewEffectCommand')
        
        # Get the control definition associated with the command.
        effectsCntrlDef = adsk.core.ListControlDefinition.cast(effectsCmdDef.controlDefinition)
        
        # Iterate through the items in the list to find the one for "Anti-Aliasing".
        # !!! This will only work in an English version of Fusion.
        listItem = adsk.core.ListItem.cast(None)
        antiAlias = adsk.core.ListItem.cast(None)
        for listItem in effectsCntrlDef.listItems:
            if listItem.name == 'Anti-Aliasing':
                antiAlias = listItem
                break

        if antiAlias:
            if antiAlias.isSelected:
                ui.messageBox('Anti-Aliasing is on.  Turning off.')
                antiAlias.isSelected = False
            else:
                ui.messageBox('Anti-Aliasing is off.  Turning on.')
                antiAlias.isSelected = True
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 5
JeromeBriot
in reply to: BrianEkins

Thank you @BrianEkins. That's exactly what I was looking for.

 

Here is the complete test for all languages supported by Fusion 360:

 

if listItem.name in {'Anti-Aliasing', 'アンチエイリアシング', '抗锯齿'}:

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report