Open file at startup

Here is where you can request new features or special features.

Open file at startup

Postby cahit » Tue Feb 23, 2021 10:33 pm

Hi,

can you add a commandline argument to open a file at startup?

like "C:\UCCNC\UCCNC.exe /f contour.nc"

thanks regards
cahit
 
Posts: 73
Joined: Thu Jun 09, 2016 6:27 pm
Location: the Netherlands

Re: Open file at startup

Postby dezsoe » Wed Feb 24, 2021 12:25 am

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);
      }
    }
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Open file at startup

Postby cahit » Wed Feb 24, 2021 8:52 am

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..
cahit
 
Posts: 73
Joined: Thu Jun 09, 2016 6:27 pm
Location: the Netherlands

Re: Open file at startup

Postby dezsoe » Wed Feb 24, 2021 9:00 am

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.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Open file at startup

Postby cahit » Wed Feb 24, 2021 9:16 pm

hey dezsoe thats a great hint thanks..
cahit
 
Posts: 73
Joined: Thu Jun 09, 2016 6:27 pm
Location: the Netherlands

Re: Open file at startup

Postby cahit » Thu Feb 25, 2021 12:09 pm

hi dezsoe,

can you write an example snipped in vb.net. i cant get it.

thanks regards
cahit
 
Posts: 73
Joined: Thu Jun 09, 2016 6:27 pm
Location: the Netherlands

Re: Open file at startup

Postby dezsoe » Thu Feb 25, 2021 3:10 pm

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.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Open file at startup

Postby cahit » Thu Feb 25, 2021 9:36 pm

very nice... works fine.

thanks

regards
cahit
 
Posts: 73
Joined: Thu Jun 09, 2016 6:27 pm
Location: the Netherlands

Re: Open file at startup

Postby cahit » Fri Feb 26, 2021 4:50 am

hi dezsoe,

i want to reload a g-codefile. how can i do that in vb?
cahit
 
Posts: 73
Joined: Thu Jun 09, 2016 6:27 pm
Location: the Netherlands

Re: Open file at startup

Postby dezsoe » Fri Feb 26, 2021 7:34 pm

Hi Cahit,

Just press the reload button. (Or do it with UC.Callbutton(555).)
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Next

Return to Feature Request

Who is online

Users browsing this forum: No registered users and 7 guests