home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Buyer 1998 February
/
DPCB0298.iso
/
DTP
/
TurboCad
/
TCW.Z
/
mdc.bas
< prev
next >
Wrap
BASIC Source File
|
1997-05-05
|
10KB
|
445 lines
'******************************************************************
'* *
'* TurboCAD for Windows *
'* Copyright (c) 1993 - 1996 *
'* International Microcomputer Software, Inc. *
'* (IMSI) *
'* All rights reserved. *
'* *
'******************************************************************
'
' Filename: MDC.BAS (Multiple Drawing Converter 2.0 Beta)
'
' Author: Pat Garner
'
' Date: 1/8/97
'
'
' Scriptname: Multiple Drawing Converter
'
' Version: 2.0 Beta
'
' Changes: Moved All Script options from
' input boxes to a 'UI' dialog.
'
'
' Description: Script asks for a directory and filetype
' sufix, and then creates a list of files
' of the specified filetype from the specified
' directory and then attempts to sequentially
' load, save, and close all files in the list.
' You also have the option to print files both
' before and after conversion as well as exit
' the application upon script completion.
'
'
' TurboCAD (TCADAPI) Functions used in this script:
'
' - TCWAppExit
' - TCWLastErrorGet
' - TCWDrawingNew
' - TCWDrawingOpen
' - TCWDrawingClose
' - TCWDrawingSaveAs
' - TCWDrawingPrint
'
'
' TODO:
' - Convert subroutines to new comment style
' - Optimize and clean up subroutinesj
' - Convert textboxes to drop down list boxes
' -
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''Script Global Access Variables'''''''''''''''''''''''''''''''
'
'
Dim dir As String
Dim ext As String
'
Dim newdir As String
Dim newext As String
'
Dim Printd As Integer
Dim BAB As Integer
'
Dim ExitApp As Integer
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''Script Global Constants''''''''''''''''''''''''''''''''''''''
'
'
Global Const BEFORE = 0
Global Const AFTER = 1
Global Const BOTH = 2
'
Global Const NO = 0
Global Const YES = 1
'
'
' Set to 1 to exit after UI dialog, or 2 to exit after
' one iteration of file loop
'
Global Const DEBUG_MODE = 0
'
'
' * Set this value to 0 to show print dialog in file loop
'
Global Const SHOW_PRINT_DIALOG = 1
'
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''SUBROUTINE: MAIN'''''''''''''''''''''''''''''''''''''''''''''
'
' * Parameters: None
' *
' *
' * Return Value: None
' *
' *
' * Description:
' *
' * Main is the conductor of the program
' * and like a music conductor, tells
' * the other parts of the program when
' * it's time to do their thing.
' *
' *
Sub main()
' * File manipulation variable declarations
Dim pos As Integer
Dim filename As String
Dim newfilenameplusdir As String
Dim filenameplusdir As String
UIDialog
' * Create a batch file that will compile our file list for us
open "c:\filelist.bat" for output as #1
print # 1, "@echo off"
print # 1, "dir /b " & dir & "\" & "*." & ext & " >c:\filelist.txt"
close
' * Run batch file to create the file list
Shell "command.com /c c:\filelist.bat", 2
'Pause for a second or three
for i#=0 To 1000000
next i
' * Open our filelist file for reading
open "c:\filelist.txt" for input as #1
' * Start the file loop and keep iterating until
' * you've reached the end of the file.
do while not EOF(1)
' * Read in a file name
line input #1, filename
' * Find out where the extension starts in the filename
pos = InStr(1,filename, ".")
' * Append the filename onto the end of the
' * directory we wish to load files from.
filenameplusdir = dir & "\" & Left$(filename, pos+3)
' * Open the current drawing
TCWDrawingOpen filenameplusdir
' * If the user answered yes to print,
' * check to see if the user wishes to
' * print before conversion...
if Printd = YES then
if BAB = BEFORE OR BAB = BOTH then
' * Print the drawing
TCWDrawingPrint SHOW_PRINT_DIALOG ' * NOTE: PrinDialog contains a value,
' * which instructs TCWDrawingPrint
' * to show the print dialog or not.
end if
end if
' * Create new filename containing the
' * original filename plus the new
' * extension.
filename = Left$(filename, pos) & newext
' * Append the newfilename onto the
' * directory the user wishes to save
' * the converted files to
newfilenameplusdir = newdir & "\" & filename
' * Save the current drawing with our
' * new filename to the directory
' * originally specified by the user.
TCWDrawingSaveAs newfilenameplusdir, FALSE
' * If the user answered yes to print check to see
' * if the user wishes to print after conversion...
if Printd = YES then
if BAB = AFTER OR BAB = BOTH then
' * Print the drawing
TCWDrawingPrint SHOW_PRINT_DIALOG ' * NOTE: PrinDialog contains a value,
' * which instructs TCWDrawingPrint
' * to show the print dialog or not.
end if
end if
' * Close the currently open drawing
TCWDrawingClose
if DEBUG_MODE = 2 then ' * If Debug has been set to 1,
MsgBox "DEBUG STOP: File Loop" ' * Display a message box telling
' * us this, and the, ...
END ' * stop script execution before
' * loop iterates again.
end if
loop ' * Iterate loop
close #1 ' * Close filelist filestream
RemoveExternalFiles
ExitScript
End Sub
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''SUBROUTINE: RemoveExternalFiles''''''''''''''''''''''''''''''
'
' * Parameters: None
' *
' *
' * Return Value: None
' *
' *
' * Description:
' *
' * Removes special files created by this script
' * for it's own use.
' *
' *
Sub RemoveExternalFiles ()
Shell "command.com /c del c:\filelist.bat", 6 ' * Delete our filelist
' * creation batch file
Shell "command.com /c del c:\filelist.txt", 6 ' * Delete our filelist file
End Sub
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''SUBROUTINE: ExitScript'''''''''''''''''''''''''''''''''''''''
'
' * Parameters: None
' *
' *
' * Return Value: None
' *
' *
' * Description:
' *
' * Exit TurboCAD upon completion
' * of script if user turned option
' * from UI dialog.
' *
' *
Sub ExitScript ()
' * If the user elected to exit the app after script completion, ...
if ExitApp = YES then
' * Display a message box telling us this ... *
MsgBox "Finished converting files!" & Chr$(10) & "Now Exiting Application!"
' * And exit the application.
TCWAppExit
else
' * Otherwise, let the user know
' * the script is done with the
' * file conversion
MsgBox "Finished converting files!"
end if
End Sub
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''SUBROUTINE: UIDialog''''''''''''''''''''''''''''''''''''''''''
'
' * Parameters: None
' *
' *
' * Return Value: None
' *
' *
' * Description:
' *
' * This is the script's user interface subroutine.
' * It's actually a dialog box definition that serves
' * as a "template" for later creating a variable of
' * of this type and them using the enable function
' * 'Dialog' to display it and return values. The
' * dialog definition is done in a manner very similar
' * to creating user defined variables with the type
' * function in basic or the struct function in C.
' * By utilizing several of the UI objects available
' * you can actually create quite a useful interface
' * for setting script values and options as well as
' * guiding the user through script setup with a
' * "wizard" like interface.
' *
' *
Sub UIDialog ()
Begin Dialog FernUI 60, 60, 240, 185, "Multiple Drawing Converter"
Text 10, 10, 150, 10, "Directory you wish to open from:"
TextBox 120, 10, 110, 10, .OpenDir
Text 10, 20, 150, 10, "Extension of files load:"
TextBox 120, 20, 110, 10, .OpenType
Text 10, 30, 150, 10, "Directory you wish to save to:"
TextBox 120, 30, 110, 10, .SaveDir
Text 10, 40, 150, 10, "Extention to save to:"
TextBox 120, 40, 110, 10, .SaveType
CheckBox 10, 60, 150, 10, "Exit TurboCAD upon script completion", .ExitTCW
CheckBox 10, 70, 100, 20, "Print drawings", .Print
GroupBox 10, 90, 130, 40, "Print Before conversion, after, or both?", .PrintBeforeAfterOrBoth
OptionGroup .WhenToPrint
OptionButton 20, 100, 30, 8, "Before", .Before
OptionButton 20, 110, 30, 8, "After", .After
OptionButton 20, 120, 30, 8, "Both", .Both
OKbutton 80, 170, 40, 12
CancelButton 120, 170, 40, 12
End Dialog
Dim Dlg1 As FernUI
Dlg1.OpenDir = "c:\imsi\tcw30\drawings"
Dlg1.OpenType = "tcw"
Dlg1.SaveDir = "c:\imsi\tcw30\drawings"
Dlg1.SaveType = "tcw"
Dlg1.Print = 0
Dlg1.ExitTCW = 0
button = Dialog(Dlg1)
if button = 0 then
END
elseif button = -1 then
dir = Dlg1.OpenDir
ext = Dlg1.OpenType
newdir = Dlg1.SaveDir
newext = Dlg1.SaveType
Printd = Dlg1.Print
BAB = Dlg1.WhenToPrint
ExitApp = Dlg1.ExitTCW
if DEBUG_MODE = 1 then
MsgBox "dir: " & dir & Chr$(10) & _
"ext: " & ext & Chr$(10) & _
Chr$(10) & _
"newdir: " & newdir & Chr$(10) & _
"newext: " & newext & Chr$(10) & _
Chr$(10) & _
"Printd: " & Printd & Chr$(10) & _
"BAB: " & BAB & Chr$(10) & _
Chr$(10) & _
"ExitApp: " & ExitApp
END
end if
end if
End Sub