Jump to content

Make Block Reference Names Unqiue


wef

Recommended Posts

Hello,

I was getting a drawing that I have to modify. The problem is, that in this drawing are several block references with the name.
I.e. I have about 100 block references calling "WcLux" . Is there a possibility to make the name of the block reference unique with a script:

 

WcLux_1, WcLux2, ... WcLux100

 

Thx

 

Frank

 

 

Link to comment
Share on other sites

This  should work. if their are attributes might have to use burst instead of explode.

 

--edit

Also doesn't check for bylayer or byblock colors so things might change after explode.

;;----------------------------------------------------------------------------;;
;; make unique block names
(defun C:UB (/ blk blkname ss en name ss1 ptslst LL UR MPT)
  (vl-load-com)
  (setq ss1 (ssadd)
        blk (car (entsel "\nSelect Block")) ;no error testing so make sure you select a block
        blkname (cdr (assoc 2 (entget blk)))
        i 1
  )
  (if (and (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname) '(410 . "Model")))) (> (sslength ss) 1))
    (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq LastEnt (entlast))
      (setq LL nil UR nil MPT nil ptslst nil)
      (command "_.Explode" blk)
      (if (setq en (entnext LastEnt))
        (while en
          (ssadd en SS1)
          (setq obj (vlax-ename->vla-object en))
          (vla-getboundingbox obj 'minpt 'maxpt)
          (setq ptslst (cons (vlax-safearray->list minpt) ptslst)
                ptslst (cons (vlax-safearray->list maxpt) ptslst)
          )
          (setq en (entnext en))
        )
      )
      (setq LL (apply 'mapcar (cons 'min ptslst))
            UR (apply 'mapcar (cons 'max ptslst))
            MPT (mapcar '/ (mapcar '+ LL UR) '(2 2 2))
      )
      (while (tblsearch "BLOCK" (strcat blkname "-" (itoa i)))
        (setq i (1+ i))
      )
      (setq name (strcat blkname "-" (itoa i)))
      (vl-cmdf "_.Block" name "_non" MPT SS1 "")
      (vl-cmdf "_.Insert" name "_non" MPT 1 1 0)
    )
  )
)

 

 

Edited by mhupp
Link to comment
Share on other sites

If you don't care what the name is this would make them unique:

(defun c:ub (/ b s)
  (if (and (setq b (car (entsel "\nSelect Block")))
	   (= "INSERT" (cdr (assoc 0 (entget b))))
	   (setq s (ssget "_X" (list '(0 . "INSERT") (assoc 2 (entget b)))))
      )
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (vla-converttoanonymousblock (vlax-ename->vla-object e))
    )
  )
  (princ)
)
(vl-load-com)

 

Edited by ronjonp
  • Like 1
Link to comment
Share on other sites

I wonder if this can be modified:

https://autocadtips1.com/2011/05/03/autolisp-copy-block-with-new-name/

 

It copies a selected block, lets you choose a new name and insert that as a new block.

 

Perhaps use RonJonPs start, select the block to rename, ssget all the blocks of that name, then a loop and passing insertion point, new name and block from selection set to this, copy and rename a lot of blocks then delete everything in the original selection set

 

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...