Lisp - Adding multiple selection sets

Lisp - Adding multiple selection sets

kenneth.smithV6QLC
Enthusiast Enthusiast
2,195 Views
5 Replies
Message 1 of 6

Lisp - Adding multiple selection sets

kenneth.smithV6QLC
Enthusiast
Enthusiast

Good afternoon,

I am looking for a way to modify Auto Number Lisp to have a user-selected object instead of "_x". So far I have found how to initiate the user-input via Get Basic Block Name, but it is not recognizing the name after swapping "_11x17" for the "bname" set. Is there a way to have one 'user selected object' to retrieve both the name and object type (block in this case)?

 

In other words, I am looking to replace "_x" in "Auto Number Lisp" with a user selection on-screen and still run the lisp. The purpose is this lisp works when the block has the same name between every drawing, but though the layout is identical, our blocks are from different sources and usually have different block names.

 

Secondly (and on the thought of the previous paragraph), could it be possible to rename a block to something specific upon clicking a block?

(defun c:SHEETNO  (/ adoc bname layoutname ss1 ent entdata)
 (setq bname (vla-get-bname (setq adoc (vla-get-activedocument (vlax-get-acad-object)))))
 (setq bname (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))
;(if (setq ss1 (ssget "_x" '((0 . "INSERT") (2 . "_11x17"))))
  (mapcar
   '(lambda (x)
     (setq ent     (cadr x)
           entdata (entget ent))
     (while (/= (cdr (assoc 0 entdata)) "SEQEND")
      (cond ((= "SHEETNO" (cdr (assoc 2 entdata)))
             (vlax-for y  bname
              (cond ((=
                     (vla-get-name (vla-objectidtoobject adoc (vla-get-ownerID (vlax-ename->vla-object (cdr (assoc 330 entdata))))))
                     (vla-get-name (vla-get-block y)))
                    (entmod (subst (cons 1 (itoa (vla-get-taborder y))) (assoc 1 entdata) entdata)))
                    (T ())))
              ))
            (setq entdata (entget (setq ent (entnext ent))))))
     (ssnamex ss1))
  "No titleblocks found!")
 (princ))

 

Thank you.

Please be kind, rewind your exploding. Do not explode hatching, dimensions or text. Think of your fellow drafters! 🙂

https://www.youracclaim.com/badges/9aa4a1d5-0d02-4888-be6f-ed8f0653d8ad/public_url
0 Likes
Accepted solutions (1)
2,196 Views
5 Replies
Replies (5)
Message 2 of 6

natasha.l
Alumni
Alumni

Hello @kenneth.smithV6QLC

 

Welcome back & thanks for posting. 

 

Here is a developers guide on the AutoLISP  options. I will move this post to the LISP forum for you. 

Please "Accept Solution" if a reply or replies have helped resolve the issue or answered your question, to help others in the community.

 

 

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this [untested]:

(defun c:SHEETNO  (/ adoc bname layoutname ss1 ent entdata)
 (setq adoc (vla-get-activedocument (vlax-get-acad-object))); <-- I also altered this line
 (setq bname (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))
 (if (setq ss1 (ssget "_x" (list '(0 . "INSERT") (cons 2 bname))))
(mapcar ....

Since the 'bname' variable requires evaluation  to be used in the (ssget) filter list, that list can't be a "quoted" one with the preceding apostrophe, but must use the (list) function explicitly, and put that name together with the 2 for the Block name, using the (cons) function.  [The object-type entry inside the filter list can be a quoted list, since that will be contained raw in objects' entity data, and doesn't contain anything needing evaluating.]

 

EDIT:  That's assuming that, as with the original, you want to find all Blocks of the same name.  Your description in Message 1 makes me wonder, though -- is that what you're after, or just one?

Kent Cooper, AIA
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@kenneth.smithV6QLC wrote:

.... could it be possible to rename a block to something specific upon clicking a block? ....


 

For that, try RenameBlock.lsp with its RB command, available >here<.

Kent Cooper, AIA
0 Likes
Message 5 of 6

kenneth.smithV6QLC
Enthusiast
Enthusiast

...is that what you're after, or just one?


The hope is to pick a single block named "TitleBlock" then have the script and run similarly to the original (finding all occurrences). With the code replacement, there is a return "error: bad argument type: vla-object collection: "TitleBlock""

Please be kind, rewind your exploding. Do not explode hatching, dimensions or text. Think of your fellow drafters! 🙂

https://www.youracclaim.com/badges/9aa4a1d5-0d02-4888-be6f-ed8f0653d8ad/public_url
0 Likes
Message 6 of 6

kenneth.smithV6QLC
Enthusiast
Enthusiast
(defun c:somefunc  (/ adoc bname layouts layoutname ss1 ent entdata)
 (setq layouts (vla-get-layouts (setq adoc (vla-get-activedocument (vlax-get-acad-object)))))
 (setq bname (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))
 (if (setq ss1 (ssget "_X" (list '(0 . "INSERT") (cons 2 bname))))
  (mapcar...
(vlax-for y layouts...

 

Looked back at the original code and realized I had accidentally left off one line or had modified it so heavilly it was lost. Adding it back in plus what you replied with, @Kent1Cooper, it is working as hoped! Many kudos. Thank you!

Please be kind, rewind your exploding. Do not explode hatching, dimensions or text. Think of your fellow drafters! 🙂

https://www.youracclaim.com/badges/9aa4a1d5-0d02-4888-be6f-ed8f0653d8ad/public_url
0 Likes