DxDesigner - how to have a script run when a project is opened

Discussion created by beltz on Nov 4, 2016
Latest reply on Dec 9, 2016 by vkhurana

I learned the following workaround from Nadia related to my SR 2901683625 based on TechNote MG593942 (which hasn't been published yet).


The DxDesigner automation documentation, talks about how to use Setup>Settings>Run on Startup to specify a form or script to run when a project is opened in DxDesigner.  This doesn't work, because it creates a scripts.ini and puts it in the user's $WDIR directory, so the script is run when DxDesigner is started and not when  the project is opened in DxDesigner.  One workaround is to copy/move this scripts.ini underneath the design directory (project file path).  Then the script is run when the project is opened.  But I wanted a way to specify this via a system $WDIR location so it would apply to all projects.


I already have a script LXKMenuDxD.vbs in my system scripts.ini location which sets up a local menu in DxDesigner (when a project is opened) to run local scripts.


I added the following which detects when a project is opened and runs the included script.


Scripting.DontExit = True


'MsgBox "Running LXKMenuDxD.vbs"


'Example code is from email from Nadia on my SR 2901683625, from a preliminary version of TechNote MG593942

' Have the startup script call a sub routine upon a Project change event.


Sub Application_ProjectChanged(projectData)


end sub


Sub Application_BeforeProjectChanged()


end sub


Sub SetCentralLibrary()

  if Not Scripting.Globals("SETUPPKG") then

     ' this is the code that will run when a project is opened in DxDesigner

     ' put the code from SetCentralLibrary.vbs here

     ' instead of having it in a scripts.ini file to run when a project is opened

     'MsgBox "SetCentralLibrary invoked due to project change"

     ' Run on an open document.

     Dim vdapp

     Set vdapp = GetObject (,"ViewDraw.Application")


     ' Get top level design name

     Dim ProjectData, DesignName

     Set ProjectData = vdapp.GetProjectData()


     Dim projfilepath

     projfilepath = vdapp.GetProjectData.getProjectFilePath()


     If Not (ProjectData.CentralLibraryPath = "/home/dms_lib/dms_lib.lmc") Then

       ProjectData.CentralLibraryPath = "/home/dms_lib/dms_lib.lmc"

       AppendOutput "xDX Databook", "FIXED **** Setting Central Library path to /home/dms_lib/dms_lib.lmc"



     End If



  end if

end sub


Then after this I have my normal script code when sets up the local menu in DxDesigner.