Scripting Document Operations

DocumentControl Methods

Get/Set Current Document

<string> DocumentControl.getCurrentDocument ()

  • Returns the ID of the current (Active) Document.

<void> DocumentControl.setCurrentDocument ( <string>documentId )

  • Sets the current (Active) Document to the specified Document ID.

Set Default Directory

<void> DocumentControl.setDefaultDirectory ( <string>directory )

  • Sets the default directory where the File > Open dialog will look for files.

Example:

DocumentControl.setDefaultDirectory ("c:/temp"); //set the default directory
DocumentControl.open(); //open the file dialog at the default directory

Get Documents List

<sringList> DocumentControl.getRecentFileList ()

  • Returns the list of recently edited Documents.
  • Equivalent to the File > Open RECENT Document... > list in the UI.

<stringList> DocumentControl.getAllDocuments ()

  • Returns a list of the IDs of all currently opened Documents.

<stringList> DocumentControl.getAllDocumentNames ()

  • Returns a list of the names of all currently opened Documents.

Save Viewport To Document

<void> DocumentControl.saveViewportsToDocument ( <string>documentId )

Document Creation

<string> DocumentControl.createDocument ()

  • Creates a new Document.
  • Does NOT switch to the new Document.

Example:

var newdoc = DocumentControl.createDocument(DocumentControl.getCurrentDocument());
DocumentControl.setCurrentDocument(newdoc);

<string> DocumentControl.cloneDocument ( <string>documentId )

  • Creates a clone of the Document with the given Document ID, and returns the new Document’s ID.

Open Document

<string> DocumentControl.open ()

  • Opens the Open File dialog and lets the user select an existing .SQ file to load.
  • If a valid file is selected, it will be loaded as a new Document.
  • Returns the Document ID of the new Document.

<string> DocumentControl.open ( <string>filename )

  • Opens the specified .SQ file without prompting with an Open File dialog.
  • Returns the Document ID of the new Document.

Example:

DocumentControl.open('c:/temp/test.sq');

Save Document

<bool> DocumentControl.save ( <string>documentId )

  • Saves the Document specified as argument to its current file name, overwriting the previous file.
  • If the Document is Untitled, opens the Save File dialog.
  • Returns true if the file was saved, false if not saved.

Example:

DocumentControl.save(DocumentControl.getCurrentDocument());

<bool> DocumentControl.saveAs ( <string>documentId, [<string>filename=”“] )

  • Saves the Document to the specified file name if a valid name is specified.
  • Does not save if the Cancel button is pressed in the Save File Dialog.
  • If the second optional filename argument is not specified, or if it is specified as an empty string, the Save File dialog will be opened.
  • Returns true if the Document was saved, false if it was not saved.

Close Document

<void> DocumentControl.close ( <string>documentId )

<void> DocumentControl.closeDocument ( <string>documentId )

  • Both methods close the document with the ID specified by the argument.

Example:

DocumentControl.close(DocumentControl.getCurrentDocument()); //closes the current document

Auto-Update and Auto-Zoom

<bool> DocumentControl.isAutoUpdate ( <string>documentId )

  • Returns true if the Document’s Auto Update option is checked, false if it is unchecked (default).

<bool> DocumentControl.isAutoZoomExtents ( <string>documentId )

  • Returns true if the Document’s Auto Zoom option is checked (default), false if it is unchecked.