Hi C# guys,
how do you run an C# automation program from DxD? Running it from the DxD command line does not work, as it accepts vbs only.
And how do you run it from an custom menu. Calling it like a vbs as command does not work.
Thanks in advance.
I do it by a wrapper vbs script.
Set objWScriptShell =CreateObject("WScript.shell") ' Create the windows object
I hope that is what you are looking for.
thank you. It's not exactly what I'm looking for. I do not want to have a extra wrapper vbs for each exe. So I tried to write a common wrapper that gets the exe to call, from arguments. But arguments in vbs seems to be not supported from DxD ...
if you figure it out Andreas, please share with the rest of us!
Really wish Mentor would just support a direct call of the exes!!!! Would make life a lot easier than jumping through these unnecessary hoops.
Aside from using a wrapper, I think the only other way is a custom menu. Here is how you do that:
' Define TOOL_LOCATION as the location where your exe's resideConst TOOL_LOCATION = "C:\some_location\" Dim objExec : Set objExec = CreateObject("Viewlogic.Exec") ' Code to get objMenu elided for clarity... Dim objBtnSet objBtn = objMenu.Controls.Add(cmdControlButton,,, -1) objBtn.Caption = strCaptionobjBtn.Target = ScriptEngineobjBtn.ExecuteMethod = "OnDisplayMyMethod" Scripting.DontExit = True Sub OnDisplayMyMethod(nID) objExec.Run TOOL_LOCATION & "myexe.exe"End Sub
' Define TOOL_LOCATION as the location where your exe's reside
Const TOOL_LOCATION = "C:\some_location\"
Dim objExec : Set objExec = CreateObject("Viewlogic.Exec")
' Code to get objMenu elided for clarity...
Set objBtn = objMenu.Controls.Add(cmdControlButton,,, -1)
objBtn.Caption = strCaption
objBtn.Target = ScriptEngine
objBtn.ExecuteMethod = "OnDisplayMyMethod"
Scripting.DontExit = True
objExec.Run TOOL_LOCATION & "myexe.exe"
are you sure, that "ExecuteMethod" is working in DxDesigner?
In my experience, only "OnAction" works in DxDesigner.
When I try "ExecuteMethod" I get following Message:
"Target object doesn't implement <mySub> method"
That code was pulled straight from a script that definitely works in DxDesigner 7.9.5. Your error message seems to indicate that your script does not contain a subroutine matching the name given to ExecuteMethod. Make sure you don't have a typo somewhere. If you can't see the problem, post a minimum code sample that doesn't work.
Which update are you on Peter? I'm guessing Mentor recently updated the APIs to be more similar and we have version differences. I am on EE7.9.4 update 9.
I'm getting the same error as Helmut. Yes, the method definitely exists. Your example is the exact code that works for Expedition menus so I weent back and added button.Target = ScriptEngine and now when you click on my menu in Dx the whole tool crashes.
now I have found my problem.
I have overlooked line "Scripting.DontExit = True" from your code snippet.
That is reason why my sub can't found from ExecuteMethod.
Because of ExecuteMethod allows no parameter I need a wrapper sub for each menu botton.
My solution looks now:
' Script AddDxDesignerCustomMenu.vbs called from scripts.ini
' Create shell object to execute exe programs without wrapper vbs
Set objWScriptShell = CreateObject("WScript.shell") ' Create the windows object
Scripting.DontExit = True ' keep this vbs script running until DxDesigner session will be closed
' Append new Menu Bar Item "Custom" at the end of "Sheet Menu Bar" of DxDesigner
Set objMenuBarPopupCustom = CommandBars("Sheet Menu Bar").Controls.Add(cmdControlPopup,,,-1)
objMenuBarPopupCustom.Caption = "&Custom"
' Add buttons to menu "Custom"
' Menu button "Create Function Report"
Set objMenuBarButtonCreateFuncRep = objMenuBarPopupCustom.Controls.Add(cmdControlButton,,, -1)
objMenuBarButtonCreateFuncRep.Caption = "Create &Function Report"
objMenuBarButtonCreateFuncRep.DescriptionText = "Creates Report based on function managed Variants" ' displayed in status bar
objMenuBarButtonCreateFuncRep.Target = ScriptEngine
objMenuBarButtonCreateFuncRep.ExecuteMethod = "subCreateFuncRep"
Sub subCreateFuncRep(nID) ' nID is required because ExecuteMode calls sub with one parameter
yep, I too was missing "Scripting.DontExit = True" in my Dx script....had it in the Expedition one...
Good catch guys.
by the way. I don't use ExecuteMode in Expedition because OnAction works there with exe files (no sub required).
CreateBillOfMaterial.OnAction = "run N:\Utilities\Expedition\CreateBillOfMaterial\CreateBillOfMaterial.exe"
So what are the intended purposes of ExecuteMethod and OnAction, more specifically what are the difference? I reread the documentation on them both but I'm still not getting it I guess.
By the way, my corporate WDIR thanks you all! I was able to clean up a lot of dumb wrapper vbs files I had in there.
so fare as I know ExecuteMethod is to execute VBS functions and subroutines, and OnAction is to execute build-in and key-in commands.
I have no experience with build-in commands up to now.
One of key-in Commands is "run".
My experience in Expedition, you can run Visual Basic scripts and exe files with "run" command.
My experience in DxDesigner you can run only Visual Basic scripts (no exe files).
I hope it's a litle bit helpful for you.
Retrieving data ...