Page 1 of 1

Button (Macro) - Call *.exe

PostPosted: Thu Aug 03, 2017 1:40 pm
by Robertspark
Similar principle to the call (open) usermanual PDF.

.... this one just starts a program of your choosing from a UCCNC screenset button press, in this case Sheetcam (obviously won't work for you directly unless you have sheetcam ..... hence change it to the program of your choosing [vectric, autocad, stepper motor tuning software [leadshine protuner from the diagnostics screen] etc...

Code: Select all
System.Diagnostics.Process Sheetcam = new System.Diagnostics.Process();
Sheetcam.StartInfo.FileName = @"C:\Program Files (x86)\SheetCam TNG Development\SheetCam TNG Development.exe";
Sheetcam.Start();

Re: Button (Macro) - Call *.exe

PostPosted: Thu Aug 03, 2017 2:05 pm
by dezsoe
The same technique to use your favorite text editor to edit g-code. Edit screen and change "Edit file" buttonnumber from 126 to 20126. In M20126.txt change the path to your favorite text editor.

Code: Select all
// 126 -> 20126 -> external code editor

string sFileName = exec.mainform.filenametoload;

if ((sFileName == "") || (sFileName == Application.StartupPath + "\\Contents\\Empty.txt"))
{
  AS3.Additemtolistbeginning("No file loaded!", 2);
  return;
}

System.Diagnostics.Process proc;
proc = System.Diagnostics.Process.Start(@"C:\Program Files (x86)\PSPad editor\PSPad.exe", sFileName);
proc.WaitForExit();

exec.mainform.loadfile();

Re: Button (Macro) - Call *.exe

PostPosted: Wed Dec 25, 2019 11:04 pm
by Robertspark
help.....

Trying to work out how to get focus / setfocus to a process that is already loaded....

I've got this far.... but I cant seem to get "SetForegroundWindow" to work for me

Code: Select all


System.Diagnostics.Process[] localByName = System.Diagnostics.Process.GetProcessesByName("SheetCam TNG Development");

if (localByName.Length > 0){
   
//System.Diagnostics.Process Sheetcam = new System.Diagnostics.Process();
//localByName.Start();

return;
}
else {
System.Diagnostics.Process Sheetcam = new System.Diagnostics.Process();
Sheetcam.StartInfo.FileName = @"C:\Program Files (x86)\SheetCam TNG Development\SheetCam TNG Development.exe";
Sheetcam.Start();
}


I've tried various things after the "if (localByName.Length > 0){" and just cannot seem to be able to give focus to an already loaded process, instead of loading another occurance


Any guidance would be greatly appreciated, thanks,

Re: Button (Macro) - Call *.exe

PostPosted: Thu Dec 26, 2019 11:55 am
by Robertspark
well, I got this far:

Code: Select all
System.Runtime.InteropServices.DllImportAttribute import = new System.Runtime.InteropServices.DllImportAttribute("USER32.DLL");


but I cannot get this to run error free.... (yet)

Code: Select all
public static extern bool SetForegroundWindow(IntPtr hWnd);




trying to use this way of doing it:
https://shatter-box.com/knowledgebase/b ... th-csharp/