Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
FireBallFab
1403 Views, 11 Replies

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

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?

11 REPLIES 11
Message 2 of 12
ThilaknathRao
in reply to: FireBallFab

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

Message 3 of 12
promm
in reply to: FireBallFab

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

Message 4 of 12
FireBallFab
in reply to: promm

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!

Message 5 of 12
david_reaume
in reply to: FireBallFab

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
Message 6 of 12
ekinsb
in reply to: FireBallFab

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
Message 7 of 12
FireBallFab
in reply to: ekinsb

Thanks!

Message 8 of 12
wh6Q9NU
in reply to: ekinsb

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

Message 9 of 12
RogerInHawaii
in reply to: FireBallFab

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;
}
Message 10 of 12
wh6Q9NU
in reply to: RogerInHawaii

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
Message 11 of 12
dan-anders
in reply to: FireBallFab

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

 

 

 

 

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

 

 

 
Message 12 of 12
dan-anders
in reply to: FireBallFab

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

 

app.activeViewport.goHome()

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report