!***********************************************************************
!  createswf / 2007-01-29 / Vertex Systems                             *
!                                                                      *
!  Convert Vertex drawing file into .swf format.                       *
!***********************************************************************

! Layer group to plot, "" to plot all
Levels$ = ""

JobDir$ = get($DIR)
VxFile$ = get($FILE)
Path$ = JobDir$&"/"&VxFile$

P = findstr(VxFile$,"p_")
if P==1 then
  File$ = VxFile$[3]
else
  P = findstr(VxFile$,".vxp")
  if P then
    File$ = VxFile$[1,P-1]
  else
    exit
  endif
endif
SwfFile$ = JobDir$&"/"&File$&".swf"

Ok = dwgopen("PICTURE",Path$, 10,10,35,100)
if Ok then
  dwgactivate "PICTURE"

  HomeDir$ = get($DIR_HOME)
  TmpPlotFile$ = HomeDir$&"plot.drwg"
  PlotterDef$ = "plotter= PDF-TEMP 7 5 """&TmpPlotFile$
  PlotterDef$ = PlotterDef$&""" """" 1 1 6 1 11 5.5 31 """" 32 ""PDF-SHEET"" 33 PDF"
  set PLOTTER_DEF PlotterDef$
  set PLOTTER_MODE "1"
  function PLOTTER_SET
  set SHEET_MODE "1"
  function SHEET_SET
  set PDF_PRINT "1"

  Scale = get($SCALE)
  Width = (Xlimit_max-Xlimit_min)/Scale
  Height = (Ylimit_max-Ylimit_min)/Scale
  MaxSize = inch_to_dwg(45.0)
  if Width >MaxSize then Width  = MaxSize
  if Height>MaxSize then Height = MaxSize
  set TMPSHEET_XMIN "0"
  set TMPSHEET_XMAX Width
  set TMPSHEET_YMIN "0"
  set TMPSHEET_YMAX Height
  function SET_PDF_SHEET

  Settings$ = "interaction=n,rotate=n,plotter=PDF-TEMP,free_scale=y"
  if len(Levels$) then Settings$ = Settings$",level_group="&Levels$"
  dwgplot Settings$

  set SHEET_MODE "0"
  function SHEET_SET
  set PLOTTER_MODE "0"
  function PLOTTER_SET

  dwgclose "PICTURE"
  dwgactivate "OLDDWG"

  Dir$ = get($DIR_PROGRAMS)
  GsProg$ = Dir$&"gs/gswin32c.exe"
  GsFonts$ = Dir$&"gs/fonts"
  SwfProg$ = Dir$&"pdf2swf.exe"
  PdfFile$ = HomeDir$&"plot.pdf"

  GsProg$ = convchars(GsProg$,"/","//")
  GsProg$ = convchars(GsProg$,"/","\\")
  GsFonts$ = convchars(GsFonts$,"/","//")
  GsFonts$ = convchars(GsFonts$,"/","\\")
  TmpPlotFile$ = convchars(TmpPlotFile$,"/","//")
  TmpPlotFile$ = convchars(TmpPlotFile$,"/","\\")
  SwfProg$ = convchars(SwfProg$,"/","//")
  SwfProg$ = convchars(SwfProg$,"/","\\")
  PdfFile$ = convchars(PdfFile$,"/","//")
  PdfFile$ = convchars(PdfFile$,"/","\\")
  SwfFile$ = convchars(SwfFile$,"/","//")
  SwfFile$ = convchars(SwfFile$,"/","\\")

  BatFile$ = HomeDir$&"createswf.bat"
  fileremove BatFile$
  open(1) BatFile$
  write(1) """"&GsProg$&""" -q -dNOPAUSE -dBATCH -I"""&GsFonts$&""" -sDEVICE=pdfwrite -sOutputFile="""&PdfFile$&""" """&TmpPlotFile$
  write(1) """"&SwfProg$&""" """&PdfFile$&""" -o """&SwfFile$
  close(1)
  Command$ = """"&BatFile$&""""
  Ok = system(Command$)

  fileremove TmpPlotFile$
  fileremove PdfFile$
  fileremove BatFile$
endif
