2 Replies Latest reply on Jun 24, 2010 11:26 PM by joerg.schmidt

    How to set up Events for a DxDesigner Application




      I like to set up a event-handler for a DxDesigner application. But the following code doesn't work and the Dxdesigner crashes during the execution.

      It seems that the a Dxdesigner application object has no Active Document?

      And the ValidateServer function, which is not shown in my sample code, doesn't work either.

      Why do I need the to call this function?


      My final goal is to set up a function for the Application_ActivateView() - event.

      Maybe someone can give me some hint(s)?


      Thanks Joerg



      ' Add any type libraries to be used.

      ' Get the Application object
      Dim dxdesignerAppObj
      Set dxdesignerAppObj = Application

      ' Get the active document
      Dim dxdesignerDocObj
      Set dxdesignerDocObj = dxdesignerAppObj.ActiveDocument


      ' License the document

      ' ValidateServer(dxdesignerDocObj)


      ' Attach events from the document object.
      Call Scripting.AttachEvents(dxdesignerDocObj, "dxdesignerDocObj")

      ' Set the Scripting.DontExit property to 
      ' true to keep the script running.
      Scripting.DontExit = True

      ' Event handlers
      ' PreClose event handler
      Function dxdesignerDocObj_OnPreClose()
          Dim ansEnum
          ansEnum = MsgBox("Close this document?", vbYesNo)
          If ansEnum = vbYesThen
              dxdesignerDocObj_OnPreClose = True
              dxdesignerDocObj_OnPreClose = False

        • 1. Re: How to set up Events for a DxDesigner Application

          Hi Joerg,


          You don't need to call ValidateServer, this is a wrapper function around the Expedition automation licensing, which is not required for DxDesigner.


          Also, you do not need to call Scripting.AddTypeLibrary if the script is running in DxDesigner, the type library is loaded automatically.  You only need to call AddTypeLibrary if the script is hosted by a different application, like Expedition or mgcscript.


          Likewise, when the script is run in DxDesigner, there is an implicit call to AttachEvents for the Application object.  Since you want to handle the Application_ActivateView event, just declare a function named Application_ActivateView that takes no arguments.  You will notice in the DxDesigner Automation manual, it is recommended to use the ActivateView2 event instead, because of a timing problem.  To follow that recommendation, declare a function named Application_ActivateView2 that takes one argument, the active view:


               Function Application_ActivateView2(v)

                   MsgBox "View " & v.Block.GetName(0) & " activated"

               End Function


          You can remove the active document code, it appear this code was copied from an Expedition script, since there is no OnPreClose event for DxDesigner.



          1 of 1 people found this helpful
          • 2. Re: How to set up Events for a DxDesigner Application

            Hi John,


            that's it!

            Now it works! That was a "push" in the right direction

            Thanks for your fast help.