Hide/show Layout Grid from API

Hide/show Layout Grid from API

Anonymous
Not applicable
537 Views
2 Replies
Message 1 of 3

Hide/show Layout Grid from API

Anonymous
Not applicable

Hi all,

 

I'm trying to save an image of my model from API. To save the image is no problem with the viewport functionality. But I also want to hide the Layout grid when I save the image.

I have found the GridPreference object, but is does not seem to contain a "visibility" property, the only property I can find is the isLayoutLockEnabled.

 

Is it not possible to hide the layout grid from the API?

Anyone that knows?

538 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

The API doesn't directly support access to the grid settings.  However, the API does provide access to the UI and through the UI you can find out if the checkbox in the grid pop-up is checked or not and change the checked state.  I created a couple of functions to wrap this and a test function so you can find out if the grid is on or not and then set it to be on or off.  Here's the code.

 

def testGridDisplay():
    ui = None
    try:
        if isGridDisplayOn():
            setGridDisplay(False)
        else:
            setGridDisplay(True)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def isGridDisplayOn():
    app = adsk.core.Application.get()
    ui  = app.userInterface

    cmdDef = ui.commandDefinitions.itemById('ViewLayoutGridCommand')
    listCntrlDef = adsk.core.ListControlDefinition.cast(cmdDef.controlDefinition)
    layoutGridItem = listCntrlDef.listItems.item(0)
    
    if layoutGridItem.isSelected:
        return True
    else:
        return False
    

def setGridDisplay(turnOn):
    app = adsk.core.Application.get()
    ui  = app.userInterface

    cmdDef = ui.commandDefinitions.itemById('ViewLayoutGridCommand')
    listCntrlDef = adsk.core.ListControlDefinition.cast(cmdDef.controlDefinition)
    layoutGridItem = listCntrlDef.listItems.item(0)
    
    if turnOn:
        layoutGridItem.isSelected = True
    else:
        layoutGridItem.isSelected = False   
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

Anonymous
Not applicable

Great!

 

Thanks for you help!

Will try this out.

 

Br

Jonas W

0 Likes