Hey Brian, thanks for the quick reply.
Your example does work in VBA and it runs successfully on my machine as well, but when I try the same method in my add-in which is written in VB.NET I get the issues I discussed above. Could there be some app domain issue going on here making it act differently in VB than in VBA? Below is the function I am having issues with.
Public Function BuildViewRepTables() As String
Try
Dim cDef As ComponentDefinition = InvApp.ActiveDocument.ComponentDefinition
'Capture the current activated view rep so
CurrentViewRep = cDef.RepresentationsManager.ActiveDesignViewRepresentation
InvApp.StatusBarText = "Generating Image..."
InvViewReps = cDef.RepresentationsManager.DesignViewRepresentations
'Create new instance of the required dictionaries.
ViewRepTables = New Dictionary(Of String, String)
ViewRepImages = New Dictionary(Of String, ImageBox)
For i As Integer = 2 To InvViewReps.Count
'Get the Inventor View Rep.
InvViewRep = InvViewReps.Item(i)
'Set up a generic view for output.
Dim OutputView As View = InvApp.ActiveDocument.Views.Add()
OutputView.WindowState = WindowsSizeEnum.kMaximize
OutputView.Visible = False
OutputView.Caption = InvViewRep.Name
OutputView.ShowAmbientShadows = True
OutputView.ShowObjectShadows = True
OutputView.ShowGroundReflections = False
OutputView.ShowGroundShadows = False
OutputView.ShowGroundPlane = False
OutputView.DisplayMode = DisplayModeEnum.kShadedWithEdgesRendering
'Activate the view rep and restore the save camera view.
InvViewRep.Activate()
InvViewRep.RestoreCamera()
Dim ViewRepCaption As String = Strings.Split(InvApp.ActiveDocument.DisplayName, ".")(0) + _
" [" + Strings.Replace(InvViewRep.Name, "/", " - ") + " View Rep]"
Dim ViewRepTempImgPath As String = DesignIntentDocumentFolder + ViewRepCaption + " [TEMP].png"
Dim ViewRepImgPath As String = DesignIntentDocumentFolder + ViewRepCaption + ".png"
Select Case InvViewRep.Camera.ViewOrientationType
Case ViewOrientationTypeEnum.kArbitraryViewOrientation
OutputView.Camera.Perspective = True
Case Else
OutputView.Camera.Perspective = False
End Select
'Save the temp ViewRepImage from Inventor.
'(This is the file that Inventor for whatever reason hangs on to and we cant close.)
OutputView.SaveAsBitmap(ViewRepTempImgPath, OutputView.Width, OutputView.Height)
'Crate the New ViewRep Image File.
Dim TempImage As New BitmapImage(New Uri(ViewRepTempImgPath))
'Create the ImageBox
Dim IB As New ImageBox(ViewRepImgPath, TempImage, ViewRepCaption)
'Add the new ViewRepImage to the dictionary.
ViewRepImages.Add(ViewRepCaption, IB)
OutputView.Update()
'OutputView._GraphicsCollectionEndDump("Delete", ViewRepTempImgPath)
OutputView.Close()
OutputView = Nothing
Next
InvApp.StatusBarText = "Completed Generating Images..."
'Reset the view rep back to the original one.
CurrentViewRep.Activate()
CurrentViewRep.RestoreCamera()
Catch ex As Exception
MsgBox("Error generating the Design View Rep Images!" & vbnewline & ex.Message)
End Try
Return ""
End Function
Also what does the "_GraphicsCollectionEndDump" method do and what are the params?
Thanks again.
Automation is key!