Author Topic: convert layers linetype  (Read 1103 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
convert layers linetype
« on: September 04, 2020, 03:09:17 AM »
Hi i have a big list of layers and want to change all linetype to continuous by default. Is any lisp code for this?

Thanks

Dlanor

  • Bull Frog
  • Posts: 263
Re: convert layers linetype
« Reply #1 on: September 04, 2020, 06:52:42 AM »
Try this, it currently does all layers in the drawing but can be adapted inside the for loop to work with checking if the layer name is in a list.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:l2c ( / doc)
  2.  
  3.     (vlax-put lyr 'linetype "CONTINUOUS")
  4.   )
  5.   (vlax-invoke doc 'regen acallviewports)
  6.   (princ)
  7. )
  8.  

PM

  • Guest
Re: convert layers linetype
« Reply #2 on: September 04, 2020, 07:51:27 AM »
thank you Dlanor

Dlanor

  • Bull Frog
  • Posts: 263
Re: convert layers linetype
« Reply #3 on: September 04, 2020, 08:38:29 AM »
I've converted it to a function. Just pass the function a list of layer name and it will convert the linetypes of those layers to "CONTINUOUS" ie (rh:l2c layerlist)

Code - Auto/Visual Lisp: [Select]
  1. (defun rh:l2c ( lst / doc)
  2.   (setq lst (mapcar 'strcase lst))
  3.     (if (vl-position (strcase (vlax-get lyr 'name)) lst) (vlax-put lyr 'linetype "CONTINUOUS"))
  4.   )
  5.   (vlax-invoke doc 'regen acallviewports)
  6. )
  7.  

JohnK

  • Administrator
  • Seagull
  • Posts: 10632
Re: convert layers linetype
« Reply #4 on: September 04, 2020, 08:56:11 AM »
Drive-by optimization.

Discussing your line #3.

Code - Auto/Visual Lisp: [Select]

which creates a variable ("doc") each iteration of the loop and is VERY inefficient and slow.

Consider the following small, but efficient, bit of code as a template for you to consider.

Code - Auto/Visual Lisp: [Select]
  1. (setq *acadobject*
  2.          (cond
  3.            (*acadobject*)
  4.            ((vlax-get-acad-object)))
  5.       *activedocument*
  6.          (cond
  7.            (*activedocument*)
  8.            ((vla-get-activedocument *acadobject*))) )

If you study this bit of code you can see the effency in it (hint: cond) which should lead you down the path of
Code - Auto/Visual Lisp: [Select]
  1. (setq *acadobject*
  2.          (cond
  3.            (*acadobject*)
  4.            ((vlax-get-acad-object)))
  5.       *activedocument*
  6.          (cond
  7.            (*activedocument*)
  8.            ((vla-get-activedocument *acadobject*)))
  9.          $lay-col$
  10.           (cond
  11.             ($lay-col$)
  12.             ((vla-get-layers *activedocument*))) )
  13. ...
  14.  
  15. (vlax-for lyr $lay-col$ ...
  16.  

EDIT: Fixed spelling error ("of").
« Last Edit: September 04, 2020, 09:05:39 AM by John Kaul (Se7en) »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org