|
<< Click to Display Table of Contents >> Navigation: Programming Mechworks PDM > DBWCommandShell > Programmer's Guide > Asynchronous scripts |
available from build: 20040906 |
It is possible to launch .VBS scripts from MechworksPDM in an asynchronous way.
In order to have a script be launched asynchronously, the special keyword:
.ASYNCH
must be declared as comment in the head of the script ( see the example below ).
Asynchronous scripts are designed for launching tasks that do not modify the database and/or the models; typically they can be used for scripts making reports or queries that can take a long time to be executed. Due to the asynchronous way of starting the scripts, any call to functions related to the current selection in the browser may give unexpected results. Only functions addressing the document through the UNIQUE_ID must be used in an asynchronous script. Please consider the following case:
1.select document with unique_id=100 in the browser
2.start an asynchronous script
3.while the script is starting change the current selection to a document with unique_id=101
4.the script started, and calls the DBWShell("CurrentDocument"): the current document is now 101, and not 100 as when the script was asked to start
To help in this situations, a set of constants is available for asynchronous scripts:
const DBWorksCurrentDocumentUniqueId
const DBWorksCurrentDocumentType
const DBWorksCurrentDocumentId
const DBWorksCurrentDocumentIdNoSpace
const DBWorksCurrentSelection
They contains the same strings as the parameters returned from the commands
DBWShell("CurrentDocument")
and
DBWShell("GetSelection")
and can help in getting the correct current selection in the browser.
For example, a script code written as:
call DBWShell( "CurrentDocument" )
docUID = DBWResult("@DOCUMENT_UNIQUE_ID")
should be rewritten as
docUID = DBWorksCurrentDocumentUniqueId
and
DBWShell("GetSelection")
selection = DBWResult("@SELECTION")
should be rewritten as
selection = DBWorksCurrentSelection
Please note you should not invoke commands belonging to MechworksPDM environment, otherwise the asynchonicity wont' be maintained.
In the below case it's used a MsgBox instead of a DBWMsgBox
'.ASYNCH
Sub Main()
DBWInit(TRUE)
MsgBox "I am an asynchronous script!"
End Sub