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

Change width of all polylines on a specified layer using script?

8 REPLIES 8
Reply
Message 1 of 9
tmblackflag
4752 Views, 8 Replies

Change width of all polylines on a specified layer using script?

Hello,

 

I need to be able to grab all polylines and change global width at once. This is a repetitve task that i have created a button for. I am trying to use this but it is not working. It gets hung up on me wanting to manually select the polylines when i thought i grabbed them with the first line.

 

(ssget "X" '((8 . "LayerName")))
(command "PEDIT" "w" "9")

8 REPLIES 8
Message 2 of 9
_Tharwat
in reply to: tmblackflag

Be careful to have your layer name is unlocked .

 

 

(Defun c:Test  (/ ss)
  (if (setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Layername"))))
    (command "_.pedit" "_m" ss "" "w" 9 ""))
  (princ))

 



Message 3 of 9
Kent1Cooper
in reply to: _Tharwat


@_Tharwat wrote:

.... 

(Defun c:Test  (/ ss)
  (if (setq ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Layername"))))
    (command "_.pedit" "_m" ss "" "w" 9 ""))
  (princ))

 


If you ever use 3D Polylines, you'll need to make that more sophisticated.  I find that with a selection of multiple Polylines, if any of them are 3D, the Width option is not offered, and the "w" will result in an invalid-option message, even if there are 2D and/or LW Polylines in the selection that width can be assigned to.

Kent Cooper, AIA
Message 4 of 9
_Tharwat
in reply to: Kent1Cooper

You are right Kent , 3dpolylines should be wxcluded from the selection set of the 2d polylines , so here it goes .

 

To OP , Don't forget to change the layer name to meet your needs .

 

(Defun c:Test (/ s ss sn i)
  (if (setq s  (ssadd)
        ss (ssget "_x" '((0 . "*POLYLINE") (8 . "LayerName")))
      )
    (progn
      (repeat (setq i (sslength ss))
    (setq sn (ssname ss (setq i (1- i))))
    (if (not (eq (cdr (assoc 100 (reverse (entget sn))))
             "AcDb3dPolyline"
         )
        )
      (ssadd sn s)
    )
      )
      (if (> (sslength s) 0)
    (command "_.pedit" "_m" s "" "w" 9 "")
      )
      (princ "\n .... ")
      (princ (strcat "Number of Polylines changed : "
             " < "
             (itoa (sslength s))
             " > "
         )
      )
    )
    (princ "\n Couldn't find any 2D polyline !!")
  )
  (princ)
)

 

Message 5 of 9
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

....

If you ever use 3D Polylines, you'll need to make that more sophisticated.  ... if any of them are 3D, the Width option is not offered, and the "w" will result in an invalid-option message....


Another way to go about it:

 

(foreach
  x
  (mapcar 'cadr ;; entity names in a list
    (ssnamex (ssget "X" '((0 . "*POLYLINE") (8 . "YourLayerName"))))
  )
  (if (/= (substr (cdr (assoc 100 (reverse (entget x)))) 5 1) "3")
    (vla-put-ConstantWidth (vlax-ename->vla-object x) YourWidth)
  )
)

 

to which, of course, you can also add a report on how many it did, as _Tharwat did.

 

I actually tried that hoping that maybe you could not bother to check whether any were 3D -- that maybe it would just ignore those.  But no, it gives an error if you try to "put" that property onto something that doesn't have it.  You could check for (vlax-property-available-p) instead of the (assoc 100) approach, but I think it would take more code, including presumably storing of the vla-object conversion in a variable name, since you would need to use it twice as a vla object [to check whether it has that property, and if so, to put a value on it].

Kent Cooper, AIA
Message 6 of 9
Ian_Bryant
in reply to: Kent1Cooper

Hi,

you can use vl-catch-all-apply to ignore 3D polylines e.g.

 

(if (setq ss (ssget "X" '((0 . "*POLYLINE") (8 . "YourLayerName"))))
   (foreach
      x (mapcar 'cadr (ssnamex ss))
     (vl-catch-all-apply
          'vlax-put-property
          (list  (vlax-ename->vla-object x) 'ConstantWidth YourWidth)
     )  
   )
)

 

Ian

 

 

Message 7 of 9
devitg
in reply to: Ian_Bryant

A way to exclude  3dpolyline  can be using this filter 

 

 

(if (setq s  (ssadd)
        ss (ssget "_x" '((0 . "*POLYLINE") (8 . "LayerName") ( 100 . "~AcDb3dPolyline"  ))
      )

~ (tilde)
 If it is the first character in the pattern, it matches anything except the pattern

 

 

 

 

Message 8 of 9

can anybody please explain what is the meaning of these lines

 

 

(setq ss (ssget ":S:E" '((0 . "LWPOLYLINE") (-4 . "<>") (43 . 0))))

 

 

Message 9 of 9


@rajeshkumar16484 wrote:

can anybody please explain what is the meaning of these lines

  

(setq ss (ssget ":S:E" '((0 . "LWPOLYLINE") ))

  


setq ss ; store selection set in variable ss
ssget ; get selection set
:S ; Allows single selection
:E ; within cursor's object selection pickbox
(0 . "LWPOLYLINE") ; of polyline (light pline)
(-4 . "<>") (43 . 0)) ; which has a constant width different than 0.

 

For more info see HERE and HERE

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

Post to forums  

Autodesk Design & Make Report

”Boost