Using macro for nesting

SheetCam related questions and tips can be posted here
Post Reply
rbmgf7
2 Star Member
2 Star Member
Posts: 79
Joined: Sat Apr 01, 2017 5:38 pm

Using macro for nesting

Post by rbmgf7 »

Using Mach3 and SheetCam.

What I have is a single, simple part that gets nested into a full sheet in a linear/rectangular/box pattern.

I was wondering if anyone has had luck writing a macro nest parts in a similar way? Technically each start position would be in its own work coordinate, right?

These are small parts and one 4x8 sheet yields 180 pieces.
User avatar
Ironken
3 Star Member
3 Star Member
Posts: 322
Joined: Thu Nov 30, 2017 7:29 pm

Re: Using macro for nesting

Post by Ironken »

I'm not quite following the macro thing....probably over my head. If I am reading you correctly, you want to do certain groups of parts perhaps in different arrangements? If so, in Sheetcam you can make different arrays of parts, say in a square pattern and save that as a job and so on. You can create arrays for 1/4 sheets or whatever. For example, you would use the array command for enough parts to fill up 1/4 of the sheet. You would then use the "new part" command and do the other 1/4 and again and again until you have 4 arrays. Now you can disable the layers for the arrays that you do not want to cut if this makes any sense.
User avatar
acourtjester
6 Star Elite Contributing Member
6 Star Elite Contributing Member
Posts: 7770
Joined: Sat Jun 02, 2012 6:04 pm
Location: Pensacola, Fla

Re: Using macro for nesting

Post by acourtjester »

Here is what I think you want, import a parts have it located in the lower left (X0 Y0) the click on nesting in the menus upper left. Then move pointer to material screen and right click on the screen a new menu will appear with "array parts" in it click on that and a new menu will come up with all the selections for setting up a large group of the same part. You can select distance between parts, the X and Y positions for the start position, how many rows and columns. you will needd to have the full sheet of material displayed to see all the parts.
multi parts layout.jpg
multi parts layout2.jpg
multi parts layout2.jpg (24.55 KiB) Viewed 682 times
multi parts layout3.jpg
multi parts layout3.jpg (24.62 KiB) Viewed 682 times
DIY 4X4 Plasma/Router Table
Hypertherm PM65 Machine Torch
Drag Knife and Scribe
Miller Mig welder
13" metal lathe
Small Mill
Everlast PowerTig 255 EXT
robertspark
4.5 Star Elite Contributing Member
4.5 Star Elite Contributing Member
Posts: 1809
Joined: Mon Jun 12, 2017 6:43 pm

Re: Using macro for nesting

Post by robertspark »

You could create a macro out of it if you are doing a lot of the same

Basically get the gcode for one object and put it within a code() function.

It will be slower because you would need to move the start point for every item you want to cut.
__________________
Another way

You can also use m98 to call a subroutine, and a second subroutine to move the start point of each cut
rbmgf7
2 Star Member
2 Star Member
Posts: 79
Joined: Sat Apr 01, 2017 5:38 pm

Re: Using macro for nesting

Post by rbmgf7 »

I don't know why this post was moved to SheetCam since macros are a universal programming function.

Appreciate the info Acourtjester. Didn't know that was available however it still isn't quite what I'm asking. Albeit, the result is the same but not a 10,000 line program.

I'm asking about developing a WHILE or IF condition to loop a section of the program to cut the part but perform some sort of arithmetic to shift the coordinate system to start a new part in the array.

I'll continue to poke at it. It's not too important since I already have a program but would be cool to learn macro programming.
robertspark
4.5 Star Elite Contributing Member
4.5 Star Elite Contributing Member
Posts: 1809
Joined: Mon Jun 12, 2017 6:43 pm

Re: Using macro for nesting

Post by robertspark »

I don't know what gcode motion control software you are using (Mach3/Mach4/UCCNC whatever?)

You don't use a WHILE of IF statement.

What you use is M98
https://www.cnccookbook.com/m98-m99-g-c ... bprograms/

Here is an example (this is a test code that I for motion)

Code: Select all

G0 X1
G91
M98 P200 L2
M98 P201 L2
M98 P202 L2
G0 Y1.5
M98 P203 L2
G0 Y-1.5
G90
G0 X0
M30

O200
G1 X3 F105
G1 X-3 
M99

O201
G1 Y3 F105
G1 X3
G1 Y-3
G1 X-3
M99

O202
G1 X3 F105
G1 Y3
G1 X-3
G1 Y-3
M99

O203
G02 X0 Y0 I1.5 J0 F105
G03 X0 Y0 I1.5 J0
G03 X1.5 Y0 I0.75 J0 
G02 X1.5 Y0 I0.75 J0
G02 X-3 Y0 I-1.5 J0
M99
Lest say that that I have this following code (a simple 3" square, extracted from the above gcode 0201 subcode):

Code: Select all

G1 Y3 F105
G1 X3
G1 Y-3
G1 X-3
Say I wanted to cut 3 of them horizontally.
Then you change the code to the following:

Code: Select all

G92 X0 Y0 (set temporary offset)
G91 (relative distance mode)
M98 P201 L3
G90 (absolute distance mode)
G0 X0 Y0 (go back to start position)
M30

O201
G1 Y3 F105
G1 X3
G1 Y-3
G1 X-3

G0 X3.5 (offsets the start position 0.5 past the outside of the cut shape)
M99
Say you now wanted 3 x horizontal (columns) and 2 x vertical (rows):

Code: Select all

G92 X0 Y0 (set temporary offset)
G91 (relative distance mode)
M98 P202 L2

G90 (absolute distance mode)
G0 X0 Y0 (go back to start position)
M30

O202 (vertical repeat)
M98 P201 L3

G90 (absolute distance mode)
G0 X0 Y0 (go back to start position)
G91 (relative distance mode)
G0 Y3.5 (offsets the start position 0.5 past the outside of the cut shape)
M99

O201 (horizontal repeat)
G1 Y3 F105
G1 X3
G1 Y-3
G1 X-3
(end of shape)

G0 X3.5 (offsets the start position 0.5 past the outside of the cut shape)
M99
robertspark
4.5 Star Elite Contributing Member
4.5 Star Elite Contributing Member
Posts: 1809
Joined: Mon Jun 12, 2017 6:43 pm

Re: Using macro for nesting

Post by robertspark »

The problem with these sorts of handballed gcodes is establishing the offset

How much to move them X and Y and also how many fit on the sheet.

The only way that I can think of doing that is via separate macro.

Basically load your shape and then run a macro which traverses the limits of your shape, this will then provide you with your offset.
It is possible to change these macros so they provide you with a window / message box that contains the X and Y extremes.

I use UCCNC, here is a macro I wrote for UCCNC to test a shape fits on my material (as I use offcuts from time to time)
http://www.forum.cncdrive.com/viewtopic ... ents#p4496


The idea came from here if you run Mach3:
http://forum.machsupport.com/forum/inde ... 154.0.html

other similar ones I'm sure could be created for Linuxcnc / Mach4 / whatever if you know what variables are available to you
Post Reply

Return to “SheetCam”