harinezumi Posted September 3, 2019 Posted September 3, 2019 (edited) Hello, I have the attached "layerSample" block that has a field that outputs the name of the layer in wich it's placed, and a sample line and solid (for color and transparency check). I need a routine that places one instance of the block in every existing layer, spacing it vertically by 0.5 units, a sort of array where the objects have a different layer. This gives a nice printable layer list, usefull to create standards etcetera. Of course the possibility to alter the block name or the distance would be appreciated. As I'm new to autolisp can someone help me? This is the desired ouput: Thank you layerSample.dwg Edited September 3, 2019 by harinezumi grammar Quote
dlanorh Posted September 3, 2019 Posted September 3, 2019 (edited) Try this. The block "layerSample" must be present in the drawing. (defun c:test (/ *error* sv_lst sv_vals c_doc c_spc c_lyrs lyr_lst pt n_obj) (defun *error* ( msg ) (mapcar 'setvar sv_lst sv_vals) (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error occurred : " msg))) (princ) );end_defun *error* (setq sv_lst (list 'cmdecho 'osmode) sv_vals (mapcar 'getvar sv_lst) c_doc (vla-get-activedocument (vlax-get-acad-object)) c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace)) c_lyrs (vla-get-layers c_doc) );end_setq (mapcar 'setvar sv_lst '(0 0)) (vlax-map-collection c_lyrs '(lambda (x) (setq lyr_lst (cons (vlax-get-property x 'name) lyr_lst)))) (setq pt (getpoint "\nSelect Insertion point : ") lyr_lst (vl-sort lyr_lst '<) );end_setq (foreach lyr lyr_lst (setq n_obj (vla-insertblock c_spc (vlax-3d-point pt) "layerSample" 1 1 1 0)) (vlax-put-property n_obj 'layer lyr) (setq pt (mapcar '+ pt '(0.0 -300.5 0.0))) );end_foreach (vla-regen c_doc acallviewports) (mapcar 'setvar sv_lst sv_vals) (princ) );end_defun Edited September 3, 2019 by dlanorh Typing error in code 1 Quote
harinezumi Posted September 3, 2019 Author Posted September 3, 2019 (edited) 3 hours ago, dlanorh said: Try this. The block "layerSample" must be present in the drawing. Great! it works as expected, thank you very much. I had to do it manually in each architect's studios where I went. I tryied to study the code but when I see vla/vlax stuff I get lost. I should start again from the basics. Thank you so much! Edited September 3, 2019 by harinezumi Quote
dlanorh Posted September 3, 2019 Posted September 3, 2019 I have attached a commented version if that helps you to understand what each bit does. BlockEveryLayer-commented.lsp Quote
BIGAL Posted September 4, 2019 Posted September 4, 2019 On the same theme prints out blocks in a pattern. block insert.lsp 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.