Edit grid spacing in Fusion360 through API

Edit grid spacing in Fusion360 through API

Anonymous
Not applicable
693 Views
3 Replies
Message 1 of 4

Edit grid spacing in Fusion360 through API

Anonymous
Not applicable
Is there any way to get access to grid settings in order to fix the grid and change grid spacing, like in grid and snaps programmatically using the API?
0 Likes
Accepted solutions (1)
694 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor
Accepted solution

Hi @Anonymous .

 

I created a sample that changes the grid.

#Fusion360API Python script
import adsk.core, adsk.fusio, traceback

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

        # grid setting
        setGrid(2,10)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


# majerGridSpacing - unit Cm
def setGrid(
    majerGridSpacing :float,
    minorSubdivisions :float
    ):

    cmds = [
        u'NuCommands.DefineGridCmd',
        u'Commands.SetDouble GridSpacingInput {}'.format(majerGridSpacing),
        u'Commands.SetDouble GridsubdivisionsInput {}'.format(minorSubdivisions),
        u'NuCommands.CommitCmd'
    ]

    app = adsk.core.Application.get()
    [app.executeTextCommand(cmd) for cmd in cmds]

 

For more information on how to use TextCommands, see here.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands2/m-p/9937161 

Message 3 of 4

Anonymous
Not applicable

@kandennti thank you for your response, do you know about the TextCommand for fit with the shortcut F6? I tried '

Camera.ZoomOut' but it isn't that accurate. Do you know the command for Fit in the zoom window?
0 Likes