CabMasterPro User Guide
In This Topic
    File Functions
    In This Topic


    There are a few general rules about functions that access files:



    AppendLine [Action Only]
    Adds a line of text to the end of the specified file
    Syntax AppendLine (file, text)
    Inputs File is what to add text to the end of
    Notes A newline character is automatically added to the end of text
    Examples AppendLine ("c:\drawing.log", "This was written using the appendline function")
    See Also WriteLine

    BrowseFile [Action Only]
    Browse for File with a file dialog
    Syntax BrowseFile(folder,filename,exts[[,relfolder],initfolder]) where exts is the list of extensions to browse for, eg "*.bmp|*.jpg|*.png" or ".csv;.xls;.blah"
    Inputs Puts up a file dialog for user selection.
    Outputs Returns yes and sets variables folder,filename provided user presses OK after selecting a file during browse. The browsing starts in initfolder (default TableFolder) and the value returned in the variable specified by folder is a path relative to relfolder (default TableFolder)
    Notes The square brackets indicate the optional 3rd and 4th params for the relative base folder and the initial browsing folder.Extensions list can be comma pipe or semicolon separated and * is optional as in examples above.

    • browsefile(folder,filename,exts) - starts in TableFolder and set variables folder (relative to initfolder) and filename
    • browsefile(folder,filename,exts,initfolder) - starts in initfolder and set variables folder (relative to initfolder) and filename
    • browsefile(folder,filename,exts,relfolder,initfolder) - starts in initfolder and sets variables folder,filename (relative to relfolder)browsefile("myfoldervar","myfilevar",LibraryFolder,TableFolder)

      This starts browsing in the TableFolder but when the user selects a file, the path returned is relative to the LibraryFolder.
    See Also BrowseDXF, BrowseImage, BrowseModel

    Call
    Reads a formula from the specified file and evaluates it
    Syntax Call (file)
    Inputs File is a text file which has CabMasterPro formula in it
    Outputs Whatever the called formula returns
    Notes This function effectively reads the entire contents of the file and replaces the actual Call function with those contents. If file does not include a formula, the program will try to run it as one anyway and give errors as expected. When file does not exist, its content is assumed to be a blank string
    Examples Call ("aVeryLongFormula.txt")

    Export [Action Only]
    Saves data from the current drawing to the specified file
    Syntax Export (filename, full)
    Inputs Filename is the name of the tab file (tab-separated values) to export to, which will be overwritten if it already exists. Full is an optional Yes/No parameter (the default is No) which determines whether a Full or Minimal export will be done
    Notes If full is True, then this function is exactly the same as using the Export to ASCII - Full command on the File menu, otherwise it is the same as Export to ASCII - Minimal.
    The default location and extension for tab files is the Library_Folder and ".tab" respectively
    Examples Export ("exportedfile")
    See Also Merge

    ExportData [Action Only]
    Creates a set of tab files (tab-delimited values) for reporting purposes and external applications
    Syntax ExportData ( )
    Inputs None (you still need to use the empty brackets)
    Notes The tab files are created in the default location, which is the root of your hard drive (required by Crystal Reports)
    Examples ExportData ( )
    See Also Export

    ExportDataMin [Action Only]
    Creates a set of tab files (tab-delimited values) for reporting purposes and external applications
    Syntax ExportDataMin (reportfileforpics)
    Inputs Exports tab data (min no components) and picture date for reports.

    If you use empty brackets i.e. ExportDataMin() then exports tab data min (no component details) for reports, qmif, etc (no picture data)
    See Also Export, ExportData

    ExportDoc3D [Action Only]
    Prompts to create a 3D export file for whole drawing
    Syntax ExportDoc3D ( )
    Inputs None (you still need to use the empty brackets)
    See Also Export, ExportData, ExportItem3D

    ExportItem3D [Action Only]
    Prompts to create a 3D export file for current item in the Preview Pane
    Syntax ExportDoc3D ( )
    Inputs None (you still need to use the empty brackets)
    See Also Export, ExportData, ExportDoc3D

    ExportValues [Action Only]
    Generate user configurable export file
    Syntax ExportValues(outfile,filterfile,separator,append)
    Inputs outfile: Name of the file to create or append to. Default folder is the LibraryFolder, default extension is .tab
    filterfile: Name of a file to be read to specify the formulas to be evaluated to get the fields of the out file. The filterfile can have tab or newline separated formulas. The number of formulas found determines the number of values created.
    separator [default is tab]: Values created by evaluating the filterfile formulas are concatenated together with a separator as specified here. One could specify ENDL as a separator to create a column of values one per line, or use the default TAB to create a tab separated line of values.
    append [default is No]: A yes/no value says whether to append to any existing outfile. Default is to overwrite it.
    Notes Note: if a header line is also required in the file, this can be output either using WriteLine or ExportValues (with constant strings). The data can then be appended to this file using the append option in ExportValues.
    Examples ExportValues("somefile.txt","MyFormulaList.txt")
    See Also _OnLoadAction, _OnSaveAction

    FileExists
    Indicates whether the specified file already exists or not
    Syntax FileExists (filename)
    Inputs Filename is the name of the file that you want to check exists
    Outputs Returns 1 if the file exists, or 0 otherwise
    Notes FileExists will also detect if directories exist, as long as there is no trailing slash.
    Wildcard characters may be used: * (asterisk) matches any number of characters, and ? (question mark) matches any single character.
    To detect if a drive exists on a machine, use something like FileExists("e:\*"), which actually checks if any files exist on that drive. If the asterisk is left off the function will return 0.
    Examples FileExists ("c:\*") = 1
    FileExists ("c:\windows\") = 0
    FileExists ("*.qlt")
    FileExists ("..\??-03-2000.log")

    FileLen
    Returns the size of a specified file in bytes
    Syntax FileLen (filename)
    Inputs Filename is the file that you want the size of
    Notes If filename does not exist or is a directory, 0 is returned
    Examples FileLen ("c:\io.sys") = 222390
    See Also FileExists

    ListFileNames
    Returns the names of files in wildspec folder listed and put into string
    Syntax ListFileNames (wildspec,sep)
    Inputs wildspec string with pipe separator.
    sep string with user specified separator.
    Notes The results are basically a copy of File Names on the Define Questions page.

    ListFolderNames
    Returns the names of subfolders in wildspec folder listed and put into string
    Syntax ListFolderNames (wildspec,sep)
    Inputs wildspec string with pipe separator.
    sep string with user specified separator.
    Notes The results are basically a copy of Folder Names on the Define Questions page.

    Merge [Action Only]
    Loads data from the specified file and merges it with the current drawing
    Syntax Merge (filename)
    Inputs Filename is the name of the tab file (tab-separated values) to merge
    Notes This function is exactly the same as using the Merge from ASCII command on the File menu.
    The default location and extension for tab files is the Library_Folder and ".tab" respectively
    Examples Merge ("exportedfile")
    See Also Export

    ReadAndIncrement
    Reads a whole number from a file, increments that number and writes the result back to the file
    Syntax ReadAndIncrement (file)
    Inputs File is what the number is read from and written to
    Outputs The original number read from file is returned, not the incremented one
    Notes If a file has a number in it but is read-only, the result is still 0.
    If the contents of file does not start with a number, it is assumed to be zero and the new result is written over the file, completely destroying any contents of the file.
    ReadAndIncrement uses file locking which means that only one copy of CabMasterPro can access the file at once. This is useful for network environments, where each workstation running CabMasterPro can obtain a unique number by reading it from a shared file. A typical use for this is assigning job numbers to drawings, where it is critical that each number is only used once. File locking makes sure that two programs trying to read the file at the same time will get two different numbers and will not corrupt the file
    Examples ReadAndIncrement ("\\server\CabMasterPro\nextJobNumber.txt")

    ReadFile
    Returns the entire file specified
    Syntax ReadFile (file, separator)
    Inputs File is where the line is to be read from, separator is the character to replace endlines with. separator is optional, defaulting to the constant ENDL.
    Notes Lines are considered to end with either a carriage return and linefeed or just a newline.
    Note From File on the Define Questions page uses ReadFile with a pipe separator.
    Examples ReadFile ("somefile.txt") will return the contents of the file.
    ReadFile("somefile.txt","|") will return the file with new lines replaced by |'s
    See Also ReadLine

    ReadLine
    Returns a specific line of text read from a file
    Syntax ReadLine (file, num)
    Inputs File is where the line is to be read from, and num is the line number to read
    Notes Lines are considered to end with either a carriage return and linefeed or just a newline
    Examples ReadLine ("somefile.txt", 17)
    See Also WriteLine, ReadFile

    SaveDrawing [Action Only]
    Saves the current drawing to disk, optionally with a new name
    Syntax SaveDrawing (filename, setTitle)
    Inputs Filename is optional, and is the name of the file to save to. setTitle is an optional Yes/No parameter (default is Yes), and will update the drawing title to filename if Yes
    Notes If filename is omitted, SaveDrawing acts exactly like the Save command on the File menu. It will prompt the user for a filename if the drawing has not been saved before.
    If filename is provided but blank, SaveDrawing behaves the same as the Save As command (prompting the user for a new name), otherwise it saves to the specified file.
    If setTitle is false (or No) then the drawing title will not change... this is useful for auto-saves or saving a copy of the drawing.
    The default location and extension for drawings is Data_Folder and ".qid" respectively
    Examples SaveDrawing ( ) (note that you still need the empty brackets)
    SaveDrawing ("newname")
    SaveDrawing ("", false)

    WriteLine [Action Only]
    Creates a new file and writes the specified string to that file
    Syntax WriteLine (file, text)
    Inputs File is what you want text to be written to
    Notes If file already exists, it is overwritten so any data it may have contained is completely destroyed. File is the name of the file to write, and can be a full path (folder and filename) to a folder that does not yet exist. If necessary the folder is created, even if several levels of subfolders need creation. The default folder if not specified is the LibraryFolder. The default extension if not specified is ".txt".
    Examples WriteLine ("somefile.txt", "New Content")
    See Also ReadLine, AppendLine