TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: rhino on April 07, 2009, 12:45:11 PM
-
Hellos,
I,ve come up with this code to set up layers in a drawing for a routine that draws a layout plan.
(defun lay_man2 (/ acadobject lay_tbl lay_list clr_list)
(vl-load-com)
(setvar "expert" 3)
(command "_-linetype" "load" "center" ""
"load" "hidden" "" ""
)
(princ)
(setq activedoc (vla-get-activedocument (vlax-get-acad-object))
lay_tbl (vla-get-layers activedoc)
lay_list '("BRACING" "CL" "GRID" "TEXT" "STEEL" "PPA" "HATCH" "WALL")
clr_list '(("BRACING" . 32) ("CL" . 8) ("GRID" . 9) ("TEXT" . 4) ("STEEL" . 3) ("PPA" . 2) ("HATCH" . 8) ("WALL" . 8))
)
(foreach n lay_list (vla-add lay_tbl n));vlax-for does not work here for some reason :|
(vlax-for n lay_tbl (vla-put-LineWeight n 0));foreach wont work here :D
(vla-put-color (vla-item lay_tbl "BRACING") (cdr (assoc "BRACING" clr_list)))
(vla-put-color (vla-item lay_tbl "CL") (cdr (assoc "CL" clr_list)))
(vla-put-color (vla-item lay_tbl "GRID") (cdr (assoc "GRID" clr_list)))
(vla-put-color (vla-item lay_tbl "TEXT") (cdr (assoc "TEXT" clr_list)))
(vla-put-color (vla-item lay_tbl "STEEL") (cdr (assoc "STEEL" clr_list)))
(vla-put-color (vla-item lay_tbl "PPA") (cdr (assoc "PPA" clr_list)))
(vla-put-color (vla-item lay_tbl "HATCH") (cdr (assoc "HATCH" clr_list)))
(vla-put-color (vla-item lay_tbl "WALL") (cdr (assoc "WALL" clr_list)))
(vla-put-linetype (vla-item lay_tbl "GRID") "CENTER")
(vla-put-linetype (vla-item lay_tbl "BRACING") "HIDDEN")
(setvar "expert" 0)
); end lay_man 2 - using Visual Lisp Code
question:
Is it possible to use the association list to set the colours of each layer in the layer table with just 1 or 2 calls to 'vla-put-color' bla bla? :|
cheers!
-
Try something like this:
(defun lay_man2 (/ lay_list lay_tbl vlay)
(vl-load-com)
(setvar "expert" 3)
(command "_-linetype" "load" "center" "" "load" "hidden" "" "")
(princ)
(setq lay_tbl (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
lay_list '(("BRACING" . 32)
("CL" . 8)
("GRID" . 9)
("TEXT" . 4)
("STEEL" . 3)
("PPA" . 2)
("HATCH" . 8)
("WALL" . 8)
)
)
(foreach n lay_list
(if (setq vlay (vla-add lay_tbl (car n)))
(vla-put-color vlay (cdr n))
)
)
(setvar "expert" 0)
) ; end lay_man 2 - using Visual Lisp Code
-
Try something like this:
(defun lay_man2 (/ lay_list lay_tbl vlay)
(vl-load-com)
(setvar "expert" 3)
(command "_-linetype" "load" "center" "" "load" "hidden" "" "")
(princ)
(setq lay_tbl (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
lay_list '(("BRACING" . 32)
("CL" . 8)
("GRID" . 9)
("TEXT" . 4)
("STEEL" . 3)
("PPA" . 2)
("HATCH" . 8)
("WALL" . 8)
)
)
(foreach n lay_list
(if (setq vlay (vla-add lay_tbl (car n)))
(vla-put-color vlay (cdr n))
)
)
(setvar "expert" 0)
) ; end lay_man 2 - using Visual Lisp Code
Thank you Ron, just what I wanted to achieve!
Cheers!
-
Glad to help :-)
-
this should eliminate the need to change the expert variable (quick & dirty, not tested).
(command "_.linetype")
(foreach x (list "Center" "Hidden")
(if (tblsearch "ltype" x)
(command "_load" x "_y" "")
(command "_load" x "")
)
)
(command "")
-
this should eliminate the need to change the expert variable (quick & dirty, not tested).
(command "_load" x "")
thanks alan - was oblivious to the 'load' command :ugly:
cheers!
-
Hi,
Maybe it's a little late, but here is my take on this thread. I've put together something a little bit more flexible and I think that this approach is also easier to further develop (like adding some other stuff to these layers), if the same approach on structuring the data and to apply it to the objects is maintained. Hope it's useful:
;;;=============================================================
(defun mylayman (ltypelist laydatalist / activedoc ltypes layer)
(setq activedoc
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(setq ltypes (vla-get-linetypes activedoc))
(defun ltypeisloaded (ltypename)
(not
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-item
(list ltypes ltypename)
)
)
)
)
(defun loadltype (ltypename)
(not
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-load
(list
ltypes
ltypename
(if (= (getvar 'measurement) 0)
"acad.lin"
"acadiso.lin"
)
)
)
)
)
)
(mapcar
'(lambda (x)
(if (not (ltypeisloaded x))
(if (not (loadltype x))
(prompt
(strcat
"\nThe linetype "
(strcase x)
" could not be loaded."
)
)
)
)
)
ltypelist
)
(mapcar
'(lambda (x)
(if
(not
(vl-catch-all-error-p
(setq layer
(vl-catch-all-apply
'vla-add
(list
(vla-get-layers activedoc)
(car x)
)
)
)
)
)
(vla-put-color layer (cdr x))
(prompt
(strcat
"\nThe layer "
(strcase (car x))
" could not be found."
)
)
)
)
laydatalist
)
(princ)
)
;;;=============================================================
;;;Usage:
;;;=============================================================
(mylayman
'("Center" "Hidden")
'(("BRACING" . 32)("CL" . 8)("GRID" . 9)("TEXT" . 4)("STEEL" . 3)("PPA" . 2)("HATCH" . 8)("WALL" . 8))
)
;;;=============================================================
-
Thanks Constantin - learnt quite a bit from your code...
cheers! :kewl:
-
Thanks Constantin - learnt quite a bit from your code...
You're welcome. I forgot to mention the fact that if you don't want the two function to be exposed outside of your main routine you could declare them as local:
(defun mylayman (ltypelist laydatalist / activedoc ltypeisloaded loadltype ltypes layer)
and of course, if you want to have them available for any other function, you could move them to your custom utilities and tools file. Hope I made my self clear.
Regards,
horsey :)