Changing the CameraType

Changing the CameraType

kandennti
Mentor Mentor
677 Views
2 Replies
Message 1 of 3

Changing the CameraType

kandennti
Mentor
Mentor

Hey there everyone.
I am thinking of changing the Camera.cameraType Property in an add-in.

2.png

 

I have created the following script for my next test.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

_CAMERA_TYPES = [
    'OrthographicCameraType',
    'PerspectiveCameraType',
    'PerspectiveWithOrthoFacesCameraType'
]

_CAMERA_TYPES_LIST = [
    adsk.core.CameraTypes.OrthographicCameraType,
    adsk.core.CameraTypes.PerspectiveCameraType,
    adsk.core.CameraTypes.PerspectiveWithOrthoFacesCameraType,
]

def run(context):
    ui: adsk.core.UserInterface = None
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        vp: adsk.core.Viewport = app.activeViewport
        cam: adsk.core.Camera = vp.camera
        backupCameraType = cam.cameraType

        backupOriginFolderLight = root.isOriginFolderLightBulbOn
        root.isOriginFolderLightBulbOn = True

        for ct in _CAMERA_TYPES_LIST:
            cam.cameraType = ct
            cameraUpdate(vp, cam)

            cam = vp.camera
            ui.messageBox(_CAMERA_TYPES[cam.cameraType])

        cam.cameraType = backupCameraType
        cameraUpdate(vp, cam)

        root.isOriginFolderLightBulbOn = backupOriginFolderLight

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


def cameraUpdate(
        vp: adsk.core.Viewport,
        cam: adsk.core.Camera):

    vp.camera = cam
    vp.refresh()
    vp.fit()

 

Here is the result.

1.png

 

"adsk.core.CameraTypes.PerspectiveWithOrthoFacesCameraType" is very different from the one I set in the GUI.
Is this the correct display?
I am using Fusion360 Ver2.0.10940.

Accepted solutions (1)
678 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

I can reproduce the problem and it does appear to be a bug and has been logged.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

kandennti
Mentor
Mentor

Thanks @BrianEkins .

 

I will not use "adsk.core.CameraTypes.PerspectiveWithOrthoFacesCameraType" in the add-in.

 

0 Likes