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

  1. ' This sample program is an example of how to do custom file IO from
  2. ' TurboCAD. We will build graphics from the vertices in the table.
  3. '
  4. ' Author    : Mike Cartwright, Tamara Cartwright (updated to 4.0 interface)
  5. ' Date        : 01/08/96, 03/08/97
  6. 'Constants
  7. Global Const GK_GRAPHIC = 11
  8. Global Const NULL         = 0
  9.  
  10. ' File I/O constants
  11. Global Const EOFILE     = -1
  12.  
  13. Sub Main ()
  14.     Dim FileName As String
  15.     Dim LineBuffer As String
  16.     Dim g As Long
  17.     Dim v As Long
  18.     Dim vi As Long
  19.     Dim fh As Long
  20.     Dim dActive As Long
  21.     Dim x As Double
  22.     Dim y As Double
  23.     Dim z As Double
  24.     Dim Part As String 
  25.     Dim PartX As String
  26.     Dim PartY As String
  27.     Dim PartZ As String
  28.     Dim Delim As String
  29.     Dim Pos As Integer
  30.     
  31.     ' Check for valid drawing
  32.     dActive    = TCWDrawingActive ()
  33.     If dActive = NULL Then
  34.        MsgBox "Program requires active drawing."
  35.        ' Terminate the program
  36.        Stop
  37.     End If
  38.     
  39.     vi = 0
  40.     g = NULL
  41.     
  42.     ' Delimiter for record fields in the input text file
  43.     Delim = Chr$(9)
  44.      
  45.     ' Get the name of the input file
  46.     FileName = InputBox("Type in the filename to import from")
  47.     
  48.     If (FileName <> "") Then        
  49.         
  50.         ' Open input text file.
  51.         fh = TCWOpenInput(FileName)
  52.         
  53.         ' Read lines from the input file and brake them down
  54.         ' to numeric values
  55.         
  56.         vi = 0 
  57.         while (TCWReadInput(fh, LineBuffer) <> EOFILE)
  58.             ' Graphic separator
  59.             if  LineBuffer = "" Then
  60.                 if ((g <> NULL) And (vi > 0)) Then
  61.                      TCWGraphicAppend NULL, g 
  62.                      TCWGraphicDraw g, 0           
  63.                      g = NULL
  64.                 End If 
  65.                 vi = 0
  66.             End If
  67.             if  (LineBuffer <> "") Then 
  68.                 ' find the first delimiters position in Line
  69.                 Pos = InStr(1, LineBuffer, Delim, 0)
  70.                 ' Let's remove the index part
  71.                 Part = Right$(LineBuffer, Len(LineBuffer) - Pos)
  72.                 ' Let's find position of the second delimiter                        
  73.                 Pos = InStr(1, Part, Delim, 0)
  74.                 ' Let's extract the frist number
  75.                 PartX = Left$(Part, Pos-1) 
  76.                 x = Val(PartX)
  77.                 Part = Right$(Part, Len(Part) - Pos)
  78.                 ' Let's find the position of the third delimiter
  79.                 Pos = InStr(1, Part, Delim, 0)
  80.                 PartY = Left$(Part, Pos-1)
  81.                 y = Val(PartY)
  82.                 PartZ = Right$(Part, Len(Part) - Pos)
  83.                 z = Val(PartZ)
  84.                 ' Add vertex (x, y, z) to the graphic g    
  85.                 If vi = 0 Then
  86.                    g = TCWGraphicCreate(GK_GRAPHIC, "")
  87.                 End If
  88.                 If g <> NULL Then                   
  89.                    TCWGraphicXYZAdd g, x, y, z 
  90.                 End If   
  91.                 vi = vi + 1 
  92.               End If
  93.         wend
  94.         
  95.         ' If anything is left out we need to add to the drawing
  96.         ' now.
  97.         if ((g <> NULL) And (vi > 0)) Then
  98.             TCWGraphicAppend NULL, g
  99.         End If
  100.  
  101.         TCWCloseInput fh
  102.  
  103.   
  104.     End If
  105.  
  106. End Sub
  107.