Page 1 of 2
Open file at startup

Posted:
Tue Feb 23, 2021 10:33 pm
by cahit
Hi,
can you add a commandline argument to open a file at startup?
like "C:\UCCNC\UCCNC.exe /f contour.nc"
thanks regards
Re: Open file at startup

Posted:
Wed Feb 24, 2021 12:25 am
by dezsoe
Hello Cahit,
Insert the following lines into your M99998 macro:
- Code: Select all
// Open file from command line /f <filepath>
// Use quotes if filepath contains space: /f "\my files\cnc.tap"
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 0)
for (int i = 0; i < args.Length; i++)
if ((args[i].Trim().ToUpper() == "/F") && (i < args.Length - 1))
{
string fname = args[i + 1];
if (System.IO.File.Exists(fname))
{
exec.AddStatusmessage("Opening " + fname);
exec.Loadfile(fname);
}
}
Re: Open file at startup

Posted:
Wed Feb 24, 2021 8:52 am
by cahit
Hi dezsoe,
thank you.
it works, great.
but i wonder if it can be embeded in the UCCNC.exe in stead of M99998 macro:
i want to use it with new autoleveler.dll plugin. now, everyone have to modify de M99998 macro.
thanks again..
Re: Open file at startup

Posted:
Wed Feb 24, 2021 9:00 am
by dezsoe
Hi Cahit,
You can do exactly the same in your plugin. E.g. you can run this in the loop event when the firstrun is true, so it runs only once after startup.
Re: Open file at startup

Posted:
Wed Feb 24, 2021 9:16 pm
by cahit
hey dezsoe thats a great hint thanks..
Re: Open file at startup

Posted:
Thu Feb 25, 2021 12:09 pm
by cahit
hi dezsoe,
can you write an example snipped in vb.net. i cant get it.
thanks regards
Re: Open file at startup

Posted:
Thu Feb 25, 2021 3:10 pm
by dezsoe
Hi Cahit,
OK, I see. The plugin loads too fast: UCCNC is not ready to load a file. I modified the loop event:
- Code: Select all
If FirstRun Then
testcmdline()
' Write code here which has to be run on first cycle only...
End If
First I wait for the reset signal to become active, then I wait 1 s and then I try to load the file and clear firstrun:
- Code: Select all
Dim cnt As Integer = 25
Private Sub testcmdline()
If Not UC.GetLED(25) Then Return
If cnt > 0 Then
cnt -= 1
Return
End If
Dim args() As String = Environment.GetCommandLineArgs()
Dim fname As String
If args.Length > 0 Then
For i As Integer = 0 To args.Length - 2
If args(i).Trim.ToUpper = "/F" Then
fname = args(i + 1)
If IO.File.Exists(fname) Then
UC.Loadfile(fname)
End If
End If
Next
End If
FirstRun = False
End Sub
I wait 25 loops which is 1 second and only then load the file.
Re: Open file at startup

Posted:
Thu Feb 25, 2021 9:36 pm
by cahit
very nice... works fine.
thanks
regards
Re: Open file at startup

Posted:
Fri Feb 26, 2021 4:50 am
by cahit
hi dezsoe,
i want to reload a g-codefile. how can i do that in vb?
Re: Open file at startup

Posted:
Fri Feb 26, 2021 7:34 pm
by dezsoe
Hi Cahit,
Just press the reload button. (Or do it with UC.Callbutton(555).)