Append File I/O 

Declaration:

PROCEDURE   Append
( fileName:STRING ) ;

Description:

Procedure Append opens the specified file for writing and appends the data to the end of the file. Existing data in the file is NOT overwritten.

If the filename includes a fully qualified path, the path has to use the appropriate notation for the local operating system:
Macintosh HD:Applications:Vectorworks:Plug-Ins:Data:Notes.txt C:\Program Files\Vectorworks\Plug-Ins\Data\Notes.txt If the filename includes a path relative to the location of the Vectorworks executable, the subfolder delimiters have to be backslashes:
Plug-Ins\Data\Notes.txt If the filename does not include a path, the file is assumed to exist in the same folder as the Vectorworks executable.

Parameters:

fileName Name of file to open for writing.

Example:

PROCEDURE Example;
VAR
   fileName :STRING; 
   major, minor, maintenance, platform :INTEGER;
BEGIN
   GetVersion(major, minor, maintenance, platform);
   IF platform = 1 THEN BEGIN
      fileName := 'Macintosh HD:Example.txt';
   END ELSE BEGIN
      fileName := 'C:\Example.txt';
   END;
   Append(fileName);
   WriteLn('example text');
   Close(fileName);
END;
RUN(Example);



  Close File I/O 

Declaration:

PROCEDURE   Close
( fileName:STRING ) ;

Description:

Procedure Close closes the specified text file.

If the filename includes a fully qualified path, the path has to use the appropriate notation for the local operating system:
Macintosh HD:Applications:Vectorworks:Plug-Ins:Data:Notes.txt C:\Program Files\Vectorworks\Plug-Ins\Data\Notes.txt If the filename includes a path relative to the location of the Vectorworks executable, the subfolder delimiters have to be backslashes:
Plug-Ins\Data\Notes.txt If the filename does not include a path, the file is assumed to exist in the same folder as the Vectorworks executable.

Parameters:

fileName Name of file to close.

Example:

BEGIN
     Open('MyData');
     WHILE NOT EOF('MyData') DO
          ReadLn(a,b,c,d);
     Close('MyData');
END;




  EOF File I/O 

Declaration:

FUNCTION   EOF
( fileName:STRING ) :BOOLEAN ;

Description:

Function EOF returns TRUE if the file pointer of an open text file has reached the end of the file (EOF marker). Function EOF is used with Procedures Read and ReadLn to ensure proper file reading and closure. Parameter fileName specifies a text file which is open for reading or writing.

If the filename includes a fully qualified path, the path has to use the appropriate notation for the local operating system:
Macintosh HD:Applications:Vectorworks:Plug-Ins:Data:Notes.txt C:\Program Files\Vectorworks\Plug-Ins\Data\Notes.txt If the filename includes a path relative to the location of the Vectorworks executable, the subfolder delimiters have to be backslashes:
Plug-Ins\Data\Notes.txt If the filename does not include a path, the file is assumed to exist in the same folder as the Vectorworks executable.

Parameters:

fileName Name of file.

Example:

BEGIN
     Open('MyData');
     WHILE NOT EOF('MyData') DO
          ReadLn(a,b,c,d);
     Close('MyData');
END;



  EOLN File I/O 

Declaration:

FUNCTION   EOLN
( fileName:STRING ) :BOOLEAN ;

Description:

Function EOLN returns TRUE if the file pointer of an open text file has reached a carriage return within the file. Parameter fileName specifies a text file which is open for reading or writing.

Parameters:

fileName Name of file.

Example:

BEGIN
     Open('MyData');
     WHILE NOT EOLN('MyData') DO
           Read(a,b,c,d);
      Close('MyData');
END;



  FindFileInPluginFolder File I/O 

Declaration:

FUNCTION   FindFileInPluginFolder
(   filename :STRING;
  VAR  path :STRING
) :BOOLEAN ;

Description:

Searches for filename in all plug-in folders. Returns TRUE if the file is found, FALSE otherwise. If found, the result is returned in the path parameter.

Example:

PROCEDURE Example;
VAR
	filename, path :STRING;
BEGIN
	filename := 'Callout.vso';
	IF FindFileInPluginFolder(filename, path) 
		THEN AlrtDialog(path)
		ELSE AlrtDialog('Could not find file.');
END;
RUN(Example);



  GetFile File I/O 

Declaration:

PROCEDURE   GetFile
VAR fileName:STRING ) ;

Description:

Procedure GetFile displays a standard file dialog which requests the user to select a text document.

It is advisable to call DidCancel after using this procedure and check that the user did not cancel the file selection process.

Parameters:

fileName Returns name of selected file.

Example:

GetFile(fileName);
IF NOT DidCancel THEN BEGIN
     Read(a,b,c);
     Close(fileName);
END;
{Select a file for reading via a file open dialog}



  GetFileInfo File I/O 

Declaration:

PROCEDURE   GetFileInfo
(   filename :STRING;
  VAR  fullReadPath :STRING;
  VAR  fullWritePath :STRING;
  VAR  readFileExists :BOOLEAN;
  VAR  writeFileExists :BOOLEAN;
  VAR  locked :BOOLEAN;
  VAR  hasReadPermission :BOOLEAN;
  VAR  hasWritePermission :BOOLEAN;
  VAR  hasFolderPermission :BOOLEAN
) ;

Description:

This function gets the attributes of a file.

Example:

PROCEDURE Example;
VAR
   fileName :STRING;
   fullReadPath, fullWritePath :STRING;
   readFileExists, writeFileExists, locked, hasReadPermission, hasWritePermission, hasFolderPermission :BOOLEAN;
BEGIN
   fileName := Concat(GetFolderPath(1), 'ADINIT.DAT');
   GetFileInfo(fileName, fullReadPath, fullWritePath, readFileExists, writeFileExists, locked, hasReadPermission, hasWritePermission, hasFolderPermission);
   ReWrite('Output.txt');
   WriteLn('fileName:            ', fileName);
   WriteLn('fullReadPath:        ', fullReadPath);
   WriteLn('fullWritePath:       ', fullWritePath);
   WriteLn('readFileExists:      ', readFileExists);
   WriteLn('writeFileExists:     ', writeFileExists);
   WriteLn('locked:              ', locked);
   WriteLn('hasReadPermission:   ', hasReadPermission);
   WriteLn('hasWritePermission:  ', hasWritePermission);
   WriteLn('hasFolderPermission: ', hasFolderPermission);
   Close('Output.txt');
END;
RUN(Example);



  GetFolderPath File I/O 

Declaration:

FUNCTION   GetFolderPath
( whichPath:INTEGER ) :STRING ;

Description:

Function GetFolderPath returns the full path to the requested folder independent of localized folder names.

Table - Folder Path Selectors

Note that use of the negative values of these constants can be used to get the user-based folder path. The positive values are for application-based paths, which should not be used for writing.

Folder Name Constant
Application 1
Plug-Ins 2
Workspaces 4
Templates 7
Standards 8
Help 9
Dictionaries 10
User App Data 12
Libraries 13
Defaults 14
Settings 15
PDF Resources 18
Plug-In Data 20
Plug-In Includes 21
Plug-In interfaces 22
Favorites 23
Renderworks - Textures 100
Cabinet - Handles 101
Door - Hardware 102
Attributes - Gradients 103
Hardscape - Hatches 104
Attributes - Hatches 105
Attributes - Image Fills 106
Plants 107
Toilet Stall - Fixtures 108
RenderWorks - Backgrounds 109
Seating Layout - Symbols 110
Tile - Symbols 111
Human Figure - Textures 112
Walls 113
Stairs 114
Drawing Border - Title Blocks 115
Section - Markers 116
Repetitive Unit 117
Door - Custom Leaves 118
Lighting Instrument - Gobos 119
Reports~Schedules 120
Lighting Instrument - Symbols 121
Plants - Hatches 124
Repetivite Unit: Flooring/Decking 125
Repetivite Unit: Framing 126
Repetivite Unit: Masonry Units 127
Repetivite Unit: Miscellaneous 128
Repetivite Unit: Roofing 129
Repetivite Unit: Siding 130
Walls - Hatches 131
Walls - Textures 132
Window - Custom Shutters 133
Sketch Styles 134
Plant Database 135
VW Plants 136
Color Palettes 137
Framing Member - Custom Profile 138
Spaces - Occupant Organization Name Lists 140
Spaces - Space Name Lists and Libraries 141
Structural Shapes 142


Parameters:

whichPath Path constant.

Example:

PROCEDURE Example;
BEGIN
	AlrtDialog(GetFolderPath(12));
END;
RUN(Example);



  GetLastFileErr File I/O 

Declaration:

FUNCTION   GetLastFileErr
:INTEGER ;

Description:

Returns an error code indicating whether an error occured during a file operation.

This function should be called after file I/O calls such as Open() or Rewrite().

Example:

UseDefaultFileErrorHandling(FALSE);
Open(Concat(pathName, fileName));
errorCode := GetLastFileErr;
IF errorCode <> 0 THEN
	CASE errorCode OF
		 2: AlrtDialog(Concat('The file "', fileName, '" cannot be processed because the hard drive is full.'));
		 4: AlrtDialog(Concat('End of file "',   fileName, '" reached prematurely.'));
		 5: AlrtDialog(Concat('The file "', fileName, '" is locked.'));
		 6: AlrtDialog(Concat('The file "', fileName, '" not found.'));
		10: AlrtDialog(Concat('The file "', fileName, '" currently in use by another program.'));
		13: AlrtDialog(Concat('The file path "', pathName, '" does not exist.'));
		OTHERWISE AlrtDialog(Concat('The file "',fileName,'" has encountered an undetermined error.'));
	END;



  Open File I/O 

Declaration:

PROCEDURE   Open
( fileName:STRING ) ;

Description:

Procedure Open opens a ASCII text file for reading.

Remember to use Close when you are finished reading or writing to a file.

If the filename includes a fully qualified path, the path has to use the appropriate notation for the local operating system:
Macintosh HD:Applications:Vectorworks:Plug-Ins:Data:Notes.txt C:\Program Files\Vectorworks\Plug-Ins\Data\Notes.txt If the filename includes a path relative to the location of the Vectorworks executable, the subfolder delimiters have to be backslashes:
Plug-Ins\Data\Notes.txt If the filename does not include a path, the file is assumed to exist in the same folder as the Vectorworks executable.

Parameters:

fileName Name of file to open.

Example:

PROCEDURE Example;
VAR
	fileName :STRING;
BEGIN
	UseDefaultFileErrorHandling(FALSE);
	fileName := 'Plug-Ins\Common\Data\Callout Prefs.txt';
	Open(fileName);
	AlrtDialog(Concat(GetLastFileErr));
	Close(fileName);
END;
RUN(Example);



  PutFile File I/O 

Declaration:

PROCEDURE   PutFile
(   commentStr :STRING;
    defaultStr :STRING;
  VAR  fileName :STRING
) ;

Description:

Procedure PutFile displays a standard file dialog which requests the user to select or create a text file for output.

Parameters:

commentStr User prompt string for dialog.
defaultStr Default file name string.
fileName Returns name of the user selected file.

Example:

PROCEDURE PutFileExample;
VAR
	fileName :STRING;
BEGIN
	PutFile('Select the file to create:', 'New File.txt', fileName);
	Message(fileName);
	IF NOT DidCancel THEN BEGIN
		WriteLn('some text');
		Close(fileName);
	END;
END;
RUN(PutFileExample);

See Also:

GetLastFileErr   Rewrite   GetFile   Open   Close  



  Read File I/O 

Declaration:

PROCEDURE   Read
( VAR  z :ANY
) ;

Description:

Procedure Read will read data from a currently open text file. The variable length parameter list returns the read data in the specified parameters.Supported data types include INTEGER, REAL, LONGINT, CHAR or STRING.

Non STRING data values must be separated by a tab or space to be correctly read into variables. If the procedure encounters an EOF(end-of-file) marker, an error is generated. Read does not position the file position pointer to the beginning of a new line after the procedure is called.

Read will detect tabs as delimiters, allowing multiple string values to be assigned to variables.



  ReadLn File I/O 

Declaration:

PROCEDURE   ReadLn
( VAR  z :ANY
) ;

Description:

Procedure ReadLn will read data from a currently open text file. The variable length parameter list returns the read data in the specified parameters.

Supported data types include INTEGER, REAL, LONGINT, CHAR or STRING. If the procedure encounters an EOF(end-of-file) marker, an error is generated. ReadLn positions the file position pointer to the beginning of a new line after the procedure is called.

ReadLn will detect tabs as delimiters, allowing multiple string values to be assigned to variables.

Example:

PROCEDURE Example;
VAR
   fileName, value1, value2, value3 :STRING; 
   major, minor, maintenance, platform :INTEGER;
BEGIN
   GetVersion(major, minor, maintenance, platform);
   IF platform = 1 THEN BEGIN
      fileName := '/Example.txt';
   END ELSE BEGIN
      fileName := 'C:\Example.txt';
   END;
   Open(fileName);
   ReadLn(value1, value2, value3);
   Close(fileName);
   AlrtDialog(lineOfText);
END;
RUN(Example);



  Rewrite File I/O 

Declaration:

PROCEDURE   Rewrite
( fileName:STRING ) ;

Description:

Procedure Rewrite creates a new ASCII text file or opens an existing one prior to writing data to the file. If the file exists, new data written to the file will overwrite any data currently within the file.

If the filename includes a fully qualified path, the path has to use the appropriate notation for the local operating system:
Macintosh HD:Applications:Vectorworks:Plug-Ins:Data:Notes.txt C:\Program Files\Vectorworks\Plug-Ins\Data\Notes.txt If the filename includes a path relative to the location of the Vectorworks executable, the subfolder delimiters have to be backslashes:
Plug-Ins\Data\Notes.txt If the filename does not include a path, the file is assumed to exist in the same folder as the Vectorworks executable.

Parameters:

fileName Name of file.

Example:

PROCEDURE Example;
VAR
   fileName :STRING; 
   major, minor, maintenance, platform :INTEGER;
BEGIN
   GetVersion(major, minor, maintenance, platform);
   IF platform = 1 THEN BEGIN
      fileName := '/Example.txt';
   END ELSE BEGIN
      fileName := 'C:\Example.txt';
   END;
   ReWrite(fileName);
   WriteLn('example text');
   Close(fileName);
END;
RUN(Example);



  Space File I/O 

Declaration:

PROCEDURE   Space
( n:INTEGER ) ;

Description:

Procedure Space writes a space to the current output file.

Parameters:

n Number of spaces.

Example:

Space(5);
{write 5 spaces to the output file}



  StdRead File I/O 

Declaration:

PROCEDURE   StdRead
( VAR  z :ANY
) ;

Description:

Procedure StdRead will read data from a currently open text file. The variable length parameter list returns the read data in the specified parameters.

Supported data types include INTEGER, REAL, LONGINT, CHAR or STRING. Non STRING data values must be separated by a tab or space to be correctly read into variables. If the procedure encounters an EOF(end-of-file) marker, an error is generated. StdRead does not position the file position pointer to the beginning of a new line after the procedure is called.

StdRead reads data according to the Pascal language standard. This differs from the Read procedure found in VectorScript primarily when reading STRING data. StdRead will read all characters, including tabs and spaces, as a single string value. Read will detect tabs as delimiters, allowing multiple string values to be assigned to variables.

Example:

GetFile(fName);
IF NOT DidCancel THEN BEGIN
Open(fName);
StdRead(partID,partName);
END;



  StdReadLn File I/O 

Declaration:

PROCEDURE   StdReadLn
( VAR  z :ANY
) ;

Description:

Procedure StdReadLn will read data from a currently open text file. The variable length parameter list returns the read data in the specified parameters.

Supported data types include INTEGER, REAL, LONGINT, CHAR or STRING. Non STRING data values must be separated by a tab or space to be correctly read into variables. If the procedure encounters an EOF(end-of-file) marker, an error is generated. StdReadLn positions the file position pointer to the beginning of a new line after the procedure is called.

StdReadLn reads data according to the Pascal language standard. This differs from the ReadLn procedure found in VectorScript primarily when reading STRING data. StdReadLn will read all characters, including tabs and spaces, as a single string value. ReadLn will detect tabs as delimiters, allowing multiple string values to be assigned to variables.

Example:

GetFile(fName);
IF NOT DidCancel THEN BEGIN
Open(fName);
StdReadLn(partID,partName);
END;



  Tab File I/O 

Declaration:

PROCEDURE   Tab
( n:INTEGER ) ;

Description:

Procedure Tab writes a tab character to the current output file.

Parameters:

n Number of tab characters to be written to file.

Example:

Tab(2);
{writes two tabs to the output file}



  UseDefaultFileErrorHandling File I/O 

Declaration:

PROCEDURE   UseDefaultFileErrorHandling
( enable:BOOLEAN ) ;

Description:

Enables or disables file I/O alert dialogs.

Use this function with GetLastFileErr() to implement custom error handling for file operations.

Parameters:

enable Status of file error dialog usage.

See Also:

GetLastFileErr  



  Write File I/O 

Declaration:

PROCEDURE   Write
(   z :ANY
) ;

Description:

Procedure Write outputs the specified data to an ASCII text file. The variable length parameter list specifies the data to be written to the file.

Parameters may be any valid data type, and data types may be mixed in a single call to the procedure. Write leaves the file pointer positioned at the end of the last data value written to the file; any data subsequently written to the file will be appended to the end of this value.

See the VectorScript Language Guide for details on formatting values using WriteLn.

Example:

Write(Value1);



  WriteLn File I/O 

Declaration:

PROCEDURE   WriteLn
(   z :ANY
) ;

Description:

Procedure WriteLn outputs the specified data to an ASCII text file. The variable length parameter list specifies the data to be written to the file.

Parameters may be any valid data type, and data types may be mixed in a single call to the procedure. A carriage return is appended to the end of the line of data, so that the file pointer is at the beginning of a new line in the file, and any data written to the file after the procedure call will be on the new line.

See the VectorScript Language Guide for details on formatting values using WriteLn.

Example:

PROCEDURE Example;
CONST
	Vendor = 'ACME';
	Price = 123.45;
	Tax = 1.07;
BEGIN
	ReWrite('Output.txt');
	WriteLn('Mfr/Cost: ', Vendor, '/', Price + Tax);
	Close('Output.txt');
END;
RUN(Example);

See Also:

WriteLnMac  



  WriteLnMac File I/O 

Declaration:

PROCEDURE   WriteLnMac
(   z :ANY
) ;

Description:

Writes a line of data to a text file using Macintosh character encoding for extended ASCII characters (128-255). This allows extended character data to be properly read and displayed by Vectorworks on Windows systems (Vectorworks by default uses Macintosh encoding for extended character values).

The line of data written to file is terminated with a return character combination appropriate for the platform on which the file is being written.

Example:

PROCEDURE Example;
CONST
	Vendor = 'ACME';
	Price = 123.45;
	Tax = 1.07;
BEGIN
	Open('Output.txt');
	WriteLnMac('Mfr/Cost: ', Vendor, '/', Price + Tax);
	Close('Output.txt');
END;
RUN(Example);

See Also:

WriteLn  



  WriteMac File I/O 

Declaration:

PROCEDURE   WriteMac
(   z :ANY
) ;

Description:

Outputs the specified data to an ASCII text file. The variable length parameter list specifies the data to be written to the file.

Parameters may be any valid data type, and data types may be mixed in a single call to the procedure. WriteMac leaves the file pointer positioned at the end of the last data value written to the file; any data subsequently written to the file will be appended to the end of this value.

See the VectorScript Language Guide for details on formatting values using WriteLn.

Example:

WriteMac(Value1);