Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Script to Set Current View to Home (Fit to View)?

Anonymous

Script to Set Current View to Home (Fit to View)?

Anonymous
Not applicable

I haven't found any way, with the api, to "Set Current View to Home (Fit to View)"

 

Does anyone know if this is currently possible?

0 Likes
Reply
Accepted solutions (1)
2,123 Views
11 Replies
Replies (11)

ThilaknathRao
Alumni
Alumni

Nick,

 

I expected it to be present on ActiveViewport but didn't find it there or anywhere else. So I am guessing this isn't supported yet.

 

Thanks,

-Thilak

0 Likes

promm
Alumni
Alumni

Screen Shot 2015-03-02 at 10.38.18 AM.png

Nick,

 

Right click on the house to the left of the view cube.  Next select set current view as home.  You can pick "fix distance" or "fit to view".  If this answers you question please select accept as solution.

 

Cheers,

 

Mike Prom

0 Likes

Anonymous
Not applicable

Thanks, but (as the title implies 🙂 I am looking for a scripted API call that would accomplish the same thing.

 

It is part of a larger script, so it will actually be saving time and mouse clicks!

0 Likes

david_reaume
Autodesk
Autodesk

Nick,

 

Try the 'isFitView' (bool) property on the Camera class.

 

/// <summary>
/// If this property is true, when this camera is applied to a viewport it
/// will modify the camera such that the entire model is displayed in the viewport.
/// When getting a camera from a viewport this property is always initialized to false.
/// </summary>

 

DaVeR

DaVeR
0 Likes

ekinsb
Alumni
Alumni
Accepted solution

The assumption is right.  This is not currently exposed through the API.  It is possible to use the API to change the current view but it's not currently possible to set it to the home view or find out the camera settings for the home view.  This is something we need to support in the future.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes

Anonymous
Not applicable

Thanks!

0 Likes

wh6Q9NU
Advocate
Advocate

I just wonder. Any update on this?
Can we already set the view home position via a API call?

0 Likes

RogerInHawaii
Collaborator
Collaborator

Here's some C++ code for, sort of, accomplishing the fit to view. It's not exactly the same as the Fit To View operation that's available in that little Box in the upper right corner of the window, but it's pretty close.

bool CenterAndShowInWindowAllVisibleObjects()
{
	Ptr<Viewport> viewPort = theFusion360Application->activeViewport();
	if (!viewPort)
		return false;
	Ptr<Camera> TheCamera = viewPort->camera();
	if (!TheCamera)
		return false;
	
	TheCamera->isFitView(true);
	viewPort->camera(TheCamera);

	return TRUE;
}
2 Likes

wh6Q9NU
Advocate
Advocate

Thank you!

And for ease of use, a Python version of this function:

import adsk.core
import math

def CenterAndShowInWindowAllVisibleObjects(app :adsk.core.Application) -> bool:
    viewPort :adsk.core.Viewport = app.activeViewport

    if (not viewPort):
        return False

    camera :adsk.core.Camera = viewPort.camera

    if (not camera):
        return False
    
    camera.isFitView =  True
    viewPort.camera = camera

    return True
0 Likes

dan-anders
Explorer
Explorer

Don't know if there is a method for this nowadays, but this worked in my case:

 

 

 

 

app.executeTextCommand(u'NamedView.RestoreCamera HOME')

 

 

 
0 Likes

dan-anders
Explorer
Explorer

...and two minutes later I stumbled across this 😀

 

app.activeViewport.goHome()

 

 

 

2 Likes