home *** CD-ROM | disk | FTP | other *** search
/ BUG 11 / BUGCD1998_02.ISO / aplic / turbocad / tcw.z / mdc.bas < prev    next >
BASIC Source File  |  1997-05-05  |  10KB  |  445 lines

  1. '******************************************************************
  2. '*                                                                *
  3. '*                      TurboCAD for Windows                      *
  4. '*                   Copyright (c) 1993 - 1996                    *
  5. '*             International Microcomputer Software, Inc.         *
  6. '*                            (IMSI)                              *
  7. '*                      All rights reserved.                      *
  8. '*                                                                *
  9. '******************************************************************
  10. '
  11. ' Filename: MDC.BAS (Multiple Drawing Converter 2.0 Beta)
  12. '
  13. ' Author:    Pat Garner
  14. '
  15. ' Date:        1/8/97
  16. '
  17. '
  18. ' Scriptname:    Multiple Drawing Converter
  19. '
  20. ' Version:        2.0 Beta
  21. '
  22. ' Changes:        Moved All Script options from 
  23. '                input boxes to a 'UI' dialog.
  24. '
  25. '
  26. ' Description:    Script asks for a directory and filetype
  27. '                sufix, and then creates a list of files
  28. '                of the specified filetype from the specified
  29. '                directory and then attempts to sequentially 
  30. '                load, save, and close all files in the list.
  31. '                You also have the option to print files both
  32. '                before and after conversion as well as exit
  33. '                the application upon script completion.
  34. '
  35. '
  36. ' TurboCAD (TCADAPI) Functions used in this script:
  37. '    
  38. '    - TCWAppExit
  39. '    - TCWLastErrorGet
  40. '    - TCWDrawingNew
  41. '    - TCWDrawingOpen
  42. '    - TCWDrawingClose
  43. '    - TCWDrawingSaveAs
  44. '    - TCWDrawingPrint
  45. '
  46. '
  47. ' TODO:
  48. '        - Convert subroutines to new comment style
  49. '        - Optimize and clean up subroutinesj
  50. '        - Convert textboxes to drop down list boxes
  51. '        - 
  52. '                 
  53. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  54.  
  55.  
  56.  
  57.  
  58. ''Script Global Access Variables'''''''''''''''''''''''''''''''
  59. '
  60. Dim dir                    As String
  61. Dim ext                    As String
  62. '
  63. Dim newdir                As String
  64. Dim newext                As String
  65. '
  66. Dim Printd                As Integer
  67. Dim BAB                    As Integer
  68. '
  69. Dim ExitApp                As Integer
  70. '
  71. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  72.  
  73.  
  74.  
  75.  
  76. ''Script Global Constants''''''''''''''''''''''''''''''''''''''
  77. '
  78. '
  79. Global Const BEFORE        = 0
  80. Global Const AFTER         = 1
  81. Global Const BOTH        = 2
  82. '
  83. Global Const NO            = 0
  84. Global Const YES        = 1
  85. '
  86. '
  87. ' Set to 1 to exit after UI dialog, or 2 to exit after
  88. '  one iteration of file loop 
  89. '
  90. Global Const DEBUG_MODE            = 0
  91. '
  92. '
  93. ' * Set this value to 0 to show print dialog in file loop 
  94. '
  95. Global Const SHOW_PRINT_DIALOG    = 1 
  96. '
  97. '                                    
  98. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  99.  
  100.  
  101.  
  102.  
  103. ''SUBROUTINE: MAIN'''''''''''''''''''''''''''''''''''''''''''''
  104. '
  105. ' * Parameters: None
  106. ' * 
  107. ' *
  108. ' * Return Value: None
  109. ' * 
  110. ' *
  111. ' * Description:
  112. ' *
  113. ' *        Main is the conductor of the program
  114. ' *         and like a music conductor, tells
  115. ' *         the other parts of the program when
  116. ' *         it's time to do their thing.
  117. ' *
  118. ' *
  119. Sub main()
  120.     
  121.     ' * File manipulation variable declarations 
  122.     Dim pos                    As Integer
  123.     Dim filename            As String
  124.     Dim newfilenameplusdir    As String
  125.     Dim filenameplusdir        As String 
  126.  
  127.     
  128.     UIDialog
  129.     
  130.  
  131.     ' * Create a batch file that will compile our file list for us 
  132.     open "c:\filelist.bat" for output as #1
  133.  
  134.         print # 1, "@echo off"
  135.         print # 1, "dir /b " & dir & "\" & "*." & ext & " >c:\filelist.txt"
  136.  
  137.     close 
  138.  
  139.  
  140.     ' * Run batch file to create the file list 
  141.     Shell "command.com /c c:\filelist.bat", 2
  142.  
  143.  
  144.     'Pause for a second or three
  145.     for i#=0 To 1000000
  146.     next i
  147.  
  148.  
  149.     ' * Open our filelist file for reading 
  150.     open "c:\filelist.txt" for input as #1
  151.  
  152.         ' * Start the file loop and keep iterating until 
  153.         ' *  you've reached the end of the file. 
  154.         do while not EOF(1)
  155.  
  156.  
  157.             ' * Read in a file name 
  158.             line input #1, filename
  159.  
  160.  
  161.             ' * Find out where the extension starts in the filename 
  162.             pos = InStr(1,filename, ".")
  163.  
  164.  
  165.             ' * Append the filename onto the end of the 
  166.             ' *  directory we wish to load files from. 
  167.             filenameplusdir = dir & "\" & Left$(filename, pos+3)
  168.  
  169.  
  170.             ' * Open the current drawing 
  171.             TCWDrawingOpen filenameplusdir
  172.  
  173.  
  174.             ' * If the user answered yes to print, 
  175.             ' *  check to see if the user wishes to 
  176.             ' *  print before conversion... 
  177.             if Printd = YES then
  178.  
  179.                 if BAB = BEFORE OR BAB = BOTH then
  180.  
  181.                     ' * Print the drawing 
  182.                     TCWDrawingPrint SHOW_PRINT_DIALOG ' * NOTE: PrinDialog contains a value, 
  183.                                                 ' *  which instructs TCWDrawingPrint 
  184.                                                 ' *  to show the print dialog or not. 
  185.                 end if
  186.  
  187.             end if
  188.  
  189.             
  190.             ' * Create new filename containing the 
  191.             ' *  original filename plus the new 
  192.             ' *  extension. 
  193.             filename = Left$(filename, pos) & newext
  194.  
  195.             
  196.             ' * Append the newfilename onto the 
  197.             ' *  directory the user wishes to save 
  198.             ' *  the converted files to 
  199.             newfilenameplusdir = newdir & "\" & filename
  200.  
  201.  
  202.             ' * Save the current drawing with our 
  203.             ' *  new filename to the directory 
  204.             ' *  originally specified by the user. 
  205.             TCWDrawingSaveAs newfilenameplusdir, FALSE
  206.  
  207.             
  208.             ' * If the user answered yes to print check to see 
  209.             ' * if the user wishes to print after conversion... 
  210.             if Printd = YES then
  211.             
  212.                 if BAB = AFTER OR BAB = BOTH then
  213.             
  214.                     ' * Print the drawing 
  215.                     TCWDrawingPrint SHOW_PRINT_DIALOG ' * NOTE: PrinDialog contains a value, 
  216.                                                 ' *  which instructs TCWDrawingPrint 
  217.                                                 ' *  to show the print dialog or not. 
  218.                 end if
  219.  
  220.             end if
  221.  
  222.  
  223.             ' * Close the currently open drawing 
  224.             TCWDrawingClose
  225.  
  226.  
  227.         
  228.             if DEBUG_MODE = 2 then                    ' * If Debug has been set to 1, 
  229.  
  230.                 MsgBox "DEBUG STOP: File Loop"        ' *  Display a message box telling 
  231.                                                     ' *  us this, and the, ... 
  232.  
  233.                 END                                    ' *  stop script execution before 
  234.                                                     ' *  loop iterates again. 
  235.  
  236.             end if
  237.  
  238.         
  239.         loop                ' * Iterate loop 
  240.                                     
  241.     close #1                ' * Close filelist filestream 
  242.     
  243.  
  244.     RemoveExternalFiles
  245.     ExitScript
  246.  
  247. End Sub    
  248. '
  249. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  250.  
  251.  
  252.  
  253.  
  254. ''SUBROUTINE: RemoveExternalFiles''''''''''''''''''''''''''''''
  255. '
  256. ' * Parameters: None
  257. ' * 
  258. ' *
  259. ' * Return Value: None
  260. ' * 
  261. ' *
  262. ' * Description:
  263. ' *
  264. ' *        Removes special files created by this script
  265. ' *         for it's own use.
  266. ' *
  267. ' *
  268. Sub RemoveExternalFiles ()
  269.  
  270.     Shell "command.com /c del c:\filelist.bat", 6    ' * Delete our filelist 
  271.                                                     ' *  creation batch file 
  272.  
  273.     Shell "command.com /c del c:\filelist.txt", 6    ' * Delete our filelist file 
  274.  
  275. End Sub
  276. '
  277. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  278.  
  279.  
  280.  
  281.  
  282. ''SUBROUTINE: ExitScript'''''''''''''''''''''''''''''''''''''''
  283. '
  284. ' * Parameters: None
  285. ' * 
  286. ' *
  287. ' * Return Value: None
  288. ' * 
  289. ' *
  290. ' * Description:
  291. ' *
  292. ' *        Exit TurboCAD upon completion
  293. ' *         of script if user turned option
  294. ' *         from UI dialog.
  295. ' * 
  296. ' *
  297. Sub ExitScript ()
  298.  
  299.     ' * If the user elected to exit the app after script completion, ... 
  300.     if ExitApp = YES then
  301.  
  302.  
  303.         ' * Display a message box telling us this ... *
  304.         MsgBox "Finished converting files!" & Chr$(10) & "Now Exiting Application!"
  305.  
  306.  
  307.         ' * And exit the application. 
  308.         TCWAppExit
  309.  
  310.  
  311.     else
  312.  
  313.  
  314.         ' * Otherwise, let the user know 
  315.         ' *  the script is done with the 
  316.         ' *  file conversion 
  317.         MsgBox "Finished converting files!"
  318.  
  319.  
  320.     end if
  321.  
  322. End Sub
  323. '
  324. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  325.  
  326.  
  327.  
  328.  
  329.  
  330. ''SUBROUTINE: UIDialog''''''''''''''''''''''''''''''''''''''''''
  331. '
  332. ' * Parameters: None
  333. ' * 
  334. ' *
  335. ' * Return Value: None
  336. ' * 
  337. ' *
  338. ' * Description:
  339. ' *
  340. ' *        This is the script's user interface subroutine.
  341. ' *         It's actually a dialog box definition that serves
  342. ' *         as a "template" for later creating a variable of
  343. ' *         of this type and them using the enable function
  344. ' *        'Dialog' to display it and return values.  The  
  345. ' *         dialog definition is done in a manner very similar 
  346. ' *         to creating user defined variables with the type 
  347. ' *         function in basic or the struct function in C.
  348. ' *         By utilizing several of the UI objects available
  349. ' *         you can actually create quite a useful interface 
  350. ' *         for setting script values and options as well as
  351. ' *         guiding the user through script setup with a 
  352. ' *         "wizard" like interface.  
  353. ' *
  354. ' *
  355. Sub UIDialog ()
  356.  
  357.     Begin Dialog FernUI 60, 60, 240, 185, "Multiple Drawing Converter"
  358.  
  359.         Text        10, 10, 150, 10,    "Directory you wish to open from:"
  360.         TextBox        120, 10, 110, 10,    .OpenDir
  361.  
  362.         Text        10, 20, 150, 10,    "Extension of files load:"
  363.         TextBox        120, 20, 110, 10,    .OpenType
  364.         
  365.         Text        10, 30, 150, 10,    "Directory you wish to save to:"
  366.         TextBox        120, 30, 110, 10,    .SaveDir
  367.         
  368.         Text        10, 40, 150, 10,    "Extention to save to:"
  369.         TextBox        120, 40, 110, 10,    .SaveType
  370.         
  371.         CheckBox    10, 60, 150, 10,    "Exit TurboCAD upon script completion", .ExitTCW
  372.         
  373.         CheckBox    10, 70, 100, 20,    "Print drawings", .Print
  374.         
  375.         GroupBox    10, 90, 130, 40,    "Print Before conversion, after, or both?", .PrintBeforeAfterOrBoth
  376.  
  377.         OptionGroup .WhenToPrint
  378.  
  379.             OptionButton 20, 100, 30, 8,    "Before",    .Before
  380.             OptionButton 20, 110, 30, 8,    "After",    .After
  381.             OptionButton 20, 120, 30, 8,    "Both",        .Both
  382.  
  383.         
  384.         OKbutton     80, 170, 40, 12
  385.         CancelButton 120, 170, 40, 12
  386.  
  387.     End Dialog
  388.     
  389.     
  390.     Dim Dlg1 As FernUI
  391.  
  392.         Dlg1.OpenDir    = "c:\imsi\tcw30\drawings"
  393.         Dlg1.OpenType    = "tcw"
  394.         
  395.         Dlg1.SaveDir    = "c:\imsi\tcw30\drawings"
  396.         Dlg1.SaveType    = "tcw"
  397.         
  398.         Dlg1.Print        = 0
  399.         Dlg1.ExitTCW    = 0
  400.  
  401.     
  402.     button = Dialog(Dlg1)
  403.  
  404.  
  405.     if button = 0 then
  406.  
  407.         END
  408.  
  409.     elseif button = -1 then
  410.  
  411.         dir        = Dlg1.OpenDir
  412.         ext        = Dlg1.OpenType
  413.  
  414.         newdir    = Dlg1.SaveDir
  415.         newext    = Dlg1.SaveType
  416.  
  417.         Printd    = Dlg1.Print
  418.         BAB        = Dlg1.WhenToPrint 
  419.         
  420.         ExitApp = Dlg1.ExitTCW
  421.  
  422.         
  423.         if DEBUG_MODE = 1 then
  424.                 
  425.             MsgBox    "dir: "        & dir        & Chr$(10) & _ 
  426.                     "ext: "        & ext        & Chr$(10) & _ 
  427.                     Chr$(10)    & _ 
  428.                     "newdir: "    & newdir    & Chr$(10) & _ 
  429.                     "newext: "    & newext    & Chr$(10) & _ 
  430.                     Chr$(10)    & _ 
  431.                     "Printd: "    & Printd    & Chr$(10) & _ 
  432.                     "BAB: "        & BAB        & Chr$(10) & _ 
  433.                     Chr$(10)    & _ 
  434.                     "ExitApp: " & ExitApp    
  435.  
  436.             END
  437.  
  438.         end if
  439.  
  440.                 
  441.     end if
  442.     
  443. End Sub
  444.