Jump to content
daveacad

Sort & number entities by clicking - LISP request (to improve laser cut efficiency)

Recommended Posts

daveacad

Hi people!

 

I'm looking for some help: I need to cut plexiglas with laser. The form, drawed with Autocad, come with many circles and arcs.

 

Know someone a routine or lisp able to click entities to reorder the sortment? And, second, it will be wonderful to add a progressive number to the entities to visually control the sortment of them!

 

(I hope the question I made is clear. My english is very poor).

 

Ciao,

Daveacad

Share this post


Link to post
Share on other sites
Lee Mac
Know someone a routine or lisp able to click entities to reorder the sortment?

 

What do you mean by 'reorder the sortment'?

 

To help us to understand, could you explain how you perform this operation manually?

Share this post


Link to post
Share on other sites
BIGAL

Sounds like nesting to minimise wastage

Share this post


Link to post
Share on other sites
daveacad

Hi Lee,

see the pictures!

 

attachment.php?attachmentid=56234&cid=1&stc=1

 

As You can see, on the right there is the draw I've made, with the order of entities comes by drawing (it is only an example. I did not check the right order!!!).

On the left side the same draw with the same entities, but ordered to let the cut made by the laser working better.

Under, I've drawed the path followed by the laser.

 

What I need is the possibility to select entities and decide wich one will be "drawed" before another one. This comes becouse the path of laser cutting depends from the order entiteis are inserted in the draw.

 

This 2nd picture is the result of the first cut:

 

attachment.php?attachmentid=56235&cid=1&stc=1

 

P.S. I've supposed the arcs are joined in a pline!

 

 

Ciao,

Davide

SORT Entieties 00.jpg

SORT WP_20151127_15_18_24_RESIZED.jpg

Share this post


Link to post
Share on other sites
BIGAL

Not sure you can reorder the entities in a dwg database but you can copy to another dwg so in correct order, it may be a case of using copy & paste. Using a pick objects and some smart tools would automate the pick order. A ssget "F" would pick all circles in correct order.

 

Need a tester code to see the order is working say a number at each object maybe using assoc 10.

 

(setq ss (ssget)) (command "copyclip" ss "") works so need to make a smart selection set using SSADD.

 

Would do it now but going out for lunch for the mother in laws birthday, let the motherin law jokes begin.

Share this post


Link to post
Share on other sites
Lee Mac

Try the following:

;; OE (Order Entities)  -  Lee Mac
(defun c:oe ( / cnt ent enx new sbx sub )
   (setq cnt 1)
   (while
       (progn
           (setvar 'errno 0)
           (setq ent (car (entsel (strcat "\nSelect object " (itoa cnt) " <done>: "))))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent)
                   nil
               )
               (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 (setq enx (entget ent)))))))))
                   (princ "\nSelected object is on a locked layer.")
               )
               (   (and
                       (setq new (entmakex enx))
                       (or (/= 1 (cdr (assoc 66 enx)))
                           (progn
                               (setq sub (entnext ent)
                                     sbx (entget  sub)
                               )
                               (while (/= "SEQEND" (cdr (assoc 0 sbx)))
                                   (entmake sbx)
                                   (setq sub (entnext sub)
                                         sbx (entget  sub)
                                   )
                               )
                               (entmake sbx)
                           )
                       )
                   )
                   (entdel ent)
                   (redraw new 3)
                   (setq   cnt (1+ cnt))
               )
               (   (princ "\nUnable to reorder selected object."))
           )
       )
   )
   (command "_.regen")
   (princ)
)

Share this post


Link to post
Share on other sites
BIGAL

Lee that would be 19 picks my idea 4 for circles last 1 for outside pline shape falls out. 5 picks. need a smart while etc fence or one at a time.

ScreenShot018.jpg

Share this post


Link to post
Share on other sites
BIGAL

Part 2 a test I have used text with numbers to check order of objects. Its hard coded to match test pattern but the method is there.

 

(defun c:test ( / pt1 pt2 pt3 pt4 pt5 ss x)
(setq pt1 (getpoint))
(setq pt2 (getpoint))
(setq pt3 (getpoint))
(setq pt4 (getpoint))
(setq pt5 (getpoint))
(setq ss (ssget "F" (list pt1 pt2 pt3 pt4 pt5)))
(setq x (sslength ss))
(repeat (sslength ss)
(princ (vla-get-textstring (vlax-ename->vla-object(ssname ss (setq x ( - x 1))))))
(princ "\n")
)
)

ScreenShot019.jpg

Share this post


Link to post
Share on other sites
daveacad

Hi guys,

thank you for your work!!!

 

The code made by Lee work properly. It will much useful with all the normal selection options; with more than 200 entities it take time to pick one by one.

 

About the code made by Bigal, I can't say anything... I'm not good with Lisp! I've tried to use it, but I don't understood how it work. Anyway thank you again for the interest.

 

And now, mr. Lee, could you please add the ability to use all the selection options of AutoCAD? Labeling items with numbers will be also nice, just with normal text.

 

I wish you a wonderful wee-end!!!

Grazie,

Davide

Share this post


Link to post
Share on other sites
Least

Hi Lee,

 

I think this could be useful for me. I will give it a test as soon as I can.

 

My survey instrument can import dxfs and the order the entities are in in the dxf corresponds to the point number the vertices and blocks are assigned. I have found that I could set the order of the line work order by reversing the lines twice.

 

P

Share this post


Link to post
Share on other sites
BIGAL

Daveacad the idea is like your images you posted you draw a path crossing over the objects which determines the order they are cut, you can go outside the object and come back in etc to make picking easy. The example with the text was so I could see if it worked as I had a visual of the order of the picked objects. I have to do something important right now (go fishing) but its likely to rain later so will have another go, picking 200 etc will not be a problem. I need to study lee's code a bit more I realise its erasing and recreating in order.

Share this post


Link to post
Share on other sites
BIGAL

Daveacad can you try this please my code is below lee's just draw a pline start and stop as often as required.

 

;; OE (Order Entities)  -  Lee Mac
(defun LEEoe ( ent / cnt  enx new sbx sub )
   (setq cnt 1)
   ;(while
       (progn
           (setvar 'errno 0)
           ;(setq ent (car (entsel (strcat "\nSelect object " (itoa cnt) " <done>: "))))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent)
                   nil
               )
               (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 (setq enx (entget ent)))))))))
                   (princ "\nSelected object is on a locked layer.")
               )
               (   (and
                       (setq new (entmakex enx))
                       (or (/= 1 (cdr (assoc 66 enx)))
                           (progn
                               (setq sub (entnext ent)
                                     sbx (entget  sub)
                               )
                               (while (/= "SEQEND" (cdr (assoc 0 sbx)))
                                   (entmake sbx)
                                   (setq sub (entnext sub)
                                         sbx (entget  sub)
                                   )
                               )
                               (entmake sbx)
                           )
                       )
                   )

                   (entdel ent)
                   (redraw new 3)
                   (setq   cnt (1+ cnt))

               )
               (   (princ "\nUnable to reorder selected object."))
           )
       )
;    ) ; while
   
   (princ)
)

; pline co-ords example
; By Alan H
(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq len (length co-ords))
(setq numb (/ len 2)) ; even and odd check required
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)

; program starts here

(defun c:OE( / ss x)
(command "_pline")
(while (= (getvar "cmdactive") 1 ) (command pause)
)
(setq co-ords (getcoords (entlast)))
(co-ords2xy) ; list of 2d points making pline
(entdel (entlast))
(setq ss (ssget "F" co-ordsxy))
(setq x (sslength ss))
(repeat (sslength ss)
(setq ent (ssname ss (setq x ( - x 1))))
(if (= (vla-get-ObjectName (setq obj (vlax-ename->vla-object ent))) "AcDbCircle")
(progn
(setq pt (vlax-safearray->list (vlax-variant-value (vla-get-center obj))) )
(setq ts (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE")))))
 (if (zerop ts)
     (command "TEXT" pt "3.5" "0" (rtos x 2 0))
     (command "TEXT" pt "0" (rtos x 2 0))
  )      
) ; progn
) ; if 
(LEEoe ent)

(princ "\n")
)
(command "_.regen")
)

Edited by BIGAL

Share this post


Link to post
Share on other sites
daveacad

Hi Bigal,

the LISP you arranged don't work properly. Please, see pictures.

The numbers will write every time you use the Lisp. If they are write once, the second time you use the Lisp, they will write again: is not a big problem, if you are good with AutoCAD o:)

 

The big problem is the selection options: I need the normal selection, or it will very difficult to work with that Lisp.

 

In the last picture you can see the numbering of items made every time you use the Lisp, with different value for the same entity.

 

Sometime the Lisp don't work properly (nil message).

 

Hope my reply will be helpful!

 

Thank you,

D.

SORT Entieties LISP OE 00.jpg

SORT Entieties LISP OE 01.jpg

SORT Entieties LISP OE 02.jpg

SORT Entieties LISP OE 03.jpg

SORT Entieties LISP OE 04.jpg

Share this post


Link to post
Share on other sites
BIGAL

Can you post a couple of samples dwg's, is the outside not a continous pline ?

Share this post


Link to post
Share on other sites
BIGAL

I am not sure what you want, draw random objects and pick them in some sort of simple method bit like picking the path of the laser, the code only puts numbers on circles at the end of the day we are doing this for free. If you don't reset the cnt it will continue numbering. You should be able to run it multiple times as you may not be able to just pick one single path. If you want the order in reverse that can be done.

 

ScreenShot021.jpg

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...