Here are three different approaches to save a snapshot picture of a document view.
1 - Simply saving the active view as is. Note that if you specify a top color, you will have to pass also a bottom one:
Sub SaveView1()
Dim view As view
Set view = ThisApplication.ActiveView
Dim camera As camera
Set camera = view.camera
Dim topClr As color
Set topClr = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
Dim bottomClr As color
Set bottomClr = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
Call camera.SaveAsBitmap("C:\Temp\test.png", _
view.width, view.height, topClr, bottomClr)
End Sub
2 - That second approach is creating an additional view and closing it at the end. You could use that approach if you plan to modify the view in any way to create the snapshot and want to conserve the active view intact for the user:
-
Sub SaveView2()
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim view As view
Set view = doc.views.Add
Dim camera As camera
Set camera = view.camera
Dim topClr As color
Set topClr = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
Dim bottomClr As color
Set bottomClr = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
Call camera.SaveAsBitmap("C:\Temp\test.png", _
view.width, view.height, topClr, bottomClr)
view.Close
End Sub
3 - The third approach is creating a transient camera. It similar to the second way but probably better because you don’t have to create a temporary view:
-
Sub SaveView3()
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim view As view
Set view = ThisApplication.ActiveView
Dim camera As camera
Set camera = ThisApplication.TransientObjects.CreateCamera
camera.SceneObject = doc.ComponentDefinition
camera.ViewOrientationType = kIsoTopLeftViewOrientation
camera.Fit
camera.ApplyWithoutTransition
Dim topClr As color
Set topClr = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
Dim bottomClr As color
Set bottomClr = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
Call camera.SaveAsBitmap("C:\Temp\test.png", _
view.width, view.height, topClr, bottomClr)
End Sub