Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change widths of polylines on layer by selecting object on layer

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mpa-la
1222 Views, 5 Replies

Change widths of polylines on layer by selecting object on layer

I am a lisp cutter and paster, not a writer.  I tried to use another routine to make one that allows you to select an object on a layer, then it changes the width of all polylines on that layer to 0.  My lisp works unless there are only polylines on the layer, then it gets stuck.  I made a second lisp that works for that condition.  It's super annoying though, not knowing which one is going to work until you try it.  I know there's a better solution, I just don't know how to do it.

 

Here's the one that works if not all objects are polylines so you can have a laugh 🙂  Thanks!

 

(defun c:w0 (/ sca scb scc)
(setq sca (car (entsel "Pick an object on the layer to reduce width to 0:")))(terpri)
(if sca (progn
(setq sca (entget sca))
(setq scb (cdr (assoc 8 sca)))(prompt "Layer name is ")(prin1 scb)(terpri)
(setq scc (ssget "X" (list (cons 8 scb))))(prompt "Press ENTER")))
(command "pedit" "m" "p" "" "w" "0" "")
(princ)
)

5 REPLIES 5
Message 2 of 6
dlanorh
in reply to: mpa-la

Try this

 

(defun c:pw0 (/ sca lyr ss ent)
  (setq sca (car (entsel "Pick an object on the layer to reduce width to 0:")))
  (cond (sca 
          (setq lyr (cdr (assoc 8 (entget sca))))
          (princ (strcat "\n" "Layer name is " lyr))
          (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE") (cons 8 lyr))))
	  (repeat (setq cnt (sslength ss))
	    (setq ent (ssname ss (setq cnt (1- cnt))))
            (command "pedit" ent "_W" "0" "")
	  )  
        )
  )      
(princ)
)

You can specify only polylines in the ssget filter, and you then need to loop through each polyline in the selection set.

I am not one of the robots you're looking for

Message 3 of 6
Moshe-A
in reply to: mpa-la

@mpa-la  hi,

 

check this code.

 

enjoy

moshe

 

 

(defun c:w0 (/ pick lay ss)
 (if (setq pick (entsel "\nPick a wide polyline to reduce width to 0.0: "))
  (progn
   (setq lay (cdr (assoc '8 (entget (car pick)))))
   (prompt (strcat "\nLayer name is " lay))
   (if (setq ss (ssget "_x" (list '(0 . "lwpolyline") (cons '8 lay))))
    (command "._pedit" "_m" "_si" ss "_width" 0 "")
   )
  )
 )

 (princ)
)
Message 4 of 6
Kent1Cooper
in reply to: mpa-la

Is it affected by changing the value in the PEDITACCEPT System Variable?  The only thing I can think of is that if that's set to require you to confirm that you want to convert Lines and Arcs into Polylines [PEDITACCEPT = 0], then it won't  ask that if there are nothing but  already-Polylines in the drawing.  Is that what the:

  (prompt "Press ENTER")

is intended for, to accept the <Y>es default answer to convert non-Polylines?  But if that's what's happening, it doesn't look to me like there's the right command sequence within the Pedit command for accepting that, so I'm not sure.

 

Try removing that prompt, and setting PEDITACCEPT to 1.

 

I would also move the Pedit command inside  the (progn) 'then'-expression wrapper.

 

You can also restrict it to "see" only  LWPolylines [assuming that's the variety you're talking about] in the selection, so no other entity types can complicate things, and that conversion question will never be asked no matter what the PEDITACCEPT setting is:
  (setq scc (ssget "X" (list (cons 8 scb) '(0 . "LWPOLYLINE"))))

 

Kent Cooper, AIA
Message 5 of 6
mpa-la
in reply to: Moshe-A

Pefect!!!  Thanks so much!

Message 6 of 6
Kent1Cooper
in reply to: mpa-la

If there might be a large number of Polylines on a given Layer, something like this could be faster, since doing things with (command) functions in quantity can be comparatively slow:

(vl-load-com); if needed
(defun c:PLW0 (/ esel lay ss n) (if (setq esel (entsel "\nObject on Layer to force Polyline widths to 0: ")) (progn ; then (setq lay (cdr (assoc 8 (entget (car esel))))) (prompt (strcat "\nThe Layer name is " lay ".")) (if (setq ss (ssget "_X" (list '(0 . "*POLYLINE") (cons 8 lay)))) (repeat (setq n (sslength ss)) (vla-put-ConstantWidth (vlax-ename->vla-object (ssname ss (setq n (1- n)))) 0) ); repeat ); if ); progn ); if (princ) ); defun
Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost