Jump to content

Need help with lisp to polyedit everything on each layer


Recommended Posts

Posted

Hello all! I need help with a lisp that would allow me to just click a button, and, layer by layer, polyedit everything together. There doesn't need to be a fuzz factor. I know very little about creating lisps; in fact my knowledge is limited to editing lisps that are already created. Thank you.

Posted

Very easily done, but polyedit to do what, just change every line into a polyline?

Posted

I work in the countertop industry. We use autocad to draw up our countertops and then use it to program our CNC's. the cnc's need every line to be a polyline. We use different layers for different tools/depths. I just figured if I could get a lisp that would polyedit every line on each layer to create polylines of everything dependant on the layer the lines are on. If lines are connecting then to connect them; if they are individual lines then just turn them into a polyline.

Posted

Here goes!

 

(defun c:pljoin    (/ *error* varLst oldVars ss ssl)

   ;;     --- Error Trap ---
   (defun *error* (msg)
   (mapcar 'setvar varLst oldVars)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ (strcat "\n" (strcase msg)))
   ) ;_  end if
   (princ)
   ) ; end of *error*

   (setq varLst  (list "CMDECHO" "PEDITACCEPT")
     oldVars (mapcar 'getvar varLst)
   ) ; end setq 

   ;;     --- Error Trap ---

   (setvar "cmdecho" 0)
   (setvar "PEDITACCEPT" 0)
   (setq plnum 0)
   (setq ss (ssget "X" (list (cons 0 "LINE") (cons 410 (getvar "ctab")))))
   (if    (/= (setq ssl (sslength ss)) 0)
   (command "_pedit" "M" ss "" "Y" "J" "0.0" "")
   ) ;_  end if
   (*error* "")
   (alert (strcat (rtos ssl) " Polylines Created/Joined."))
   (princ)
) ;_  end defun


Posted

I really do appreciate your help, but that doesn't seem to work. It's changing layers on certain items, and not polyediting radii together. How I envision it in my head is as such. Turning off all layers except for one. running pedit, selecting "multiple", selecting everything on screen, using "join" option, with no fuzz distance. Then moving on to the next layer and repeating the above steps. Does that makes sense? If you want, I could also send you a finished file of what we are trying to do. thanks.

Posted

Hmm... it worked on my machine when I tested it - its such a simple routine, not much could go wrong really.

 

Could you post an example and I'll see if there is another issue at fault. :)

 

Have just retested it on my machine - and no layers are changed, all lines are converted to polylines.

Posted

Here is a file of one of our drawings. the lines needed to be polyedited are already made in to polylines so you will have to explode it. Note there are certain layers (cab lines, text, sqft, etc) that are not a concern. it's all the ones that start with "route".

exampledrawing.dxf

Posted

Might my favorite command, BOUNDARY, be of any use in this instance?

Posted

Ok, I can see what is happening - its because you have polylines which are touching on two different layers. - this is why the layers change - it moves them onto the same layer when they are joined.

Posted

Ok this will work:

 

(defun c:pljoin    (/ *error* varLst oldVars oLst plnum ss)

   ;;     --- Error Trap ---
   (defun *error* (msg)
   (mapcar 'setvar varLst oldVars)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ (strcat "\n" (strcase msg)))
   ) ;_  end if
   (princ)
   ) ; end of *error*

   (setq varLst  (list "CMDECHO" "PEDITACCEPT")
     oldVars (mapcar 'getvar varLst)
   ) ; end setq 

   ;;     --- Error Trap ---

   (vl-load-com)
   (vlax-for l
       (vla-get-Layers
           (vla-get-ActiveDocument
           (vlax-get-acad-object)
           ) ;_  end vla-get-ActiveDocument
       ) ;_  end vla-get-Layers
   (setq oLst
        (cons (vla-get-Name l) oLst)
   ) ; end setq
   ) ; end vlax-for
   (setq oLst (reverse oLst))

   (setvar "cmdecho" 0)
   (setvar "PEDITACCEPT" 0)
   (setq plnum 0)
   (foreach lay oLst
   (if
       (setq ss (ssget "X"
               (list (cons 0 "LINE")
                 (cons 410 (getvar "ctab"))
                 (cons 8 lay)
               ) ;_  end list
            ) ;_  end ssget
       ) ;_  end setq
          (progn
          (command "_pedit" "M" ss "" "Y" "J" "0.0" "")
          (setq plnum (+ (sslength ss) plnum))
          ) ;_  end progn
   ) ;_  end if
   ) ;_  end foreach
   (*error* "")
   (alert (strcat (rtos plnum 2 0) " Polylines Created/Joined."))
   (princ)
) ;_  end defun


Posted

It's working a lot better. I really appreciate all this. but it looks like when setq ss it's only selecting lines, nothing with a curve to it. So it's still not polyediting the whole line (if you'll look along some of the walls for instance, which are red, most are straight lines, but there are a few areas where it is a curve instead. it will polyedit everything but those segments.). Thanks.

Posted

My apologies, as I read your thread now it does say to polyedit everything on each layer - not just the lines.

 

I shall update the LISP accordingly.

Posted

Try this:

 

(defun c:pljoin    (/ *error* varLst oldVars oLst plnum ss)

   ;;     --- Error Trap ---
   (defun *error* (msg)
   (mapcar 'setvar varLst oldVars)
   (if (= msg "")
       (princ "\nFunction Complete.")
       (princ (strcat "\n" (strcase msg)))
   ) ;_  end if
   (princ)
   ) ; end of *error*

   (setq varLst  (list "CMDECHO" "PEDITACCEPT")
     oldVars (mapcar 'getvar varLst)
   ) ; end setq 

   ;;     --- Error Trap ---

   (vl-load-com)
   (vlax-for l
       (vla-get-Layers
           (vla-get-ActiveDocument
           (vlax-get-acad-object)
           ) ;_  end vla-get-ActiveDocument
       ) ;_  end vla-get-Layers
   (setq oLst
        (cons (vla-get-Name l) oLst)
   ) ; end setq
   ) ; end vlax-for
   (setq oLst (reverse oLst))

   (setvar "cmdecho" 0)
   (setvar "PEDITACCEPT" 0)
   (setq plnum 0)
   (foreach lay oLst
   (if
       (setq ss (ssget "X"
               (list (cons 0 "LINE,ARC,LWPOLYLINE,POLYLINE")
                 (cons 410 (getvar "ctab"))
                 (cons 8 lay)
               ) ;_  end list
            ) ;_  end ssget
       ) ;_  end setq
          (progn
          (command "_pedit" "M" ss "" "Y" "J" "0.0" "")
          (setq plnum (+ (sslength ss) plnum))
          ) ;_  end progn
   ) ;_  end if
   ) ;_  end foreach
   (*error* "")
   (alert (strcat (rtos plnum 2 0) " Polylines Created/Joined."))
   (princ)
) ;_  end defun


Posted

No problem. I really appreciate all this.

Posted

Works perfectly. The change you made is what I thought might actually need to be changed, but I didn't want to go mucking around in your code. Thanks again.

Posted

sir,

 

so far.... i know now how to use lisp in cad.. but dont know yet how to create one.... and i tried the code that you posted....

 

firts pick line then second then the 2 line are automatic become a polyline...

 

is it possible that instead of picking 2 points or picking 2 lines...

you can use a window selection?

 

example if im going to convert many lines.. into polylines instead of picking.. i'll use window....

what i mean is, instead of the promt pick 1st line and 2nd line... is it possible that the promt is for pick window?

 

thanks in advance....:)

Posted

Something like this?

 

(defun c:pljoin    ()
   (if    (zerop (getvar "PEDITACCEPT"))
   (command "._PEDIT" "_M" (ssget) "" "_Y" "J" "0.0" "")
   (command "._PEDIT" "_M" (ssget) "" "J" "0.0" "")
   ) ;_  end if
   (princ)
) ;_  end defun

Posted

i have tried the code and it really works... instead of picking

 

its now window...

 

and it fasten everytime i convert a line into polyline....

 

thanks.. a lot Mr. Lee Mac....:)

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...