home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2002 March
/
PCWMAR02.iso
/
software
/
turbocad
/
V4
/
tcw.z
/
Impoint.bas
< prev
next >
Wrap
BASIC Source File
|
1997-10-28
|
3KB
|
115 lines
' This sample program is an example of how to do custom file IO from TurboCAD. We will build graphics from the vertices in the table.
'
' Author : Mike Cartwright, Tamara Cartwright (updated to 4.0 interface)
' Date : 01/08/96, 03/08/97
'
'Constants
Global Const GK_GRAPHIC = 11
' File I/O constants
Global Const EOFILE = -1
Sub Main ()
Dim FileName As String
Dim LineBuffer As String
Dim Ertxt As String
Dim g As Long
Dim v As Long
Dim vi As Long
Dim fh As Long
Dim dActive As Long
Dim x As Double
Dim y As Double
Dim z As Double
Dim Part As String
Dim PartX As String
Dim PartY As String
Dim PartZ As String
Dim Delim As String
Dim Pos As Integer
' Check for valid drawing
dActive = TCWDrawingActive ()
If dActive = 0 Then
MsgBox "Program requires active drawing."
' Terminate the program
Stop
End If
vi = 0
g = 0
' Delimiter for record fields in the input text file
Delim = Chr$(9)
' Get the name of the input file
FileName = InputBox("Type in the filename to import from","TurboCAD")
If (FileName <> "") Then
' Open input text file.
fh = TCWOpenInput(FileName)
if (fh=0) Then
result=TCWLastErrorGet(ertxt)
MsgBox ertxt
Stop
End If
' Read lines from the input file and brake them down
' to numeric values
vi = 0
while (TCWReadInput(fh, LineBuffer) <> EOFILE)
' Graphic separator
if LineBuffer = "" Then
if ((g <> 0) And (vi > 0)) Then
TCWGraphicAppend 0, g
TCWGraphicDraw g, 0
g = 0
End If
vi = 0
End If
if (LineBuffer <> "") Then
' find the first delimiters position in Line
Pos = InStr(1, LineBuffer, Delim, 0)
' Let's remove the index part
Part = Right$(LineBuffer, Len(LineBuffer) - Pos)
' Let's find position of the second delimiter
Pos = InStr(1, Part, Delim, 0)
' Let's extract the frist number
PartX = Left$(Part, Pos-1)
x = Val(PartX)
Part = Right$(Part, Len(Part) - Pos)
' Let's find the position of the third delimiter
Pos = InStr(1, Part, Delim, 0)
PartY = Left$(Part, Pos-1)
y = Val(PartY)
PartZ = Right$(Part, Len(Part) - Pos)
z = Val(PartZ)
' Add vertex (x, y, z) to the graphic g
If vi = 0 Then
g = TCWGraphicCreate(GK_GRAPHIC, "")
End If
If g <> 0 Then
TCWGraphicXYZAdd g, x, y, z
End If
vi = vi + 1
End If
wend
' If anything is left out we need to add to the drawing
' now.
if ((g <> 0) And (vi > 0)) Then
TCWGraphicAppend 0, g
End If
TCWCloseInput fh
MsgBox "Finished"
Stop
End If
MsgBox "Script was cancelled."
End Sub