Hello Guest it is April 20, 2024, 06:51:53 AM

Author Topic: Can you assign G code to a button?  (Read 8783 times)

0 Members and 1 Guest are viewing this topic.

Can you assign G code to a button?
« on: July 01, 2008, 07:57:50 AM »
I would like to have several buttons on my Mach screen assigned to various G codes I have written. I know the button editor allows you to execute G code however you can only have 1 line and my codes are much longer.
I want to load a complete cabinet or countertop program (Subroutines and all) with the click of a button into Mach 3 so I don’t have to browses for different files with the load G code button. I don’t want it to start running I just want to load it.
I know nothing of VB but have been trying to figure out how to do this. I found some code on line, I can paste this in the button editor to view the contents of a text file but I can’t load it into Mach. Any help would be greatly appreciated.

'Declare variables.
    Dim fso
    Dim ts
    Dim fileText
    Dim ForReading, ForWriting, ForAppending
   
    'You can just use the numbers 1,2, and 8
    ForReading = 1
    ForWriting = 2
    ForAppending = 8
   
    'Create file sys object
    Set fso = CreateObject("Scripting.FileSystemObject")
   
    'Open file. using ForReading (or just use 1)
    Set ts = fso.OpenTextFile("C:\Test\Test.txt", ForReading, True)
   
    'Loop while not at the end of the file.
    Do While Not ts.AtEndOfStream
    fileText = fileText & ts.ReadLine
    Loop
   
    'Close the file.
    ts.Close
   
    'Clean up
    Set fso = Nothing
    Set ts = Nothing
   
    'Display what the file has in it
    MsgBox fileText

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Can you assign G code to a button?
« Reply #1 on: July 01, 2008, 11:17:19 AM »
Using VB script, use:

code "G0 X1 Y1"
code "G1 Z-.25"
code " G1 Xx Yy"
And on and on.....
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Can you assign G code to a button?
« Reply #2 on: July 01, 2008, 11:49:12 AM »
Put this in your "Loadcode buttons"

You can have several buttons that load code for you this way, you push the button and it loads the G-code of the file that is in that path.

If you want to "Reuse" your buttons you could name, button 1's TAP file "Button1", button 2's file could call Button2.tap, etc.
That way with your CAD/CAM, you could write any Code Changes to those buttons directly without changing what is in your screen set.
So if you wrote part #1 as file: "Button1.TAP" when you hit button "1" it would load that part file, if later you wanted to change what "Part 1" is, (modify it, make a whole new part, whatever), you could just save, and rename your OLD Button1 (if you wanted to keep it), and then post out your CAM to a new part file called button1, save it in the same place that your old buttton1 was, and when you hit button1, it would load your new file.......................

In screen designer, make a cutom button call it, Button1, and this is the VB that goes into it.
Loadfile("C:\CNC-parts-Files\Button1.TAP")

Here is the code inside Button2
Loadfile("C:\CNC-parts-Files\Button2.TAP")

as you can see, you can have as many of these quick call buttons as you want, also you can change the code they load by overwriting the file they call with your new file calling it the same name as the old. Very versitile.

Also, IF you want to get really fancey, you can use the OpenTeachFile, OpenSubroutineFile, AppendTeachFile, and CloseTeachFile(), and LoadTeachFile() functions to customize files and subroutines............

Scott




« Last Edit: July 01, 2008, 11:57:05 AM by poppabear »
fun times
Re: Can you assign G code to a button?
« Reply #3 on: July 01, 2008, 03:20:08 PM »
Hey thanks poppabear that worked flawlessly, I know you have read this a million times but it's guys like you helping out the rest of us that really make a difference on the forums. Keep up the good work and hopefully I can learn enough to help out on here someday.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Can you assign G code to a button?
« Reply #4 on: July 01, 2008, 04:07:17 PM »
Thank you, for the Thank you,..............sir,

scott
fun times

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Can you assign G code to a button?
« Reply #5 on: July 01, 2008, 04:43:47 PM »
Yup, thanks Scott, good job.  :)

Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline budman68

*
  • *
  •  2,352 2,352
    • View Profile
Re: Can you assign G code to a button?
« Reply #6 on: July 01, 2008, 05:27:02 PM »
The man's a genuine machine -   ;)
----------------------------------------------------------------------
Just because I'm a Global Moderator, don't assume that I know anything !

Dave->    ;)

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Can you assign G code to a button?
« Reply #7 on: July 07, 2008, 02:14:20 PM »
FVMC:

For fun, I did a "Quicky" Mod to one of my router screens, that you could adapt to your use as well.
This Screen will be a "Part counter" that can run User G code defined number of parts, or, a manual override for number of runs.
I.e.  If you want 3 "Cabinet Doors" (see G code below), the G-Code format also gives your operator Part/Job info"
So copy the "PartsCounter.set" to your main Mach3 directory.
Copy the M1000, and M1001 to the macro folder under the profile of the machine your running.
The button that says Manual PartCnt OVR ON (will select if your G code runs the part count, or the operator).
I.e. If you want 3 runs, once the operator hits cycle start, once it runs the G code 3 times, on the 4th run (it has to hit the M1000 again), it will stop the machine and give a message that the parts run is finished. (this is useful, for large part runs to keep count).

For instance the G code below "Button1.TAP":

(CDS #4, run 8, J#678)     'this message shows in your Status line, translation: CDS= Cabinet Door Style #4, Run this many 8, J# is the Job tracking number
#1=3                              'Parameter #1, is the parameter you use to pass the number of runs you want
M1000                             'M1000 this will HAVE to come after the parameter, and before your Code Starts
g0 x1                              'tool path code
g0 x0                              'tool path code
M1001                             'companion counter code, has to be right before your M30
m30

The Screen set, and the above two macros are attached below....

Scott
fun times
Re: Can you assign G code to a button?
« Reply #8 on: July 07, 2008, 02:47:33 PM »
You have a strange way of having fun! :-)

thanks I will load the page up and take a look.

Question: Have you ever had Mach3 just flip out? As an example, I run the same cabinet program 3 times in a row then on the 4th run it just decides to make a couple random circles then drop the bit. Or it looses it's offset in the middle of the run. restart the computer and Mach and everything runs fine again. any thoughts?

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Can you assign G code to a button?
« Reply #9 on: July 07, 2008, 10:18:16 PM »
clueless here, never had that happen to me.

scott
fun times