View orientations.

View orientations.

dames123
Advocate Advocate
155 Views
2 Replies
Message 1 of 3

View orientations.

dames123
Advocate
Advocate

Are these view orientations accessible through the API? If so what's the correct command?

 

dames123_0-1745947729980.png

Thanks.

0 Likes
156 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

As far as I'm aware, there isn't API functionality for this. However, there is a simple workaround that, in this case, is probably just as good. Each of these orientations is a command, and since there's no dialog or input required for the command, you can execute it through the API to get the same result. Here's some example code demonstrating it.

 

ui.commandDefinitions.itemById('IronViewOrientationFront').execute()

 

Here are the names of the different commands:

  • IronViewOrientationTop
  • IronViewOrientationBottom
  • IronViewOrientationFront
  • IronViewOrientationBack
  • IronViewOrientationLeft
  • IronViewOrientationRight
  • IronViewOrientationIso
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 3

dames123
Advocate
Advocate

Hi Brian,

 

I couldn't get that to work. What I'm trying to do is. Activate setup, orient the model (according to the setup X,Y), take an image capture. Go to next setup, etc. The following code works but the "TopViewOrientation looks at the model from the top but doesn't necessarily orient the setup X,Y, correctly. That's why I wanted to use "ToolTop" because that uses the setup XY orientation. I guess theres no API functionality for that.

 

import adsk.core
import adsk.fusion
import adsk.cam
import traceback

def capture_image(app, file_path):
    try:
        # Get the active design
        design = app.activeProduct
        if not design:
            app.userInterface.messageBox('No active design')
            return

        # Get the active viewport
        viewport = app.activeViewport

        # Set the camera view to iso top-left view orientation
        camera = viewport.camera
        camera.viewOrientation = adsk.core.ViewOrientations.TopViewOrientation
        camera.isFitView = True  # Ensure the view fits the screen

        # Refresh the viewport to apply the new orientation
        viewport.camera = camera
        viewport.refresh()

        # Capture the image
        image = viewport.saveAsImageFile(file_path, 640, 480)
        if image:
            app.userInterface.messageBox(f'Image captured and saved as {file_path}')
        else:
            app.userInterface.messageBox('Failed to capture image')
    except:
        app.userInterface.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def capture_images_for_setups(app):
    try:
        # Get the active design
        design = app.activeProduct
        if not design:
            app.userInterface.messageBox('No active design')
            return

        # Get the CAM product
        cam = adsk.cam.CAM.cast(design)
        if not cam:
            app.userInterface.messageBox('No CAM product found')
            return

        # Get the setups
        setups = cam.setups
        if setups.count == 0:
            app.userInterface.messageBox('No setups found')
            return

        # Iterate through each setup
        for setup in setups:
            # Activate the setup
            setup.activate()

            # Prompt user for file path
            file_dialog = app.userInterface.createFileDialog()
            file_dialog.isMultiSelectEnabled = False
            file_dialog.title = f'Save Captured Image for Setup {setup.name}'
            file_dialog.filter = 'PNG files (*.png)'
            file_dialog.initialFilename = f'{setup.name}.png'
            dialog_result = file_dialog.showSave()

            if dialog_result == adsk.core.DialogResults.DialogOK:
                file_path = file_dialog.filename
                capture_image(app, file_path)
            else:
                app.userInterface.messageBox(f'Image capture canceled for setup {setup.name}')
    except:
        app.userInterface.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        capture_images_for_setups(app)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    pass
0 Likes