- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Camera / View Rep - Crash (Do you want to crash Inventor?)
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
