LISP modification - multiple selection

LISP modification - multiple selection

Anonymous
Not applicable
2,018 Views
4 Replies
Message 1 of 5

LISP modification - multiple selection

Anonymous
Not applicable

Hi all,

 

I have found this lisp in this forum but currently it does not allow me to have a multiple selection.

Quite new with this lisp stuff btw. Any ways to have this lisp modified to allow multitple selections?

 

;;  BELTB.lsp
;;  = change all Block Entities of definitions of a selected block and all
;;    nested block definitions within it to the Layer of the Top-level Block
;;  Kent Cooper, 18 November 2014

(vl-load-com)
(defun C:BELTB (/ *error* doc nametolist blkss inc blk lay blknames ent edata)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (vla-endundomark doc)
    (princ)
  ); defun - *error*

  (defun nametolist (blk / blkobj blkname); get Block name and put it into list of names
    (if (= (logand (cdr (assoc 70 (entget blk))) 4) 0) ; not an Xref
      (progn
        (setq
          blkobj (vlax-ename->vla-object blk)
          blkname
            (vlax-get-property blkobj
              (if (vlax-property-available-p blkobj 'EffectiveName) 'EffectiveName 'Name)
                ; to work with older versions that don't have dynamic Blocks
            ); ...get-property & blkname
        ); setq
        (if
          (not (member blkname blknames)); name not already in list
          (setq blknames (append blknames (list blkname))); then -- add to end of list
        ); if
      ); progn
    ); if
  ); defun -- nametolist

  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc); = Undo Begin

  (if (setq blkss (ssget "_+.:S" '((0 . "INSERT")))); User selection of a Block/Minsert/Xref
    (progn ; then
      (setq
        blk (ssname blkss 0); top-level Block insertion
        lay (cdr (assoc 8 (entget blk))); Layer it's inserted on
      ); setq
      (nametolist blk); put it in blknames list
      (while (setq blk (car blknames)); as long as there's another Block name in list
        ;; done this way instead of via (repeat) or (foreach), so it can add nested Blocks' names to list
        (setq ent (tblobjname "block" blk)); Block definition as entity
        (while (setq ent (entnext ent)); then -- proceed through sub-entities in definition
          (setq edata (entget ent)); entity data list
          (if (member '(0 . "INSERT") edata) (nametolist ent)); if nested Block, add name to end of list
          (entmod (subst (cons 8 lay) (assoc 8 edata) edata)); change to top-level Block's Layer
        ); while -- sub-entities
        (setq blknames (cdr blknames)); take first one off
      ); while
      (command "_.regen")
    ); progn
    (prompt "\nNo Block(s) selected.")
  ); if [user selection]

  (vla-endundomark doc); = Undo End
  (princ)
); defun

TIA

0 Likes
Accepted solutions (1)
2,019 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

That could certainly be done, but questions arise....

 

Suppose you have a Block that is Inserted on more than one Layer in the drawing, and you select more than one of those?  The routine would change everything in them to the Layer that one of those is Inserted on, and then later change all of that all over again, to the Layer another is Inserted on.

 

Suppose you have a Block that is nested in more than one top-level Block definition, and you select more than one top-level Block that contain that nested Block?  The routine would change everything in that nested Block to the Layer that the last-processed top-level Block is on, which would change it all within other Blocks it's nested in.

 

Can you come up with criteria to limit or otherwise account for such conflicts?

Kent Cooper, AIA
0 Likes
Message 3 of 5

Anonymous
Not applicable

I have been using this routine on anonymous blocks (exported on plant3D) so there will be no more than one instance of each blocks in the drawing.

 

I hope that answers your questions. Thanks.

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

I had forgotten -- this has come up before.  See >this<.

Kent Cooper, AIA
0 Likes
Message 5 of 5

Anonymous
Not applicable

Works perfectly in my part. Thanks a heap sir.

0 Likes