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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Manipulating the camera view

Message 1 of 3
1015 Views, 2 Replies

Manipulating the camera view

If I understand this correctly you can manipulate which portion of you design shows in the window by manipulating the Camera object. I was able to figure out how to get it to do an API "fit view" operation, which is somewhat, but not quite, what a Find In Window browser operation does.


Fit View causes the entire design (well, at least the parts of the design that are currently visible, via their Light Bulb icons) to be maximized in the window, In my case the design is taller than it is wide, so the top of the design just touches the top of the display window and the bottom of the design just touches the bottom o f the display window.

Prior to doing the Fit View my window looks like this:



AFTER the Fit View operation it looks like this:

Camera 1.jpg


BUT, if instead of doing the Fit View (via my C++ script) I just click on the entire project in the browser and select to Find In Window, I get this.


Camera 2.jpg


Which does NOT maximize the image but rather leaves some room at the top and bottom. It's kind of like the "camera" has been moved back from the object.

I want to be able to do something like that but via my C++ script. I tried writing some code that uses the Camera eye object. I made sure that the Z axis of the object is pointing directly perpendicular to the screen and modified the z component of the eye object, as in this code:

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

	return TRUE;

bool ZoomOutToShowInWindowAllVisibleObjects()
	// This is different than CenterAndShowInWindowAllVisibleObjects in that
	// we want to move the camera back a bit so that everything shown doesn't
	// simply extend to the outer edges of the windo. In particular we
	// want to assure that any movement or, for example, landing gear deployments
	// are fully visible.
	Ptr<Viewport> viewPort = theFusion360Application->activeViewport();
	if (!viewPort)
		return false;
	Ptr<Camera> TheCamera = viewPort->camera();
	if (!TheCamera)
		return false;

	// Get the existing CameraPosition
	Ptr<Point3D> CameraPosition = TheCamera->eye();
	Show("EXISTING Camera Position X,Y,Z = " + std::to_string(CameraPosition->x()) + "," + std::to_string(CameraPosition->y()) + "," + std::to_string(CameraPosition->z()));

	// Modify the CameraPosition, effectively pulling it back a bit, perpendicular to the center of the window.
	// It's the Z axis (for the overall project) that is perpendicular to the surface of the screen, i.e. towards (+) you and away from you (-).
	double CameraPositionZ = CameraPosition->z();
	double AmountToPullBackInCentimeters = 200;
	CameraPosition->z(CameraPositionZ + AmountToPullBackInCentimeters);

	// Set the value of the property, where value_var is a Point3D.


	Show("NEW Camera Position X,Y,Z = " + std::to_string(CameraPosition->x()) + "," + std::to_string(CameraPosition->y()) + "," + std::to_string(CameraPosition->z()));

	return TRUE;

The first method basically does the FitView operation. And that does indeed get the object fitted into view.

The second method is intended to basically "pull back" from the view, which SHOULD (I think) result in the object looking a bit smaller in the window and be more like what you get when you use the Find In Window operation from the Browser. But it doesn't. Instead it seems to re-orient the displayed object.

I've tried lots of different approaches but can't seem to get it to do what I want. Basically, no matter how the object is oriented within the window, I want to be able to zoom-out much like the Browser's Find In Window operation works.

Camera 3.jpg

 Ideally, I'd also like to be able to do, through my C++ script, the operations you get when you click on the various faces of the little cube in the upper right corner.

Camera 4.jpg


Is that possible?

Is there any documentation/examples on how to effectively use the Camera object?

Message 2 of 3
in reply to: RogerInHawaii

Hi @RogerInHawaii .


Since I do not understand C ++, it will be explained in Python. I'm sorry.

Here is @BrianEkins  Python 'FindInWindow' sample. 

However, 'FindInWindow' will not be performed if the selection is canceled at the end.
Probably because commandDefinition.execute () is processed after script execution.
I experienced a similar phenomenon here. 

Therefore, I think that it cannot be used during processing.


The Camera object has a viewExtents property, so why not increase this size? 

After a little trial, the value was about 1.4 ~ 1.5 times that of the isFitView method.
They don't exactly match, but I don't think there is a big difference.

#Fusion360API Python script

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
        app  :adsk.core.Application = adsk.core.Application.get()
        ui   :adsk.core.UserInterface = app.userInterface

        vp = app.activeViewport
        cam :adsk.core.Camera =
        cam.viewExtents = cam.viewExtents * 1.45 = cam
        if ui:
Message 3 of 3
in reply to: RogerInHawaii

Here's an overview of cameras in a blog post I wrote a while ago.  It was written for Inventor but the concepts apply the same to Fusion 360 and the post just discusses the concepts.  I'm sure your problem with zooming out is because you were using an orthographic camera, which is discussed in the post.


Here's a video that was an early experiment where I used a program to modify parameters and move the camera.


The intro to this video was done entirely with Fusion 360 and some customization.





Brian Ekins
Inventor and Fusion 360 API Expert

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