Sub CATMain()
tempfolder = Environ("Temp")
filenames = Array(tempfolder & "\initial.jpg", tempfolder & "\usual.jpg", tempfolder & "\lowlight.jpg", tempfolder & "\no3d.jpg")
Set oViewer = CATIA.ActiveWindow.ActiveViewer
oViewer.CaptureToFile catCaptureFormatJPEG, filenames(0)
CATIA.StartCommand ("Usual")
oViewer.CaptureToFile catCaptureFormatJPEG, filenames(1)
CATIA.StartCommand ("Low light")
oViewer.CaptureToFile catCaptureFormatJPEG, filenames(2)
CATIA.StartCommand ("No 3D Background")
oViewer.CaptureToFile catCaptureFormatJPEG, filenames(3)
initvalue = FileLen(filenames(0))
usualvalue = FileLen(filenames(1))
lowlightvalue = FileLen(filenames(2))
no3dvalue = FileLen(filenames(3))
' checking which file is the same as the initial state
solution = 0
If initvalue = usualvalue Then solution = solution + 1
If initvalue = lowlightvalue Then solution = solution + 2
If initvalue = no3dvalue Then solution = solution + 4
CATIA.StartCommand ("Fit All In")
Set oSel = CATIA.ActiveDocument.Selection
oSel.Clear
On Error Resume Next
While oSel.Count = 0
CATIA.RefreshDisplay = True
oSel.Search ("Sketcher.Origin,scr")
Wend
On Error GoTo 0
Set oSketch = oSel.Item(1).Value.Parent.Parent.Parent
oSel.Clear
MsgBox (" the sketch is " & oSketch.Name)
' restoring initial visu
Select Case solution
Case 1
CATIA.StartCommand ("Usual")
Case 2
CATIA.StartCommand ("Low light")
Case 4
CATIA.StartCommand ("No 3D Background")
Case Else
MsgBox ("Can't be sure about initial sketch visu setting")
End Select
For i = 0 To 3
Kill filename(i)
Next
End Sub