CAD Forums > CAD General

Renumbering blocks?

(1/1)

hudster:
Doeds anyone have a lisp I can use to re-number blocks sequentially?

I have a load of grid references, inserted as attributes,  starting at 1 and ending in 76, I need to renumber in order.

Cheers for any help.

whdjr:
Here is an old one that I wrote to read multiple blocks, but you are welcome to modify and update as you see fit.

I could give you my new tool, but it a part of a larger program so it would be more difficult.

Usage:
It asks for a reference block(which needs to have the correct number value), then you select each block to renumber as you need.  As you select a block the number increments by one.

HTH,
 :D
--- Code: ---(vl-load-com)

(defun att (atts / num)
  (foreach for-item (vlax-safearray->list
     (vlax-variant-value
(vla-getattributes
 (vlax-ename->vla-object atts)
)
     )
   )
    (cond ((or (= (vla-get-tagstring for-item) "ROOM#")
      (= (vla-get-tagstring for-item) "DOOR#")
      (= (vla-get-tagstring for-item) "240-DOOR#")
      (= (vla-get-tagstring for-item) "999")
      (= (vla-get-tagstring for-item) "1")
  )
  (setq num (vla-get-textstring for-item))
 )
    )
  )
  num
)


(defun attup (atts num)
  (foreach for-item (vlax-safearray->list
     (vlax-variant-value
(vla-getattributes
 (vlax-ename->vla-object atts)
)
     )
   )
    (cond ((or (= (vla-get-tagstring for-item) "ROOM#")
      (= (vla-get-tagstring for-item) "DOOR#")
      (= (vla-get-tagstring for-item) "240-DOOR#")
      (= (vla-get-tagstring for-item) "999")
      (= (vla-get-tagstring for-item) "1")
  )
  (vla-put-textstring for-item num)
 )
    )
  )
  (vla-update (vlax-ename->vla-object atts))
)


(defun c:numinc (/ ent sel cnt)
  (setq ent (car (entsel "\nSelect reference block:  ")))
  (cond ((not ent) (princ "\nNothing selected.  *INVALID*"))
(T (setq cnt (att ent)))
  )
  (while ent
    (setvar "ErrNo" 0)
    (cond
      ((not
(setq sel (car (entsel "\nSelect attribute to update:  ")))
       )
       (if (/= 52 (getvar "ErrNo"))
(princ "\nNo object selected, please try again: ")
(progn
  (princ "\nRight click detected - Terminate program. ")
  (setq ent nil)
)
       )
      )
      (T (attup sel (itoa (1+ (atoi cnt)))))
    )
  )
  (princ)
)
--- End code ---

hudster:
thanks a lot, I modified it and it works great. :D

Navigation

[0] Message Index

Go to full version