How to batch redefine the selected block

How to batch redefine the selected block

skchui6159
Advocate Advocate
837 Views
9 Replies
Message 1 of 10

How to batch redefine the selected block

skchui6159
Advocate
Advocate

If there are the selected blocks, I want to update the blocks with other dwg (with same block name). (The block reference to other blocks.) Or, Can I get all block names from the selection?

skchui6159_1-1722494843858.png

 

skchui6159_0-1722494816883.png

skchui6159_3-1722495114119.png

Anyone help?

0 Likes
Accepted solutions (2)
838 Views
9 Replies
Replies (9)
Message 2 of 10

skchui6159
Advocate
Advocate

Also, How can i extract the all block names from the selected blocks?

0 Likes
Message 3 of 10

komondormrex
Mentor
Mentor
Accepted solution

check this

(defun c:get_block_names (/ insert_sset block_name block_list)
	(prompt "\nSelect inserts to get their names in list...")
	(if (setq insert_sset (ssget '((0 . "insert"))))
		(progn
			(foreach insert (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex insert_sset))))
				(if (not (member (setq block_name (vla-get-effectivename insert)) block_list))
					(setq block_list (cons block_name block_list))
				)
			)
			(print (acad_strlsort block_list)) 
		)
	)
	(princ)
)
0 Likes
Message 4 of 10

skchui6159
Advocate
Advocate

Thank a lot.

I also want to select the blocks by entering the name, anyone help?

0 Likes
Message 5 of 10

skchui6159
Advocate
Advocate

Thanks you

0 Likes
Message 6 of 10

ec-cad
Collaborator
Collaborator

Here is an old Lisp just for that.

You can add it as a 'callable' routine within any other Lisp program.

Just do :

(C:GBBN)

within your existing Lisp, to get a selection set 'ss' with your blocks in it.

 

ECCAD

 

 

;; Lisp name: GBBN.lsp Get Block By Name
;; Notes:
;;  Type GBBN to run this lisp
;;  IF it finds blocks by that name, will save that selection in variable 'ss'
;;  IF not, just prompts - Could not find any blocks by that name
;;  IF found, ss will exist and you can do whatever else you need to do with that selection set

(defun C:GBBN ( / bn)
 (setq bn "" ss nil)
 (setq bn (strcase (getstring "\nBlock Name to find ?")))
  (if bn
   (progn
    (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 bn))))
     (if ss
      (progn
        (setq N (sslength ss)); Number of Blocks by that name
        (prompt (strcat "\nFound " (itoa N) " blocks by that name"))
      ); progn
      (prompt "\nCould not find any blocks by that name")
     ); if
    ); progn
   ); if
 (princ)
); function

 

 

0 Likes
Message 7 of 10

skchui6159
Advocate
Advocate

Thanks, but can the lisp can make the selection of the search object?

0 Likes
Message 8 of 10

Kent1Cooper
Consultant
Consultant

@skchui6159 wrote:

.... can the lisp can make the selection of the search object?


This seems to be wandering from the original Topic, but....

 

If what you want is to select a Block [rather than type in a Block name] and have AutoCAD make a selection of all Blocks of that name like the results of Message 6, you don't need any routine.  Use the SELECTSIMILAR command.

 

If that is not what you are describing, please explain in more detail.

Kent Cooper, AIA
0 Likes
Message 9 of 10

ec-cad
Collaborator
Collaborator
Accepted solution

"Thanks, but can the lisp can make the selection of the search object?"

 

The Lisp already has 'selected' all the blocks by that name, held in a local variable called 'ss

If you want to explore the contents of that selection set, you can check the first one by:

(setq blk (entget (ssname ss 0)))

That will echo on the command line, a 'list' of that block.

With a little more programming, it could make changes to those blocks, such as change Layer, insert

position, scale, etc.

 

ECCAD

0 Likes
Message 10 of 10

skchui6159
Advocate
Advocate

Thank you! It is helpful. Sorry, I am missing the "ss" variable for the selection. Thank for your help.

0 Likes