Jump to content

Polyline Regeneration


Ocron

Recommended Posts

Hello,

 

The problem I have been having is trying to find a way to select all the polylines on my drawing, and then to turn the Ltype Regeneration to "ON" on all of them. I have a little experience with autolisp, but can't seem to get this to work.

 

This is basically what my lisp looks like right now, but for some reason when it gets to the "pedit" command it cannot use the "ss" for my selection and instead makes each letter command after that unknown. :(

 

(defun C:exd ()

(setq CE-SAV (getvar "cmdecho"))

(setvar "cmdecho" 0)

(setq ss (ssget "x" '((0 . "*polyline")) ))

(command "pedit" ss "" "l" "on" "")

 

(setq ss nil)

 

(setvar "cmdecho" CE-SAV)

(princ)

) ;_ end of defun

 

 

Please help me out if you can, cause this is frustrating the heck out of me. lol

 

Thank you

Link to comment
Share on other sites

This should work:

 

(defun C:exd (/ *error* vl ov ss) ;; Localise Variables!

 ;; Error Handler to Reset Sys Vars in case User hits Esc!
 
 (defun *error* (msg)
   (and ov (mapcar 'setvar vl ov))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 ;; Get Sysvars and store them

 (setq vl '("CMDECHO" "PEDITACCEPT") ov (mapcar 'getvar vl))

 ;; Set sys vars to what we want
 
 (mapcar 'setvar vl '(0 1))

 ;; Include IF statment to allow for a null SelectionSet

 (if (setq ss (ssget "_X" '((0 . "*POLYLINE"))))
   (command "_.pedit" "_M" ss "" "_L" "ON" ""))

 ;; Reset Sys Vars
 
 (mapcar 'setvar vl ov)
 (princ))

 

Please read the comments, if you have questions, just ask :)

 

Lee

Link to comment
Share on other sites

Lee Mac You are a god among men. lol

 

Thank you that worked perfectly.:D

 

Hehe thanks Ocron :D

 

After thinking about it, I suppose the code doesn't really need the error handler, as there is no pause for user input, but its good practice anyway, as we are tampering with Sys Vars. :)

 

Lee

Link to comment
Share on other sites

Actually it's good for me to see that and start using it. When I learned Lisp it was back during ACAD2004 and they didn't even teach us to do that. Most of it was Initget commands and such which was a pain. lol

Link to comment
Share on other sites

Actually it's good for me to see that and start using it. When I learned Lisp it was back during ACAD2004 and they didn't even teach us to do that. Most of it was Initget commands and such which was a pain. lol

 

Hehe, I always say the forums are by far the best place to learn :)

Link to comment
Share on other sites

Is this the same thing?

 

(defun c:Test (/ #SS)
 (and (setq #SS (ssget "_X" '((0 . "*POLYLINE"))))
      (foreach x (mapcar 'cadr (ssnamex #SS))
        (vl-catch-all-apply
          'vla-put-linetypegeneration
          (list (vlax-ename->vla-object x) :vlax-true)
        ) ;_ vl-catch-all-apply
      ) ;_ foreach
 ) ;_ and
 (princ)
) ;_ defun

Link to comment
Share on other sites

Actually, I think I could have scaled it down to this:

 

(defun c:Test (/ #SS)
 (and (setq #SS (ssget "_X" '((0 . "*POLYLINE"))))
      (foreach x (ssnamex #SS)
        (vl-catch-all-apply
          'vla-put-linetypegeneration
          (list (vlax-ename->vla-object (cadr x)) :vlax-true)
        ) ;_ vl-catch-all-apply
      ) ;_ foreach
 ) ;_ and
 (princ)
) ;_ defun

Link to comment
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
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...