home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F38622_Converter.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-10-30  |  14.9 KB  |  499 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "Mscomctl.ocx"
  3. Begin VB.Form frmConverter 
  4.    Caption         =   "TurboCAD File Converter"
  5.    ClientHeight    =   6645
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   11415
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   6645
  13.    ScaleWidth      =   11415
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin MSComctlLib.ProgressBar ProgressBar1 
  16.       Height          =   345
  17.       Left            =   7080
  18.       TabIndex        =   20
  19.       Top             =   240
  20.       Width           =   4095
  21.       _ExtentX        =   7223
  22.       _ExtentY        =   609
  23.       _Version        =   393216
  24.       Appearance      =   0
  25.    End
  26.    Begin VB.CommandButton bCancel 
  27.       Caption         =   "Cancel"
  28.       Height          =   450
  29.       Left            =   4125
  30.       TabIndex        =   19
  31.       Top             =   5880
  32.       Visible         =   0   'False
  33.       Width           =   1300
  34.    End
  35.    Begin VB.CommandButton Close 
  36.       Caption         =   "Close"
  37.       Height          =   450
  38.       Left            =   2055
  39.       TabIndex        =   18
  40.       Top             =   5880
  41.       Width           =   1300
  42.    End
  43.    Begin VB.Timer Timer1 
  44.       Enabled         =   0   'False
  45.       Interval        =   500
  46.       Left            =   5535
  47.       Top             =   5700
  48.    End
  49.    Begin VB.ComboBox Combo2 
  50.       Height          =   315
  51.       Left            =   6960
  52.       Style           =   2  'Dropdown List
  53.       TabIndex        =   17
  54.       Top             =   5200
  55.       Width           =   4215
  56.    End
  57.    Begin VB.ComboBox Combo1 
  58.       Height          =   315
  59.       ItemData        =   "Converter.frx":0000
  60.       Left            =   1320
  61.       List            =   "Converter.frx":0002
  62.       MousePointer    =   1  'Arrow
  63.       Style           =   2  'Dropdown List
  64.       TabIndex        =   16
  65.       Top             =   5200
  66.       Width           =   4215
  67.    End
  68.    Begin VB.DriveListBox Drive2 
  69.       Height          =   315
  70.       Left            =   6000
  71.       TabIndex        =   6
  72.       Top             =   1080
  73.       Width           =   2415
  74.    End
  75.    Begin VB.DirListBox Dir2 
  76.       Height          =   2565
  77.       Left            =   6000
  78.       TabIndex        =   5
  79.       ToolTipText     =   "Select a directory where converted files will be placed."
  80.       Top             =   1680
  81.       Width           =   2415
  82.    End
  83.    Begin VB.FileListBox File2 
  84.       Height          =   2625
  85.       Left            =   8640
  86.       TabIndex        =   4
  87.       Top             =   1680
  88.       Width           =   2415
  89.    End
  90.    Begin VB.FileListBox File1 
  91.       Height          =   2625
  92.       Left            =   3000
  93.       MultiSelect     =   2  'Extended
  94.       TabIndex        =   3
  95.       ToolTipText     =   "A list of files to be converted."
  96.       Top             =   1680
  97.       Width           =   2415
  98.    End
  99.    Begin VB.DirListBox Dir1 
  100.       Height          =   2565
  101.       Left            =   360
  102.       TabIndex        =   2
  103.       ToolTipText     =   "Select a directory containing files for conversion."
  104.       Top             =   1680
  105.       Width           =   2415
  106.    End
  107.    Begin VB.DriveListBox Drive1 
  108.       Height          =   315
  109.       Left            =   360
  110.       TabIndex        =   1
  111.       Top             =   1080
  112.       Width           =   2415
  113.    End
  114.    Begin VB.CommandButton Run 
  115.       Caption         =   "Run"
  116.       Height          =   450
  117.       Left            =   105
  118.       TabIndex        =   0
  119.       ToolTipText     =   "Starts the conversion process."
  120.       Top             =   5880
  121.       Width           =   1300
  122.    End
  123.    Begin VB.Frame Source 
  124.       Caption         =   "Source:"
  125.       Height          =   4215
  126.       Left            =   120
  127.       TabIndex        =   7
  128.       Top             =   720
  129.       Width           =   5415
  130.       Begin VB.Label NFiles1 
  131.          Height          =   375
  132.          Left            =   3960
  133.          TabIndex        =   11
  134.          Top             =   3720
  135.          Width           =   1215
  136.       End
  137.       Begin VB.Label Label1 
  138.          Caption         =   "Total files:"
  139.          Height          =   375
  140.          Left            =   2880
  141.          TabIndex        =   8
  142.          Top             =   3720
  143.          Width           =   855
  144.       End
  145.    End
  146.    Begin VB.Frame Target 
  147.       Caption         =   "Destination:"
  148.       Height          =   4215
  149.       Left            =   5760
  150.       TabIndex        =   9
  151.       Top             =   720
  152.       Width           =   5415
  153.       Begin VB.Label NFiles2 
  154.          Height          =   375
  155.          Left            =   4080
  156.          TabIndex        =   12
  157.          Top             =   3720
  158.          Width           =   1215
  159.       End
  160.       Begin VB.Label Label2 
  161.          Caption         =   "Total files: "
  162.          Height          =   375
  163.          Left            =   2880
  164.          TabIndex        =   10
  165.          Top             =   3720
  166.          Width           =   855
  167.       End
  168.    End
  169.    Begin VB.Label ExportFiltersList 
  170.       Caption         =   "Files of type:"
  171.       Height          =   375
  172.       Left            =   5760
  173.       TabIndex        =   15
  174.       Top             =   5200
  175.       Width           =   975
  176.    End
  177.    Begin VB.Label ImportFiltersList 
  178.       Caption         =   "Files of type:"
  179.       Height          =   375
  180.       Left            =   120
  181.       TabIndex        =   14
  182.       Top             =   5200
  183.       Width           =   975
  184.    End
  185.    Begin VB.Label Label3 
  186.       BorderStyle     =   1  'Fixed Single
  187.       Height          =   345
  188.       Left            =   3000
  189.       TabIndex        =   13
  190.       Top             =   240
  191.       Width           =   3975
  192.    End
  193. Attribute VB_Name = "frmConverter"
  194. Attribute VB_GlobalNameSpace = False
  195. Attribute VB_Creatable = False
  196. Attribute VB_PredeclaredId = True
  197. Attribute VB_Exposed = False
  198. Private Sub File1_PatternChange()
  199.     File1.Refresh
  200. End Sub
  201. Private Sub File2_PatternChange()
  202.     File2.Refresh
  203. End Sub
  204. Private Sub Close_Click()
  205.     Unload frmConverter
  206.     Set Drs = Nothing
  207. End Sub
  208. Private Sub Combo1_LostFocus()
  209.     Timer1.Enabled = False
  210.     File1.Pattern = "*." & Left(Combo1.Text, 3)
  211.     File1.Refresh
  212.     NFiles1.Caption = File1.ListCount
  213. End Sub
  214. Private Sub Combo1_GotFocus()
  215.     CurCombo = True
  216.     Timer1.Enabled = True
  217.     CurImportFilter = Combo1.Text
  218. End Sub
  219. Private Sub Combo2_LostFocus()
  220.     Timer1.Enabled = False
  221.     File2.Pattern = "*." & Left(Combo2.Text, 3)
  222.     File2.Refresh
  223.     NFiles2.Caption = File2.ListCount
  224. End Sub
  225. Private Sub Combo2_GotFocus()
  226.     CurCombo = False
  227.     Timer1.Enabled = True
  228.     CurExportFilter = Combo2.Text
  229. End Sub
  230. Private Sub Dir1_Change()
  231.     File1.FileName = Dir1.Path
  232.     File1.Refresh
  233.     NFiles1.Caption = File1.ListCount
  234. End Sub
  235. Private Sub Dir2_Change()
  236.     File2.FileName = Dir2.Path
  237.     File2.Refresh
  238.     NFiles2.Caption = File2.ListCount
  239. End Sub
  240. Private Sub Drive1_Change()
  241. '    MsgBox Dir1.Path
  242.     On Error GoTo ErrHandler
  243.     Err.Clear
  244.     Dir1.Path = Drive1.Drive
  245.     Dir1.Refresh
  246.     File1.FileName = Dir1.Path
  247.     File1.Refresh
  248.     NFiles1.Caption = File1.ListCount
  249.     Exit Sub
  250. ErrHandler:
  251.     MsgBox Err.Description, vbOKOnly, LoadResString(101)
  252.     Drive1.Refresh
  253.     Dir1.Path = Drive1.Drive
  254.     Dir1.Refresh
  255.     File1.FileName = Dir1.Path
  256.     File1.Refresh
  257.     NFiles1.Caption = File1.ListCount
  258.     Err.Clear
  259. End Sub
  260. Private Sub Drive2_Change()
  261. '    MsgBox Dir1.Path
  262.     On Error GoTo ErrHandler
  263.     Err.Clear
  264.     Dir2.Path = Drive2.Drive
  265.     Dir2.Refresh
  266.     File2.FileName = Dir2.Path
  267.     File2.Refresh
  268.     NFiles2.Caption = File2.ListCount
  269.     Exit Sub
  270. ErrHandler:
  271.     MsgBox Err.Description, vbOKOnly, LoadResString(101)
  272.     Drive2.Refresh
  273.     Dir2.Path = Drive2.Drive
  274.     Dir2.Refresh
  275.     File2.FileName = Dir2.Path
  276.     File2.Refresh
  277.     NFiles2.Caption = File2.ListCount
  278.     Err.Clear
  279. End Sub
  280. Private Sub Form_Load()
  281.     bConversionRunned = False
  282.     Call Init_ReadFiltersList
  283.     File1.Refresh
  284.     Call Init_WriteFiltersList
  285.     File2.Refresh
  286. End Sub
  287. Private Sub Run_Click()
  288.     On Error GoTo ErrorHandler
  289.     Dim CadFile As String
  290.     Dim CadFileSave As String
  291.     Dim temp As String
  292.     Dim ext As String
  293.     Dim bSave As Boolean
  294.     Dim nFilestobeConverted As Integer
  295.     Dim bwasOpened As Boolean
  296.     bwasOpened = False
  297.     Dim lDrIndex As Long
  298.     lDrIndex = -1
  299.     bSave = False
  300.     ext = Left((Right(Combo1.Text, 4)), 3)
  301.     Dim i, iFilesCount As Integer
  302.     i = 0
  303.     iFilesCount = File1.ListCount
  304.     If (iFilesCount = 0) Then
  305. '        MsgBox "No " & ext & " files in source directory", vbOKOnly, "TurboCAD  File Converter"
  306.         MsgBox LoadResString(111) & ext & LoadResString(112), vbOKOnly, LoadResString(101)
  307.         Exit Sub
  308.     End If
  309.     frmConverter.Close.Enabled = False
  310.     bConversionRunned = True
  311.     frmConverter.Run.Enabled = False
  312.     nFilestobeConverted = CheckSourceFileList()
  313.     If (nFilestobeConverted > 0) Then
  314.         ' if at least one file is selected i the files list then perform conversion
  315.         'setup progress indicator
  316.         ProgressBar1.Min = 0
  317.         ProgressBar1.Max = nFilestobeConverted
  318.         ProgressBar1.Value = 0
  319.         ProgressBar1.Visible = True
  320.     Else
  321.         MsgBox LoadResString(110), vbOKOnly, LoadResString(101)
  322.         Call EnableButtons
  323.         Exit Sub
  324.     End If
  325.     i = 0
  326.     While (i < iFilesCount)
  327.         If (File1.Selected(i) = True) Then
  328.             Label3.Caption = File1.List(i) + LoadResString(114)
  329.             Label3.Refresh
  330.            
  331.             temp = Right(File1.Path, 1)
  332.             If (temp = "\") Then
  333.                 CadFile = File1.Path & File1.List(i)
  334.             Else
  335.                 CadFile = File1.Path & "\" & File1.List(i)
  336.             End If
  337.            
  338.             On Error Resume Next
  339.             Err.Clear
  340.             For Each Dr In Drs
  341.                 If (Dr.Path <> "") Then
  342.                     If (Dr.Path = CadFile) Then
  343.                         bwasOpened = True
  344.                         lDrIndex = Dr.Index
  345.                         Exit For
  346.                     End If
  347.                 End If
  348.                 Set Dr = Nothing
  349.             Next Dr
  350.             If bwasOpened And lDrIndex <> -1 Then
  351.                 Set Dr = Drs(lDrIndex)
  352.             Else
  353.                 Set Dr = Drs.Open(CadFile)
  354.             End If
  355.             If Err.Number <> 0 Then
  356.                 Err.Clear
  357.                 GoTo NextFile
  358.             End If
  359.            
  360.             temp = Right(File2.Path, 1)
  361.            
  362.             CadFileSave = Left(File1.List(i), (Len(File1.List(i)) - 4)) ' clip the extesion of the file
  363.             If (temp = "\") Then
  364.                 CadFileSave = File2.Path & CadFileSave & "." & Left(Combo2.Text, 3) ')Left((Right(Combo2.Text, 5)), 4)
  365.             Else
  366.                 CadFileSave = File2.Path & "\" & CadFileSave & "." & Left(Combo2.Text, 3) 'Left((Right(Combo2.Text, 5)), 4)
  367.             End If
  368.         
  369. '           Dr.SaveAs (CadFileSave)
  370. ' check drawing for duplicates IDs and correct if necessary
  371.             Call CorrectIDs(Dr)
  372.             
  373.             Dr.SaveCopyAs (CadFileSave)
  374.             If Not bwasOpened Then
  375.                 Dr.Close bSave
  376.             End If
  377.             ProgressBar1.Value = ProgressBar1.Value + 1
  378. NextFile:
  379.             Set Dr = Nothing
  380.             File2.Refresh
  381.             NFiles2.Caption = File2.ListCount
  382.             NFiles2.Refresh
  383.         End If
  384.         i = i + 1
  385.     Wend
  386.     ProgressBar1.Value = 0
  387.     ProgressBar1.Visible = False
  388. '  MsgBox "Conversion is complete !", vbOKOnly, "TurboCAD  file converter"
  389.     MsgBox LoadResString(116), vbOKOnly, LoadResString(101)
  390.     Label3.Caption = ""
  391.     Label3.Refresh
  392.     frmConverter.Close.Enabled = True
  393.     bConversionRunned = False
  394.     frmConverter.Run.Enabled = True
  395. Exit Sub
  396. ErrorHandler:
  397.     MsgBox Err.Description, , vbOKOnly, LoadResString(101)
  398.     frmConverter.Close.Enabled = True
  399.     bConversionRunned = False
  400.     frmConverter.Run.Enabled = True
  401.     ProgressBar1.Value = 0
  402.     ProgressBar1.Visible = False
  403. End Sub
  404. Sub Timer1_Timer()
  405.     If (CurCombo = True) Then
  406.         If (CurImportFilter <> Combo1.Text) Then
  407.             File1.Pattern = "*." & Left(Combo1.Text, 3)
  408.             File1.Refresh
  409.             NFiles1.Caption = File1.ListCount
  410.         End If
  411.     Else
  412.         If (CurExportFilter <> Combo2.Text) Then
  413.             File2.Pattern = "*." & Left(Combo2.Text, 3)
  414.             File2.Refresh
  415.             NFiles2.Caption = File2.ListCount
  416.         End If
  417.     End If
  418. End Sub
  419. Public Sub Init_ReadFiltersList()
  420. Dim n As Long
  421. Dim Ft As Filter
  422. Dim FtName As String
  423. Dim i As Long
  424. i = 0
  425. Set Ftrs = ObjApp.Filters
  426. n = Ftrs.Count
  427. Combo1.Clear
  428. 'Fill list of filters that TurboCAD can import
  429. While (i < n)
  430.     Set Ft = Ftrs.Item(i)
  431.     If (Ft.Capability = imsiRead Or Ft.Capability = imsiReadWrite) Then
  432.         If (Ft.Hidden = False) Then
  433.             ' skip bmf filter because it works via FP Bridge now
  434.             If (Ft.Extension <> "BMF") Then
  435.                 FtName = Ft.FilterString
  436.                 FtName = Left(FtName, (Len(FtName) - 8))
  437.                 Combo1.AddItem Ft.Extension & " " & " - " & Ft.Description
  438.             End If
  439.         End If
  440.     End If
  441.     Set Ft = Nothing
  442.     i = i + 1
  443. Combo1.ListIndex = 0
  444. File1.Pattern = "*." & Left(Combo1.Text, 3)
  445. File1.Refresh
  446. NFiles1.Caption = File1.ListCount
  447. Combo1.Refresh
  448. End Sub
  449. Public Sub Init_WriteFiltersList()
  450. Dim n As Long
  451. Dim Ft As Filter
  452. Dim FtName As String
  453. Dim i As Long
  454. i = 0
  455. Set Ftrs = ObjApp.Filters
  456. n = Ftrs.Count
  457. Combo2.Clear
  458. 'Fill list of filters that TurboCAD can export to
  459. While (i < n)
  460.     Set Ft = Ftrs.Item(i)
  461.     If (Ft.Capability = imsiWrite Or Ft.Capability = imsiReadWrite) Then
  462.         If (Ft.Hidden = False) Then
  463.             If (Ft.Extension(0) <> "BMF") Then
  464.                 FtName = Ft.FilterString
  465.                 FtName = Left(FtName, (Len(FtName) - 8))
  466.                 Combo2.AddItem Ft.Extension & " " & " - " & Ft.Description
  467.             End If
  468.         End If
  469.     End If
  470.     Set Ft = Nothing
  471.     i = i + 1
  472. Combo2.ListIndex = 1
  473. File2.Pattern = "*." & Left(Combo2.Text, 3)
  474. File2.Refresh
  475. NFiles2.Caption = File2.ListCount
  476. Combo2.Refresh
  477. End Sub
  478. Private Function CheckSourceFileList() As Integer
  479.     Dim i As Integer
  480.     Dim n As Integer
  481.     Dim k As Integer
  482.     k = 0
  483.     i = 0
  484.     n = File1.ListCount
  485.     CheckSourceFileList = 0
  486.     While (i < n)
  487.         If (File1.Selected(i) = True) Then
  488.             k = k + 1
  489.         End If
  490.         i = i + 1
  491.     Wend
  492. CheckSourceFileList = k
  493. End Function
  494. Private Sub EnableButtons()
  495.     frmConverter.Close.Enabled = True
  496.     bConversionRunned = False
  497.     frmConverter.Run.Enabled = True
  498. End Sub
  499.