Anti-Aliasing effect

Anti-Aliasing effect

JeromeBriot
Mentor Mentor
5,619 Views
4 Replies
Message 1 of 5

Anti-Aliasing effect

JeromeBriot
Mentor
Mentor

Hello,

 

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

 

fusion-360-anti-aliasing.png

 

Thanks

0 Likes
Accepted solutions (2)
5,620 Views
4 Replies
Replies (4)
Message 2 of 5

goyals
Autodesk
Autodesk
Accepted solution

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
Mentor
Mentor

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
Mentor
Mentor
Accepted solution

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
Mentor
Mentor

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', 'アンチエイリアシング', '抗锯齿'}:
0 Likes