Camera / View Rep - Crash (Do you want to crash Inventor?)

Camera / View Rep - Crash (Do you want to crash Inventor?)

MegaJerk
Collaborator Collaborator
354 Views
2 Replies
Message 1 of 3

Camera / View Rep - Crash (Do you want to crash Inventor?)

MegaJerk
Collaborator
Collaborator

Got a minute to spare to see if the below code will crash your inventor session? If so, continue reading. If not, well then… stop! The more feedback the better!

 

I spent a few days at home working on some code to better assist with creating & populating Design View Representations. The work was being done in Inventor 2012, and I was able to get the major portions working without much hassle.

However, upon testing it at work, it would crash my Inventor session without fail!!!! Trying to troubleshoot the issue, I passed it off to a few co-workers who were able to use it with no problems…

After a full reinstall of Inventor, and testing it out on different workstations, I eventually narrowed the problem down to with how Inventor sets the PerspectiveAngle value if your viewing your model in Perspective (not Orthographic), and all of the occurrences have been set to visible = false.

If those conditions are ever met, the value of PerspectiveAngle will be changed beyond the bounds of its type and will result in an overflow error, and will inform the user that Inventor was unable to allocate the proper amount of memory. This kills the Inventor.

Though I have not attached an assembly file, I have included some testing code that you should be able to use to crash your Inventor session! Please note that if you’re using Orthographic stage view or if you’re using inventor 2012, you should be fine. However, using Perspective stage view and versions above 2012 (<- not sure which year this bug was introduced which is why I need you to act as crash testers) should result in killing Inventor.

Thank you all for your (potential) help! Code below

------------------------

!!!!!!! THIS WILL POSSIBLY CRASH YOUR INVENTOR SESSION! DO NOT USE IF YOU ARE WORKING ON ACTUAL WORK UNLESS YOU WANT TO CRY YOURSELF TO SLEEP !!!!!!!!
------------------------

 

 

Imports Inventor.ViewOrientationTypeEnum


If ThisApplication.ActiveDocument.DocumentType _
<> kAssemblyDocumentObject Then
    MessageBox.Show ("Run from an Assembly!!!")
    Return
End If

' Set the current assembly to the active document 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Set the document's Assembly Component Definition

Dim oCompDef As AssemblyComponentDefinition
oCompDef = oDoc.ComponentDefinition

' Setting the Reps Manager

Dim oRepManager As RepresentationsManager
oRepManager = oCompDef.RepresentationsManager

' This used to test to see if you were on a 'Locked'
' ViewRep, but that doesn't work because for whatever reason, 
' If you're on the Master View Rep, it is ***NOT*** flagged 
' as being locked through the ActiveDesignViewRepresentation
' , even though it is locked if you were to look at the Design View
' directly through the Items collection.
'
' This might be another bug. 

If oRepManager.ActiveDesignViewRepresentation.Name <> "View1" Then
	Try 
		oRepManager.DesignViewRepresentations.Item("View1").Activate
	Catch 
		oRepManager.DesignViewRepresentations.Add("View1")
	Finally 
		oRepManager.DesignViewRepresentations.Item("View1").Activate
	End Try
End If

' Let's set our oViewRep to the Active Design View

Dim oViewRep As DesignViewRepresentation
oViewRep = oRepManager.ActiveDesignViewRepresentation

' Setting the DesignViewReps

Dim oViewReps As DesignViewRepresentations
oViewReps = oRepManager.DesignViewRepresentations

' Getting all of the Components from the assembly
    
Dim oCompOccs As ComponentOccurrences
oCompOccs = oCompDef.Occurrences

' Setting an empty ComponentOccurrence container

Dim oCompOcc As ComponentOccurrence

' Change the view of ALL Components to Invisible
' The Perspective / Camera error will only occure 
' if there are no visible Components. 

For Each oCompOcc In oCompOccs
    oCompOcc.Visible = False
Next

' Let's get the Camera from the Active View Rep

Dim oCam As Camera
oCam = ThisApplication.ActiveView.Camera


' If your set for Ortho, we'll change it to Perspective.
' If you're already set to Perspective, this doesn't 
' really do anything. 

oCam.Perspective = True
oCam.Apply

' NO matter, while on Perspective, and
' with no parts visible, once you change the -
' ViewOrientationType to any valid enum, the 
' PerspectiveAngle Is changed to a value outside
' of the Type Bounds For a Double.

oCam.ViewOrientationType = kIsoTopRightViewOrientation
oCam.Fit()
Call oCam.Apply()

' Typically doing the above will crash you, however
' occasionally it will not. Adding a new View Rep 
' 'which will change the active camera' will push it over
' the edge, but even sometimes this is just as spotty. 

Dim oNewViewRep As DesignViewRepresentation
oNewViewRep = oViewReps.Add("Crash")
oNewViewRep.Activate
oNewViewRep.Delete

Dim oOriginalCamera As Camera
oOriginalCamera = oViewRep.Camera

' Just in case you haven't crashed yet
' I'm throwing this in there because it where I will 
' absolutely run into problems. Trying to turn the Occurrences
' back to visible will make bad things happen!

For Each oCompOcc In oCompOccs
    oCompOcc.Visible = True
Next

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
355 Views
2 Replies
Replies (2)
Message 2 of 3

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

Thanks for reporting this.

I too could reproduce the issue and have logged it in our system.

 

I guess the obvious workaround is to make sure that the camera view is not perspective when mofidying things, and then set it back to perspective at the very end: that seemed to work fine for me.

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 3

Owner2229
Advisor
Advisor

Hi, so I tested it in Inventor 2016 and here are the results:

Setting camera to "IsoTopRightViewOrientation" works 100% fine here, didn't crash even once, however adding new view representation crashed every time. The same applies for turning the occurrences back to visible. I did even try to do it manualy, but stil crashed.

I tested both Perspective/Orto and all parts visible/invisible.

 

From my point of view is your code fine, can't see any issues, so it may be Inventor issue.

 

In the end I'd like to thank you for such amazing job you're doing for this community (Injector, solutions, tips etc.).

Keep up the good work.

 

And ofc. sorry for my english.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes