Jump to content

Bcount in block Attribute?


Attila The Gel

Recommended Posts

Hello,

 

Anyone knows a way to put the total number of a block used in a drawing in the block itself?

 

This is what I'm trying to do:

 

Got this block called 'Border' with some attributes inside it.

I Used the block 'Border' 12 times.

So I would like to see the number '12' in each block.

and when I copy or insert another 'Border' in this drawing. All the blocks must contain 13 instead of 12.

And when I delete it must update (with regen or automatically, it doest really mather).

 

Anyone got an Idea?

I tried to find it in field but no success.

Link to comment
Share on other sites

Thx, Lee

 

It didn't work because after I select the block, this lisp asks to select a polyline and here's where it goes wrong:

 

Command: BLKUPD

 

Select Block:

Select Polyline:

>

Command:

Command:

BLKUPD

Select Block:

Select Polyline: ; error: bad argument type: lselsetp nil

 

could you moddify this lisp to do only the COUNT thing.

many thanx,

 

After this I have another question for you.

 

ps: LOL I have a feeling that Acad isn't complete without you :lol:.

 

Many thanks for the feedback :)

 

Hopefully this is more reliable:

 

;; Block Attribute Updater  by Lee McDonnell 06.07.2009

(defun c:blkUpd (/ ins wid hgt bEnt bObj
                  pEnt pObj MiP MaP win num )
 (vl-load-com)

 ;;<<  Tag Names must be Capitalised! >>
 (setq ins "COUNT")         ;; << Instances Tag
 (setq Wid "X-WIDTH")       ;; << Width Tag
 (setq Hgt "Y-HEIGHT")      ;; << Height Tag

 (if
   (and
     (setq bEnt
       (car (entsel "\nSelect Block: ")))
     (eq "AcDbBlockReference"
         (vla-get-ObjectName
           (setq bObj
             (vlax-ename->vla-object bEnt))))
     (eq (vla-get-HasAttributes bObj) :vlax-true)
     (setq pEnt
       (car (entsel "\nSelect Polyline: ")))
     (wcmatch
       (cdr (assoc 0 (entget pEnt))) "*POLYLINE"))
   (progn
     (vla-getBoundingBox
       (setq pObj
         (vlax-ename->vla-object pEnt)) 'MiP 'MaP)
     (mapcar
       (function
         (lambda (Obj)
           (putxdat Obj "LMACUPD"
             (vl-prin1-to-string
               (list
                 (vla-get-Handle pObj)
                   (vla-get-Handle bObj)))))) (list pObj bObj))
     (setq win (mapcar 'vlax-safearray->list (list MiP MaP))
           num (sslength
                 (ssget "_X"
                   (list
                     (cons 0 "INSERT")
                       (cons 2 (vla-get-Name bObj))
                         (cons 66 1)))))            
     (foreach Att (vlax-safearray->list
                    (vlax-variant-value
                      (vla-getAttributes bObj)))
       (cond
         ((eq ins (strcase (vla-get-TagString Att)))
          (vla-put-TextString Att
            (rtos num 2 0)))
         ((eq Wid (strcase (vla-get-TagString Att)))
          (vla-put-TextString Att
            (rtos
              (- (caadr win) (caar win)) 2 2)))
         ((eq Hgt (strcase (vla-get-TagString Att)))
          (vla-put-TextString Att
            (rtos
              (- (cadadr win) (cadar win)) 2 2))))))
   (princ "\n<< Incorrect Selection >>"))
 (princ))

(defun c:BlkUpdshow (/ gr ent xtyp xval Objlst)
 (while
   (and
     (setq gr (grread t 13 2))
     (eq 5 (car gr)))
   (if (setq ent (car (nentselp (cadr gr))))
     (progn
       (vla-getXdata
         (vlax-ename->vla-object ent) "LMACUPD" 'xtyp 'xval)
       (if (and xtyp xval)
         (mapcar
           (function
             (lambda (x)
               (redraw x 3)))
           (setq Objlst
             (mapcar 'handent
               (read
                 (vlax-variant-value
                   (cadr
                     (vlax-safearray->list xval)))))))))
         (if Objlst
           (mapcar
             (function
               (lambda (x)
                 (redraw x 4))) Objlst))))
 (princ))


(defun BlkUpdr (Reac Args / ins wid hgt blk ss xtyp xval hand
                           pObj MiP MaP bObj win num)

 ;;<<  Tag Names must be Capitalised! >>
 (setq ins "COUNT")         ;; << Instances Tag
 (setq Wid "X-WIDTH")       ;; << Width Tag
 (setq Hgt "Y-HEIGHT")      ;; << Height Tag

 (if (vl-position
       (car Args)
         '("GRIP_STRETCH"
           "GRIP_MOVE"
           "GRIP_SCALE"
           "GRIP_ROTATE"))
   (if (setq ss (cadr (ssgetfirst)))
     (progn
       (vla-getXdata
         (vlax-ename->vla-object
           (ssname ss 0)) "LMACUPD" 'xtyp 'xval)
       (if (and xtyp xval)
         (progn
           (setq hand
             (mapcar 'handent
               (read
                 (vlax-variant-value
                   (cadr
                     (vlax-safearray->list xval))))))
           (vla-getBoundingBox
             (setq pObj
               (vlax-ename->vla-object (car hand))) 'MiP 'MaP)
           (setq bObj (vlax-ename->vla-object (cadr hand))
                 win (mapcar 'vlax-safearray->list (list MiP MaP))
                 num (sslength
                       (ssget "_X"
                         (list
                           (cons 0 "INSERT")
                             (cons 2 (vla-get-Name bObj))
                               (cons 66 1)))))
           (foreach Att (vlax-safearray->list
                          (vlax-variant-value
                            (vla-getAttributes bObj)))
             (cond
               ((eq ins (strcase (vla-get-TagString Att)))
                (vla-put-TextString Att
                  (rtos num 2 0)))
               ((eq Wid (strcase (vla-get-TagString Att)))
                (vla-put-TextString Att
                  (rtos
                    (- (caadr win) (caar win)) 2 2)))
               ((eq Hgt (strcase (vla-get-TagString Att)))
                (vla-put-TextString Att
                  (rtos
                    (- (cadadr win) (cadar win)) 2 2)))))))))))          

(defun putxdat (Obj App Data / ent type1 valeur)

 (setq xtype
   (vlax-make-variant
     (vlax-safearray-fill
       (vlax-make-safearray
         vlax-vbInteger '(0 . 1)) '(1001 1000))))

 (setq xval
   (vlax-make-variant
     (vlax-safearray-fill
       (vlax-make-safearray
         vlax-vbVariant '(0 . 1)) (list App Data))))

 (vla-setXData Obj xtype xval))

(vl-load-com)
(if *lmac-Block*
 (vlr-remove *lmac-Block*)
 (setq *lmac-Block* nil))
(setq *lmac-Block*
 (vlr-command-Reactor nil
   (list
     (cons :vlr-CommandEnded 'BlkUpdr))))

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