Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
convert layers linetype
« previous
next »
Print
Pages: [
1
] |
Go Down
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
Logged
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]
(
defun
c:l2c
(
/
doc
)
(
vl-load-com
)
(
vlax-for
lyr
(
vla-get-layers
(
setq
doc
(
vla-get-activedocument
(
vlax-get-acad-object
)
)
)
)
(
vlax-put
lyr 'linetype
"CONTINUOUS"
)
)
(
vlax-invoke
doc 'regen acallviewports
)
(
princ
)
)
Logged
Dlanor
http://www.theswamp.org/donate.html
PM
Guest
Re: convert layers linetype
«
Reply #2 on:
September 04, 2020, 07:51:27 AM »
thank you Dlanor
Logged
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]
(
defun
rh:l2c
(
lst
/
doc
)
(
setq
lst
(
mapcar
'
strcase
lst
)
)
(
vlax-for
lyr
(
vla-get-layers
(
setq
doc
(
vla-get-activedocument
(
vlax-get-acad-object
)
)
)
)
(
if
(
vl-position
(
strcase
(
vlax-get
lyr 'name
)
)
lst
)
(
vlax-put
lyr 'linetype
"CONTINUOUS"
)
)
)
(
vlax-invoke
doc 'regen acallviewports
)
)
Logged
Dlanor
http://www.theswamp.org/donate.html
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]
(
vlax-for
lyr
(
vla-get-layers
(
setq
doc
(
vla-get-activedocument
(
vlax-get-acad-object
)
)
)
)
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]
(
setq
*
acadobject
*
(
cond
(
*
acadobject
*
)
(
(
vlax-get-acad-object
)
)
)
*
activedocument
*
(
cond
(
*
activedocument
*
)
(
(
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]
(
setq
*
acadobject
*
(
cond
(
*
acadobject
*
)
(
(
vlax-get-acad-object
)
)
)
*
activedocument
*
(
cond
(
*
activedocument
*
)
(
(
vla-get-activedocument
*
acadobject
*
)
)
)
$lay
-
col$
(
cond
(
$lay
-
col$
)
(
(
vla-get-layers
*
activedocument
*
)
)
)
)
...
(
vlax-for
lyr $lay
-
col$ ...
EDIT: Fixed spelling error ("of").
«
Last Edit: September 04, 2020, 09:05:39 AM by John Kaul (Se7en)
»
Logged
TheSwamp.org
(serving the CAD community since 2003)
Member location map - Add yourself
Donate to TheSwamp.org
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
convert layers linetype