VS:GetFileN: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
m (1 revision)
m (fix chars)
 
(10 intermediate revisions by the same user not shown)
Line 5: Line 5:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<desc>
<desc>
Prompts for the selection of a file. Returns the fully qualified pathname of the selected file. Returns false if the user clicked the Cancel button.
Returns the fully-qualified pathname of the selected file.</desc>
 
Valid mask values include:
*.ext (where ext is the actual extension, such as *.txt)
TEXT (Mac text file)
MCD (Mac VectorWorks file)
**** (all files, either platform)
</desc>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<def>
<def>
<funcDef lang="vs">
<funcDef lang="vs">
FUNCTION GetFileN(title :STRING; defaultFolder :STRING; mask :STRING; VAR fileName :STRING) :BOOLEAN;
FUNCTION GetFileN(title:STRING; defaultFolder:STRING; mask:STRING; VAR fileName:STRING) : BOOLEAN;
</funcDef>
</funcDef>
<funcDef lang="py">
<funcDef lang="py">
Line 46: Line 39:
fileName
fileName
STRING
STRING
Output parameter.
 
</line>
</line>
</lineList>
</lineList>
</params>
</params>


-----------------------------------------------------------------------------------------------------------
<remark>
([[User:CBM-c-|_c_]] 2017.01.22): Prompts for selection of a file of type "mask". The parameter "defaultFolder", if not empty, must be a posix path (with slashes). A HFS path (with colons) to the default folders can be obtained with [[VS:GetFolderPath]], you will need to use [[VS:ConvertHSF2PosixPath]] for converting it into posix for older Vectorworks versions. Assigns the found path to var "fileName". Mask is case sensitive. The returned path is posix.
* mask = 'vwx' allows selection of files of type .vwx
* mask = ′′ allows selection of any kind of files
* mask = 'vwx;txt' allows range of selection (from Pat Stanford on the VS list)
The GetFileN uses the SDK interface IFileChooserDialog
[[VCOM:Working with File/Folder Choose Dialogs]]
the ‘mask’ parameter goes as input to
fileChooser->SetDefaultExtension(mask);


-----------------------------------------------------------------------------------------------------------
[[VCOM:VectorWorks:Filing:IFileChooserDialog::SetDefaultExtension]]
<return>
</return>


-----------------------------------------------------------------------------------------------------------
(MaKro, 2016.10.18):
<remark>
:Mask format change in VW2016 on a Windows 7 machine
On OSX, the defaultFolder has to be just the folder, but on OS9 or on Windows, it can include a filename. Either way, if a filename is present, the file does not get selected in the dialog, so don't bother casing this for platforms -- just make sure that defaultFolder just has the name of a folder.
:Python mask example: '*.txt' if VW-Version < 2016 else 'txt'


On OSX, GetFileN expects a fully qualified name, using foreslashes, such as '/Applications/VectorWorks'.
</remark>
</remark>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<sample>
<sample>
==== VectorScript ====
<code lang="pas">
<code lang="pas">
PROCEDURE Example;
PROCEDURE Example;
VAR
VAR
  major, minor, maintenance, platform :INTEGER;
    fileName, title : STRING;  
  title, defaultFolder, mask, fileName: STRING;
    defaultFolder : STRING;
    mask : STRING;  
BEGIN
BEGIN
  title := 'Select something...';
    title := 'Select the object library file...';
  GetVersion(major, minor, maintenance, platform);
    defaultFolder := '';
  IF platform = 1 THEN BEGIN
    mask := 'vwx';
      defaultFolder := '/Applications';
    pathName := 'Drafting Tools.vwx';
  END ELSE BEGIN
 
      defaultFolder := 'C:\Program Files';
    IF GetFileN(title, defaultFolder, mask, pathName) THEN
  END;
        AlrtDialog(pathName);
  mask := '*.txt';
  IF GetFileN(title, defaultFolder, mask, fileName)
      THEN AlrtDialog(fileName);
END;
END;
RUN(Example);</code>
RUN(Example);
</code>


==== Python ====
<code lang="py">
title = 'Select the object library file...'
defaultFolder = ''
mask = 'vwx'
boo, pathName = vs.GetFileN(title, defaultFolder, mask)
if boo:
    vs.AlrtDialog(pathName)
</code>
</sample>
</sample>
-----------------------------------------------------------------------------------------------------------
<seeAlso></seeAlso>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<version>
<version>
Availability: from All Versions
Availability: from Vectorworks 2014


This is drop-in function.
</version>
</version>
-----------------------------------------------------------------------------------------------------------
<seeAlso>
</seeAlso>


</vwDoc>
</vwDoc>

Latest revision as of 04:18, 25 April 2022

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Returns the fully-qualified pathname of the selected file.

FUNCTION GetFileN(
title :STRING;
defaultFolder :STRING;
mask :STRING;
VAR fileName :STRING) : BOOLEAN;
def vs.GetFileN(title, defaultFolder, mask):
    return (BOOLEAN, fileName)

Parameters

title STRING
defaultFolder STRING
mask STRING
fileName STRING

Remarks

(_c_ 2017.01.22): Prompts for selection of a file of type "mask". The parameter "defaultFolder", if not empty, must be a posix path (with slashes). A HFS path (with colons) to the default folders can be obtained with VS:GetFolderPath, you will need to use VS:ConvertHSF2PosixPath for converting it into posix for older Vectorworks versions. Assigns the found path to var "fileName". Mask is case sensitive. The returned path is posix.

  • mask = 'vwx' allows selection of files of type .vwx
  • mask = ′′ allows selection of any kind of files
  • mask = 'vwx;txt' allows range of selection (from Pat Stanford on the VS list)


The GetFileN uses the SDK interface IFileChooserDialog

VCOM:Working with File/Folder Choose Dialogs

the ‘mask’ parameter goes as input to fileChooser->SetDefaultExtension(mask);

VCOM:VectorWorks:Filing:IFileChooserDialog::SetDefaultExtension

(MaKro, 2016.10.18):

Mask format change in VW2016 on a Windows 7 machine
Python mask example: '*.txt' if VW-Version < 2016 else 'txt'

Example

VectorScript

PROCEDURE Example;
VAR
    fileName, title : STRING; 
    defaultFolder : STRING; 
    mask : STRING; 
	
BEGIN
    title := 'Select the object library file...';
    defaultFolder := '';
    mask := 'vwx';
    pathName := 'Drafting Tools.vwx';

    IF GetFileN(title, defaultFolder, mask, pathName) THEN 
        AlrtDialog(pathName);
END;
RUN(Example);


Python

title = 'Select the object library file...'
defaultFolder = ''
mask = 'vwx'

boo, pathName = vs.GetFileN(title, defaultFolder, mask)
if boo:
    vs.AlrtDialog(pathName)

Version

Availability: from Vectorworks 2014