Function Main As String
' Batch mode export from ChemSketch's page to BMP.GIF,MOL files

' THE EXAMPLE ILLUSTRATES THE USE OF:
'   ActiveDocument
'   ActivePage
'   Drawings
'   Diagrams
'   Count
'   Self
'   ExportToBMP
'   ExportToGIF
'   ExportToMOL
'   For Each




Dim page,diagram as object,fname as string, OK as boolean
Dim s,stri,dcr As String, i,k,j As Integer
Const title="SHOW DRAW OBJECTS METHODS"



  k=MBB_OK + MBI_INFORMATION
  dcr=Chr(13)+Chr(13)

  Main="Not completed."
  i=0
  Page=ActiveDocument.ActivePage
  If Page.Drawings.Count<1 Then
    i=MessageBox("Your page is empty, sorry", title, k)
    Goto ShutDown
  EndIf

  With Page.Diagrams
    If .Count<1 Then
      j=MessageBox("Your page contains no molecules, sorry", title, k)
      Goto ShutDown
    EndIf
    For Each diagram In .Self
      i=i+1
      stri=Str(i)
      fname=stri
      'first of all, save as pictures
      OK=diagram.ExportToBMP (fname+".BMP")
      if OK Then j=MessageBox("Molecule #"+Str(i)+" saved as "+stri+".BMP", title, k)
      OK=diagram.ExportToGIF (fname+".GIF")
      if OK Then j=MessageBox("Molecule #"+Str(i)+" saved as "+stri+".GIF", title, k)
      'save as MOL file
      OK=diagram.ExportToMOL(fname+".MOL")
      if OK Then j=MessageBox("Molecule #"+Str(i)+" saved as "+stri+".MOL", title, k)
    Next diagram
  End With

ShutDown:
  Main="Demo completed"
End Function
