viewOrientation doesn't work consistently + How to Set current view as Home

viewOrientation doesn't work consistently + How to Set current view as Home

jschmidt1340
Participant Participant
920 Views
4 Replies
Message 1 of 5

viewOrientation doesn't work consistently + How to Set current view as Home

jschmidt1340
Participant
Participant

Hi! I'm new to F360 scripting and trying to work my way through the object model.

 

I'm trying to put together a script to do the following:

 

  1. Hides all sketch points on all sketched
  2. Sets the camera to the TopViewOrientation.
  3. Sets the Current view as Home ->Fit to View

Here's what I have so far:

 

 

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        vp = app.activeViewport
        #ui.messageBox('Start')

        # Hide sketch points in all sketches
        for component in design.allComponents:
            for sketch in component.sketches:
                sketch.arePointsShown = False

        #Re-set Home
        cam = vp.camera
        cam.viewOrientation = adsk.core.ViewOrientations.TopViewOrientation
        cam.isFitView = True
        vp.camera = cam

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

 

 

There are two problems that I'm running into:

 

  1. Sometimes, but not always, the TopViewOrientation is rotated by 90 degrees.
  2. I can't figure out how to set the current view as the new Home -> Fit to View

So, what I end up doing is having to manually rotate the view using the rotation arrows. And, even if the TopViewOrientation is correctly oriented, I still have to manually set the current view as home. I don't get why I have to sometimes rotate the view 90 degrees. And I cannot find a way through my review of the object model to be able to set the current view to Home.

 

I'm attaching a sample file here. When I run the script on this file, the TopViewOrientation is rotated 90 degrees clockwise. I have to manually rotate the view 90 degrees counterclockwise.

 

Any help is appreciated! Thank you!

 

Jonathan

0 Likes
Accepted solutions (1)
921 Views
4 Replies
Replies (4)
Message 2 of 5

jschmidt1340
Participant
Participant

Posted this by mistake.

0 Likes
Message 3 of 5

BrianEkins
Mentor
Mentor
Accepted solution

The API doesn't use the settings defined by the view cube.  It probably should but it doesn't.  The API uses the view orientation setting of the Preferences setting that defines if the Y or Z axis is pointing up.  Currently, there's no access to the view cube information.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 4 of 5

jschmidt1340
Participant
Participant

Awww... bummer. Well, that explains my inability to make it work at least. 🙂 Thanks for the reply!

0 Likes
Message 5 of 5

jnaudin57
Explorer
Explorer
Hi Brian Ekins,

I know this thread is 2 years old, so I am wondering: is this still the case?
I'm deep in a project where I assumed that I would be able to control the view cube orientation through API. Does that mean I won't be able to?
0 Likes