Associating a Dialog with a View Tool

(This article assumes familiarity with the Dialog Designer extension. To download it, click HERE.)

Assume a Dialog named "Dialog1". To launch the Dialog when a tool is clicked, add the following lines to the tool's Click script:

theDialog = av.FindDialog("Dialog1")
theDialog.Open
To cause the Dialog to close when the View is closed or deactivated, add the following lines to its Open script:

theView = av.GetActiveDoc
SELF.SetServer(theView)
SELF.SetServerActivated("")
SELF.SetServerClosed("CloseDialog")
SELF.SetServerDeactivated("CloseDialog")
where "CloseDialog" contains the following lines:

theDialog = av.FindDialog("Dialog1")
theDialog.Close
To cause the Dialog to close when the Tool is not selected, or reopen if the Tool is still selected when the View is reactivated, place the following lines at the beginning of the Tool's Update script:

theDialog = av.FindDialog("Dialog1")
if (SELF.IsSelected) then
   theDialog.Open
else
   theDialog.Close
end
Unfortunately, not every other tool causes an Update event when it's clicked. For every tool that lacks a Click script, assign one; even if the script is empty, it will automatically trigger an Update event.


Dialog Tools

If your dialog has tools, you will want to deactivate them when the dialog is closed and reactivate them when the dialog is opened. Assuming that a Dialog named "Dialog1", the following line should be present in the dialog's Open script:

SELF.GetControlPanel.SetEnabled(true)
and the following in the Close script:

SELF.GetControlPanel.SetEnabled(false)

Dialogs Associated with Views but not View Tools

If a dialog is associated with a View but not with a tool, you may want it check whether or not it should be reopened when the View is activated. This may be done by means of an object tag. Place the following lines in the Open script:
theView = av.GetActiveDoc
SELF.SetServer(theView)
SELF.SetServerActivated("Restore")
SELF.SetServerClosed("Hide")
SELF.SetServerDeactivated("Hide")
SELF.SetObjectTag("NORESTORE")
where "Hide" contains the following lines:
if (SELF.IsOpen) then
   SELF.SetObjectTag("RESTORE")
   SELF.Close
end
and "Restore" contains the following lines:
if (SELF.GetObjectTag = "RESTORE") then
   SELF.Open
end

Back to AVTips