Restore the view orientation type

Restore the view orientation type

Anonymous
Not applicable
2,439 Views
9 Replies
Message 1 of 10

Restore the view orientation type

Anonymous
Not applicable

Hello,

 

Before I change the view settings in my code I like to save the current settings. After the code has finished these saved settings needs to be restored.

 

...	
Dim oView As Inventor.View = ThisApplication.ActiveView
Dim oCam As Inventor.Camera = ThisApplication.ActiveView.Camera

'save current settings
Dim DisplayMode As DisplayModeEnum = oView.DisplayMode
Dim AmbientShadows As Boolean = oView.ShowAmbientShadows
Dim ObjectShadows As Boolean = oView.ShowObjectShadows
Dim GroundShadows As Boolean = oView.ShowGroundShadows
Dim GroundPlane As Boolean = oView.ShowGroundPlane
Dim Raytracing As Boolean = oView.RayTracing
Dim _ViewOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kCurrentViewOrientation
		
<do some stuff here>

'restore settings
oCam.ViewOrientationType = _ViewOrientation '<---------- this line does not work
'oCam.ViewOrientationType = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation '<----------- this line works fine
oView.DisplayMode = DisplayMode
oView.ShowAmbientShadows = AmbientShadows
oView.ShowObjectShadows = ObjectShadows
oView.ShowGroundShadows = GroundShadows
oView.ShowGroundPlane = GroundPlane
oView.RayTracing = Raytracing
ocam.Apply 
...

I have an issue with the  _ViewOrientation  variable. In the restore section I placed two lines. The first one doesn't work, while the second runs fine. Why?

What am I overlooking here?

 

Best regards,

 

0 Likes
Accepted solutions (1)
2,440 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

The error message is:

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Camera.set_ViewOrientationType(ViewOrientationTypeEnum )
at ThisRule.CreateImage(AssemblyDocument Assy, String FolderName, String Filename, Boolean CreateImage, Boolean CreateRayTracing)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

So in my ilogic rule called "CreateImage"  I execute  "Camera.set_viewOrientationType(ViewOrientationTypeEnum) by my code "oCam.ViewOrientationType = _ViewOrientation".

Is there something wrong with the handling of enum parameter?

0 Likes
Message 3 of 10

omartin
Advocate
Advocate

Probably the kCurrentViewOrientation enum does not relate to, or holds the enough information to set the camera, when you lookup up the vieworientation enums it holds various types not all related.

I think you need to store / restore the cameras: eye, target, upvector, and extents

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 4 of 10

Anonymous
Not applicable

No, I don't think we are missing info here. When the following line is used:

oCam.ViewOrientationType = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation

it works fine. But when  a variable is used it crashes.

 

0 Likes
Message 5 of 10

JelteDeJong
Mentor
Mentor

I think that your assumption that the variable is the problem isn't correct. if i fill the variable with "ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation" then the code works. But if i fill it "ViewOrientationTypeEnum.kCurrentViewOrientation" then i also get a error.

Dim oView As Inventor.View = ThisApplication.ActiveView
Dim oCam As Inventor.Camera = ThisApplication.ActiveView.Camera

Dim _ViewOrientation As ViewOrientationTypeEnum

_ViewOrientation = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
oCam.ViewOrientationType = _ViewOrientation '<-- variable works and variable content works
msgbox("So far the code works.")

_ViewOrientation = ViewOrientationTypeEnum.kCurrentViewOrientation
oCam.ViewOrientationType = _ViewOrientation '<-- variable works BUT variable content does not work
msgbox("you will not see this msgbox because an exception")

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 6 of 10

JhoelForshav
Mentor
Mentor

I think it'll work if you use the variable like this:

 

oCam.ViewOrientationType.Equals(_ViewOrientation)

 

Message 7 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Below iLogic code is working with _ViewOrientation.

 

Dim oView As Inventor.View = ThisApplication.ActiveView
Dim oCam As Inventor.Camera = ThisApplication.ActiveView.Camera

' 
Dim _ViewOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kBottomViewOrientation 
'restore settings
oCam.ViewOrientationType = _ViewOrientation  
 
oCam.Apply

In your code, after doing some stuff. ActiveView is already in current view (kCurrentViewOrientation). It is not possible to assign again kCurrentViewOrientation. It means that other than kCurrentViewOrientation. _ViewOrientation can accept other view orientation type.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 10

JhoelForshav
Mentor
Mentor

I was wrong in a reply here but didn't find a way to delete it. Only edit it. So ignore this 🙂

0 Likes
Message 9 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

I've done some testing with this code:

 

Dim oView As Inventor.View = ThisApplication.ActiveView
Dim oCam As Inventor.Camera = ThisApplication.ActiveView.Camera

'save current settings
Dim DisplayMode As Integer = oView.DisplayMode.GetHashCode
Dim AmbientShadows As Boolean = oView.ShowAmbientShadows
Dim ObjectShadows As Boolean = oView.ShowObjectShadows
Dim GroundShadows As Boolean = oView.ShowGroundShadows
Dim GroundPlane As Boolean = oView.ShowGroundPlane
Dim Raytracing As Boolean = oView.RayTracing

Dim _ViewOrientation As ViewOrientationTypeEnum = oCam.ViewOrientationType
'-------Message current view type-------
MsgBox(_ViewOrientation & vbCrLf & _ViewOrientation.ToString)

'-------------
'<Do stuff>
'-------------


If _ViewOrientation.Equals(ViewOrientationTypeEnum.kArbitraryViewOrientation) = False

'Set orientation type back using stored hash code
oCam.ViewOrientationType  = _ViewOrientation
'-------------------------------------------------

End If

oCam.Apply 

 As Long as the first view type is one that we actually have a specific vieworientationtype for it works. For example Top, Bottom, Left, Right. If its Arbitrary the code you can't use it. It is for example arbitrary if the text on the viewcube isn't correctly oriented.

 

Hope this helps at least a little in figuring out the problem

Message 10 of 10

Anonymous
Not applicable

Thank you all for the hints, tips and pushing me to the right direction.

 

To complete this thread hereby my runing code:

Sub CreateImage(Assy As AssemblyDocument, FolderName As String, Filename As String, CreateImage As Boolean, CreateRayTracing As Boolean)
	Dim oView As Inventor.View = ThisApplication.ActiveView
	Dim oCam As Inventor.Camera = ThisApplication.ActiveView.Camera

	'save current settings
	Dim _DisplayMode As DisplayModeEnum = oView.DisplayMode
	Dim _AmbientShadows As Boolean = oView.ShowAmbientShadows
	Dim _ObjectShadows As Boolean = oView.ShowObjectShadows
	Dim _GroundShadows As Boolean = oView.ShowGroundShadows
	Dim _GroundPlane As Boolean = oView.ShowGroundPlane
	Dim _Raytracing As Boolean = oView.RayTracing
	Dim _ViewOrientation As ViewOrientationTypeEnum = oCam.ViewOrientationType 
	Dim _target As Point = oCam.Target
 	Dim _UpVector As UnitVector = oCam.UpVector 
	Dim _Eye As Point = oCam.Eye
	Dim _Angle As Object = oCam.PerspectiveAngle
	Dim _Height As Double
	Dim _Width As Double
	oCam.GetExtents(_Height,_Width)
	
	'change the camera and apply the changes. 
	oCam.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopRightViewOrientation
	oCam.Fit()
	oCam.Animating = False
	oCam.ApplyWithoutTransition()

	'change settings
	oView.DisplayMode = DisplayModeEnum.kRealisticRendering
	oView.ShowAmbientShadows = False
	oView.ShowObjectShadows = True
	oView.ShowGroundShadows = True
	oView.ShowGroundPlane = False

	If CreateImage Then
		'Save the result, defining the background color of the image. 
		oCam.SaveAsBitmap(
			FolderName & Filename & ".jpg",
			1600,
			1200,
			ThisApplication.TransientObjects.CreateColor(255, 255, 255)
		)
	End If

	If CreateRayTracing Then
		oView.RayTracing = True
		oView.RayTracingQuality = RayTracingQualityEnum.kDraftRayTracingQuality
		Do
			ThisApplication.UserInterfaceManager.DoEvents
		Loop Until oView.RayTracingProgress = 1
		oView.SaveAsBitmapWithRayTracing(FolderName & Filename & "_RT.jpg")
	End If

'restore the settings If _ViewOrientation.Equals(ViewOrientationTypeEnum.kArbitraryViewOrientation) = False oCam.ViewOrientationType = _ViewOrientation Else oCam.Eye = _Eye oCam.PerspectiveAngle = _Angle oCam.UpVector = _UpVector oCam.Target = _target oCam.SetExtents(_Height,_Width) End If If _DisplayMode.Equals(oView.DisplayMode) = False oView.DisplayMode = _DisplayMode End If oView.ShowAmbientShadows = _AmbientShadows oView.ShowObjectShadows = _ObjectShadows oView.ShowGroundShadows = _GroundShadows oView.ShowGroundPlane = _GroundPlane If oView.DisplayMode.Equals(DisplayModeEnum.kRealisticRendering) Then oView.RayTracing = _Raytracing End If oCam.Apply End Sub