Author Topic: Current Block Count on drawings?  (Read 4295 times)

0 Members and 1 Guest are viewing this topic.

Andrew H

  • Guest
Current Block Count on drawings?
« on: September 09, 2004, 03:49:05 PM »
Does anyone have a lisp to display all or part of the block counts in mtext somewhere on the drawing?

I have certain blocks I need to keep an updated count on no matter who edits the drawing. Is there a way to do this, even if I have to rerun the command after editing the drawing each time. (just some I don't have to count them all again!, gets crazy with 100+ blocks and boss asking 10,000 questions while trying to count).

Thanks everyone.

P.S. Mark, if this question is better suited for the LISP forums then by all means move it over there, thanks.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Current Block Count on drawings?
« Reply #1 on: September 09, 2004, 06:48:46 PM »
Andrew,
Here's a quick little lisp that uses a list defined inside the lisp for the blocks to count. It will not count nested blocks. It inserts an Mtext object at 0,0 in Modelspace and assumes that it is the only Mtext object at that location. If there is a chance of a conflict, any arbitrary coordinate you would like can be used. If there is already an Mtext at that location (ie - from this being previously run in the drawing) it will be updated with the new data.

It is NOT set up to be run automatically, but someone with reactor knowledge better than I should be able to make it work as such. But just calling the command from a button whenever you need the updated data won't be that bad.

Code: [Select]

(defun c:blk-count-update (/ blist str *doc* ss txt inspt)
  ;;; Place the desired block names into the following list,
  ;;; you can use as many as you want, remove the "test" blocks I used
  (setq blist (list "test1" "test2")
        inspt '(0.0 0.0 0.0) ; modify for different insertion point
str "Block - Count"
*doc* (vla-get-activedocument (vlax-get-acad-object))
)
  (foreach x blist
    (if (setq ss (ssget "x" (list '(0 . "INSERT") (cons 2 x))))
      (setq str (strcat str "\\P" x " - " (itoa (sslength ss))))
      )
    )
  (if (> (strlen str) 13)
    (progn
      (setq ss (ssget "c" inspt inspt '((0 . "MTEXT"))))
      (if (not ss)
(progn
 (setq txt (vlax-invoke (vla-get-modelspace *doc*) "addMtext" inspt 0 str))
 (vla-put-color txt 8); I did this just to make it different
 )
(progn
 (setq txt (vlax-ename->vla-object (ssname ss 0)))
 (vla-put-textstring txt str)
 )
)
      )
    )
  (princ)
  )

Andrew H

  • Guest
Current Block Count on drawings?
« Reply #2 on: September 10, 2004, 09:45:33 AM »
Man, that is exactly what I'm looking for, thanks so much. The automatic updating in the lisp will work great. The 0,0 coordinates will be easy to find and move.

I will setup a button for easy access and will post the button text file so anyone which doesn't know how to write them will have that too.

Once again thank you so much.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Current Block Count on drawings?
« Reply #3 on: September 10, 2004, 10:30:39 AM »
Quote from: Andrew H
Man, that is exactly what I'm looking for, thanks so much. The automatic updating in the lisp will work great. The 0,0 coordinates will be easy to find and move.

I will setup a button for easy access and will post the button text file so anyone which doesn't know how to write them will have that too.

Once again thank you so much.

You are most welcome!

One thing you say that concerns me, though. "will be easy to find and move"....if you move the mtext object the routine will not find it the next time you run it. Be careful, you may end up with multiple instances of the block count..... :shock:

Andrew H

  • Guest
Current Block Count on drawings?
« Reply #4 on: September 10, 2004, 10:36:23 AM »
Yeah, I noticed that after rereading your post. I'll figure a way to get what I need. (even if I have to delete the old one which was moved, then rerun the command).

One other thing, the command doesn't work. I try invoking it and all I get is the name returned in the command prompt and a double empty command prompt. No text.

BTW.... I'm running 2005.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Current Block Count on drawings?
« Reply #5 on: September 10, 2004, 11:20:13 AM »
Yes, the command works. Did you modify the list in it to work with the blocks you want to count? If so, did you zoom to where the Mtext would be placed in the drawing (0 0 0)?

Here's a slightly modified file that will print to the text window whether it creates the Mtext or if no blocks are found. Make sure to change the names in the list shown in CAPS to the block names YOU want.

Code: [Select]

(defun c:blk-count-update (/ blist str *doc* ss txt inspt)
  ;;; Place the desired block names into the following list,
  ;;; you can use as many as you want
  (setq blist (list "PLAN02" "PLAN03");;<<<<<<<CHANGE THESE
inspt '(0.0 0.0 0.0)
str "Block - Count"
*doc* (vla-get-activedocument (vlax-get-acad-object))
)
  (foreach x blist
    (if (setq ss (ssget "x" (list '(0 . "INSERT") (cons 2 x))))
      (setq str (strcat str "\\P" x " - " (itoa (sslength ss))))
      )
    )
  (if (> (strlen str) 13)
    (progn
      (setq ss (ssget "c" inspt inspt '((0 . "MTEXT"))))
      (if (not ss)
(progn
 (setq txt (vlax-invoke (vla-get-modelspace *doc*) "addMtext" inspt 0 str))
 (vla-put-color txt 8)
 )
(progn
 (setq txt (vlax-ename->vla-object (ssname ss 0)))
 (vla-put-textstring txt str)
 )
)
      (princ "\nMtext placed at 0, 0, 0.....")
      )
    (princ "\nNo matching block names found....")
    )
  (princ)
  )

Andrew H

  • Guest
Current Block Count on drawings?
« Reply #6 on: September 10, 2004, 11:23:08 AM »
I must have missed the part where I'm supposed to add my block names to be counted. What part of the lips do i do that in?

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Current Block Count on drawings?
« Reply #7 on: September 10, 2004, 11:43:03 AM »
Look at lines 2, 3 & 4 of the lisp.......
Code: [Select]

  ;;; Place the desired block names into the following list,
  ;;; you can use as many as you want
  (setq blist (list "PLAN02" "PLAN03");;<<<<<<<CHANGE THESE

:)

Andrew H

  • Guest
Current Block Count on drawings?
« Reply #8 on: September 10, 2004, 11:49:30 AM »
lol, guess it shows I didn't read the entire lisp before asking dumb questions. Sorry.

Andrew H

  • Guest
Current Block Count on drawings?
« Reply #9 on: September 10, 2004, 12:16:49 PM »
The lisp works great.

Here is the button text
Code: [Select]
^C^Cblk-count-update;

Andrew H

  • Guest
Current Block Count on drawings?
« Reply #10 on: September 13, 2004, 11:38:58 AM »
One last question...

& BTW, the lisp works perfect.

I was wondering if adding and extra "" (blank) in between the block listings (as in "blocka" "blockb" etc.) would create a carriage return in the mtext box? Thanks for the help.

I'll test to see if this works, but if someone knows if this will not work and something else will, will you please let me know what that is.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Current Block Count on drawings?
« Reply #11 on: September 13, 2004, 02:01:29 PM »
I'm not sure what you are looking for, Andrew. It currently does add a carriage return, at least it does here.

In Acad2002, the "\P" is what denotes a carriage return. Has this changed for 2005?
Here's what it should look like:

Andrew H

  • Guest
Current Block Count on drawings?
« Reply #12 on: September 13, 2004, 02:04:41 PM »
You are correct as \P is still a carriage return, but I meant an extra to add a blank line in between block groups.

example:
A 32
B 12
C 34

D 34

E 22
F 34
G 34

Something like this.

Would I just add "P\" to the lisp code?

Thanks for the help.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Current Block Count on drawings?
« Reply #13 on: September 13, 2004, 02:31:54 PM »
Oh, OK......Correct a "\P" will do it. Here's revised code to do this. In the block list, just include a " " (that's quote-space-quote) to add a blank line wherever you want.
Code: [Select]

(defun c:blk-count-update (/ blist str *doc* ss txt inspt)
  ;;; Place the desired block names into the following list,
  ;;; you can use as many as you want. Use " " for a space in the list
  (setq blist (list "TEST1" " " "TEST2")
inspt '(0.0 0.0 0.0)
str "Block - Count"
*doc* (vla-get-activedocument (vlax-get-acad-object))
)
  (foreach x blist
    (if (setq ss (ssget "x" (list '(0 . "INSERT") (cons 2 x))))
      (setq str (strcat str "\\P" x " - " (itoa (sslength ss))))
      )
    (if (eq x " ")
      (setq str (strcat str "\\P"))
      )
    )
  (if (> (strlen str) 13)
    (progn
      (setq ss (ssget "c" inspt inspt '((0 . "MTEXT"))))
      (if (not ss)
(progn
 (setq txt (vlax-invoke (vla-get-modelspace *doc*) "addMtext" inspt 0 str))
 (vla-put-color txt 8)
 )
(progn
 (setq txt (vlax-ename->vla-object (ssname ss 0)))
 (vla-put-textstring txt str)
 )
)
      (princ "\nMtext placed at 0, 0, 0.....")
      )
    (princ "\nNo matching block names found....")
    )
  (princ)
  )

Andrew H

  • Guest
Current Block Count on drawings?
« Reply #14 on: September 13, 2004, 02:51:47 PM »
Man, I really appreciate all your help.