Check Z Of 2D Polylines

Check Z Of 2D Polylines

christianbaileypaulsen1
Advocate Advocate
2,719 Views
31 Replies
Message 1 of 32

Check Z Of 2D Polylines

christianbaileypaulsen1
Advocate
Advocate

When programming for cnc we make our bits cut .005 into the table. So that the Z value of out cuts are -.005. After creating a program we must read through all the Nc code which could be pages, and make sure none of the Z values are below -.005. Then we go to front view of out cnc drawing and look if anything is further below than Z -.005. When doing hundreds of programs this adds hours of work. I was wanting to create a lisp would check if there is anything in the project less than -.005. Then maybe select those object so that i can see which ones they are and fix them. This would save me hours a day and allow me to work much more efficiently. Any advice is welcome. Thank you. Im not good at coding at all but ill try to give an idea below so you guys can see im at least trying. 

 

If Z < -.005

{ Select object}

else

{Dont select Object}

 

... Repeat for all objects in drawing until everything has been checked.

 

I really appriciate everyone's help, even if you just read this thread and didn't say anything.

 

0 Likes
2,720 Views
31 Replies
Replies (31)
Message 21 of 32

Kent1Cooper
Consultant
Consultant

Your code in Post 20 worked for me [in limited testing].  Does it load and accept the command name?  Are you getting any error message?

Kent Cooper, AIA
0 Likes
Message 22 of 32

As soon as i put in the material thickness, i get kicked out of the command. OSMODE is my object snap right? I dont see how that would be affecting what im trying to do but i get the below error in my command prompt.

 

Command: APPLOAD
zcheck.LSP successfully loaded.
Command:
Command:
Command: TOODEEP
Enter material thickness:.75
AutoCAD variable setting rejected: "OSMODE" nil
Command:

0 Likes
Message 23 of 32

Kent1Cooper
Consultant
Consultant

Since there's no OSMODE setting in the code, I suspect something is triggering an Enter  that's recalling the last command, and the last thing you did prior was to set OSMODE with the command-line version.  To test that, try doing something else like drawing a Line, and then trying the routine again, and see if it complains in a different way.

 

What could be causing that, I don't see at the moment....  It could possibly be something version-dependent -- I'm at my ol' Acad2004 location right now.

Kent Cooper, AIA
0 Likes
Message 24 of 32

christianbaileypaulsen1
Advocate
Advocate

Seems to be working i guess. Weird that sometimes it does and sometimes it doesnt. It says its added to a selection set under variable TooDeep. How do i actually select the objects though?

0 Likes
Message 25 of 32

Kent1Cooper
Consultant
Consultant

@christianbaileypaulsen1 wrote:

.... It says its added to a selection set under variable TooDeep. How do i actually select the objects though?


You can use what's in any  AutoLisp variable in a manually-run command by preceding the variable name with an exclamation point, e.g. if it's a selection set that you want to Move:

 

Command: MOVE

Select objects: !TooDeep
<Selection set: 61e>
4 found

Select objects: {Enter to finish selection}
Specify base point or displacement: ....

 

You can do the same outside any command for other kinds of variables, e.g. if you have a point saved in the 'pt1' variable, you can get its coordinates reported:

 

Command: !pt1
(2.0 -23.0 0.0)

 

If you want to do something to them one at a time, you can get at the things in a selection set with the (ssname) function, for instance, within an AutoLisp routine:

 

(redraw (ssname TooDeep 0) 3)

 

will highlight the first thing in the selection set [indexing starts with number 0].  You can use the same out in a manual command:

 

Command: MOVE

Select objects: (ssname TooDeep 2)
<Entity name: 7ed9cd68>
1 found

Select objects: ....

Kent Cooper, AIA
0 Likes
Message 26 of 32

wkmvrij
Advocate
Advocate

In this entire discussion some very vague points. You write: From there i will open up my cnc program in autocad. I presume, that you will then generate your Gcode for your router machine. Have you added the lead in and lead out your self? Are these not parameters in this software? Which elements from your DWG are taken by this software and how are they related to the zero position of your router?

 

 

In your workflow I miss the notion of stock material. Ideally your toolpath should relate to this stock material, with the top position for your lead in/out ramps and having a bottom plane, that you might place at -005. before you generate the Gcode .

 

Your Gcode file is a text file. In principle you could analyse that file programmatically too, even in Lisp...

 

 

 

0 Likes
Message 27 of 32

christianbaileypaulsen1
Advocate
Advocate

 

Okay so at the end of the command could there be a part like this added?

 

(command _.select !toodeep)

 

That way at the end of the command all the too deep parts will already be selected.

0 Likes
Message 28 of 32

christianbaileypaulsen1
Advocate
Advocate

My cnc file is only a template so i can lay out parts across an entire 4x8 sheet. I then add the polylines. I just click the polyline i would like to cut and prewritted knowledge adds in the lead in and lead out. I also always cut my parts in 2 passes. The first pass will cut most of the way through the part, and the second will cut all the way .005 past the bottom of the part. I dont have a stock material, we cut anything from 1/16" material to 3" material. If im cutting 3/4" material, my final cut depth should be -.755. If im cutting 3" material my final cut depth should be -3.005. 

 

In the block that is created you can see the path the router bit follows. The yellow lines are the lead in and lead out, the red lines are the line if follows to cut all the way around the piece, there is even some MTEXT in the block that describes the feed rate at different points. There are two red lines in the block because i cut my parts in two passes, one of them will be higher than the other, and the final cut will be the lowest one.

 

Before this i had to open the text file in Notepad, press control f to open up the find tool, type in "z-", and scroll through all the text to double check there is nothing below .005. When gone too fast stuff is easily missed and you leave it in the hands of people who make mistakes, computers who accurately run numbers do not make mistakes. Sometimes our code gets VERY long and it could take 20-30 minutes to look through just one program. We make hundreds of programs a day so the amount of time this could potentially save is no small number.

 

I hope that answered all of your questions. Kent this was not meant for you by the way i just accidentally clicked reply under your name.

0 Likes
Message 29 of 32

Kent1Cooper
Consultant
Consultant

@christianbaileypaulsen1 wrote:

 

Okay so at the end of the command could there be a part like this added?

 

(command _.select !toodeep)

 

That way at the end of the command all the too deep parts will already be selected.


Inside AutoLisp functions, you just use the variable name, without the exclamation point:

(command _.select TooDeep)

 

HOWEVER, that will leave you with the further "Select objects:" prompt that you have to answer, and whether you just hit Enter or select more things, with the SELECT command completed, yes, they'll be in the Previous selection, but they won't  be selected/highlighted/gripped any more, as that as-yet-uncompleted (command) function leaves them.  If you want that, do this:

 

(sssetfirst nil TooDeep)

 

and then they'll all be selected/highlighted/gripped in noun-verb-selection style, ready for grip-editing or calling any editing command.

Kent Cooper, AIA
0 Likes
Message 30 of 32

wkmvrij
Advocate
Advocate

I appreciate your answer even when that was sent to Kent Smiley Wink 

I looked at your sample drawing a bit closer now and stumbled on some more questions.

 

You have your toolpath specified in the block called "drawing11-1".  First off, I do not see any ramp-in from the first cutting path into the next. ( the path that lies a bit lower and allows for the through cut) Both your in-path and your out-path end on the lowest rectangle.(the cut trough path).It should be a continuous movement all the way from the first contact of your bit on your stock to the final movement cutting the part loose.

 

Now when I WBLOCK your toolpath (block drawing11-1) I find, that the base point of your block is equal to the start of one of the in or out ramps. So all of the poly-lines included in your block are to be related back to the INSERT coordinates of the block when put in your template DWG. That does not facilitate the easy check of finding the top of your routertable minus 0.005

 

How does that block come into beeing ?

 

Is that block fed into the software that generates the Gcode? 

 

If you are to produce an array of similar products from a full sheet do you then create an array of blocks "drawing11-1", each with its own INSERT or is one single block made called  "drawing11-1" with all of the sets of poly-lines one after the other with spindle transportation poly-lines in between? The first option would require a nested block with connecting paths and product description blocks.

 

In general I would approach your problem from the Gcode side. Your DWG has no interaction with the machine, and as the Gcode is a well structured text file it would be quit possible to follow the track of the tip of the router bit and check the Z-coordinates before starting the machine. After all, you have the start of the path and your machine has a well established data between your table and your bit. Add all the Z-values sequentially and alert when the totall exceeds the distance between tip of the tool and table.

 

0 Likes
Message 31 of 32

christianbaileypaulsen1
Advocate
Advocate

Kent is there a way to clear the selection set at the beginning of the lisp? There will be items that are too deep the first time around, then i fix them. Once i fix them and rerun the lisp, they items that are fixed are still in the selection set. Thank you.

0 Likes
Message 32 of 32

Kent1Cooper
Consultant
Consultant

@christianbaileypaulsen1 wrote:

Kent is there a way to clear the selection set at the beginning of the lisp? .....


A couple of ways....  One is to clear it explicitly:

 

(defun C:TooDeep (/ candidates item minpt maxpt materialthickness)
  (setq

    materialthickness (getreal "Enter material thickness:")

    TooDeep nil

  ); setq
  (if (< (caddr (getvar 'extmin)) (- 0 materialthickness 0.005))

....

 

Another is to move the starting of the empty selection set earlier:

 

(defun C:TooDeep (/ candidates item minpt maxpt materialthickness)
  (setq

    materialthickness (getreal "Enter material thickness:")

    TooDeep (ssadd) ; initially empty selection set

  ); setq

(if (< (caddr (getvar 'extmin)) (- 0 materialthickness 0.005)); ANYTHING in the drawing too low?
    (progn ; then -- find it/them
      (setq
        candidates ....

 

The latter has the disadvantage, if you want to consider it that, of leaving a variable floating around whether or not  anything was found to be too deep.

 

That can be avoided if  you are able to add processing of the misbehavers into the routine, in which case you could localize the variable, and it would not exist after the end of the routine:

 

(defun C:TooDeep (/ TooDeep candidates item minpt maxpt materialthickness)

....

 

That may be possible, if what you always  want to do is just to Move them up enough that they don't go too deep any more -- each one could be Moved depending on its own current penetration depth.  But if there might be other possible fixes [replace with a different Block, or something], don't do it that way, because you won't have  the selection to work with after the routine is done.

Kent Cooper, AIA
0 Likes