Get current camera settings to return to

gert-leonvanlier
Collaborator
Collaborator

Get current camera settings to return to

gert-leonvanlier
Collaborator
Collaborator

I am looking for a way to get the current view that a user is looking at (how he/she turned the model so to say). I want to use this, so that when the user saves the file, the camera moves to the ISO view, the files is then saved and a thumbnail is created, and then moves back to the view the user was initially looking at. In that way all our thumbnails will have the same view point. Going to the ISO view is working, but I can not find a way to save the user's view and use that to go back to after the save.

 

I assume I have to do something with the camera.

0 Likes
Reply
Accepted solutions (1)
558 Views
4 Replies
Replies (4)

theo.bot
Collaborator
Collaborator

In the iproperties of your files you can set the thumbnail creation to "Active Component Iso view on Save". This saves the thumbnail in the same Iso position. Not sure if this will help you, but it could save coding time 🙂

 

theobot_0-1646224326220.png

 

gert-leonvanlier
Collaborator
Collaborator
Accepted solution

That is indeed something that would save time. Thank you. Somehow I implemented switching to the ISO view on save at the start of the addin I made. Perhaps because I wanted to be sure that the ISO view is used at save, but maybe I can acces this setting instead of manipulating the camera.

 

However, I figured out how to get the current camera position and later go back to that position, after a save. So for someone else who could use (a part) of my code, here it is.

 

To get the current view:

public void CurrentView(Data.ViewData viewData)
{
	Inventor.View activeView = Globals.invApp.ActiveView;
	Camera camera = activeView.Camera;

	Point eyePoint = camera.Eye;
	Point targetPoint = camera.Target;
	UnitVector upVector = camera.UpVector;
	Double perspectiveAngle = camera.PerspectiveAngle;

	viewData.EyePoint = eyePoint;
	viewData.TargetPoint = targetPoint;
	viewData.UpVector = upVector;
	viewData.PerspectiveAngle = perspectiveAngle;
}

 

To go back to the view the user was before the save:

public void ReturnView(Data.ViewData viewData)
{
	Inventor.View activeView = Globals.invApp.ActiveView;
	Camera camera = activeView.Camera;

	camera.Eye = viewData.EyePoint;
	camera.Target = viewData.TargetPoint;
	camera.UpVector = viewData.UpVector;
	camera.PerspectiveAngle = viewData.PerspectiveAngle;
	camera.ApplyWithoutTransition();
}

 

A separate class stores the values:

public class ViewData
{
	public Point EyePoint { get; set; }
	public Point TargetPoint { get; set; }
	public UnitVector UpVector { get; set; }
	public Double PerspectiveAngle { get; set; }
}

 

theo.bot
Collaborator
Collaborator

You can access this setting for each type of document as the property "SetThumbnailSaveOption"

 

Dim oDoc As PartDocument
oDoc = ThisDoc.Document 

oDoc.SetThumbnailSaveOption(kActiveComponentIsoViewOnSave)

 

WCrihfield
Mentor
Mentor

Just a quickie additional note on the subject...

Here is a very simple iLogic code to switch that Save option by code, just in case that might come in handy at some point.

 

oDoc = ThisDoc.Document
oDoc.SetThumbnailSaveOption(ThumbnailSaveOptionEnum.kActiveComponentIsoViewOnSave)

 

Edit: Just noticed we both pasted the same thing at the same time.  "Great minds think alike." 😉

Wesley Crihfield

EESignature

(Not an Autodesk Employee)