Jump to content

help: lisp to place a sample block in each existing layer


harinezumi

Recommended Posts

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:

image.png.1a010bac3577c0ec44dc4fab38d91c99.png

Thank you

layerSample.dwg

Edited by harinezumi
grammar
Link to comment
Share on other sites

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 by dlanorh
Typing error in code
  • Thanks 1
Link to comment
Share on other sites

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 by harinezumi
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...