Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Count.lsp modifications

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
5912 Views, 11 Replies

Count.lsp modifications

The count.lsp program counts blocks within the drawing. I wanted to know if anyone could help me to have the information that is returned to be exported to a text file... Has anyone done this or any suggestions....


(defun C:COUNT ( / blocks ss pat)
(setq pat (getstring t "\nBlock name specification <*>: "))
(if (eq pat "") (setq pat "*"))
(princ "\nPress to select entire drawing or,")
(cond
( (not (setq ss (cond ((ssget (list '(0 . "INSERT") (cons 2 pat))))
(t (ssget "x" (list '(0 . "INSERT") (cons 2 pat)))))))
(princ "\nNo matching block insertions found."))
(t (princ "\nCounting block insertions...\n")
( (lambda (i)
(repeat i (count_block (ssname ss (setq i (1- i))))))
(sslength ss))
(cond
( (not blocks)
(princ "\nNo block insertions found."))
(t (table-print blocks "Block" "Count" "-" 8 "." nil 'itoa)))))
(princ)
)

(defun table-print (alist title1 title2 headsub coltab padchr
car-form cdr-form / maxlen maxline padstr )
(setq car-form (cond (car-form) (t '(lambda (x) x)))
cdr-form (cond (cdr-form) (t '(lambda (x) x))))
(setq maxlen
(mapcar
'(lambda (pair)
(cons (strlen (car pair))
(strlen (cdr pair))))
(setq alist
(mapcar
'(lambda (pair)
(cons (apply car-form (list (car pair)))
(apply cdr-form (list (cdr pair)))))
alist ))))
(setq maxlen (+ -2 (apply 'max (mapcar 'car maxlen))
(apply 'max (mapcar 'cdr maxlen)))
maxline (+ maxlen coltab)
padstr (repl padchr 70))

(cprinc-init)
(cprinc (strcat title1 " "
(ctab (cons title1 title2)
maxline
(repl " " 70))
" " title2))
(cprinc (repl headsub (+ maxline 2)))
(mapcar
'(lambda (pair)
(cprinc (strcat (car pair) " "
(ctab pair maxline padstr) " "
(cdr pair))))
alist )
)

(defun repl (chr len / res)
(apply 'strcat (repeat len (setq res (cons chr res))))
)

(defun ctab (pair max padstr)
(substr padstr 1 (- max (strlen (car pair) (cdr pair))))
)

(defun cdr++ (key alist)
( (lambda (x)
(cond (x (subst (cons (car x) (1+ (cdr x))) x alist))
(t (cons (cons key 1) alist))))
(assoc key alist))
)

(defun get (k l) (cdr (assoc k l)))

(defun entgetf (k e)
( (lambda (l)
(mapcar '(lambda (x) (cdr (assoc x l))) k))
(entget e))
)

(defun count_block (ename)
(apply
'(lambda (etype name)
(cond
( (and (eq "INSERT" etype)
(or (assoc name blocks)
(zerop (logand 45 (get 70 (tblsearch "block" name)))))
(setq blocks (cdr++ name blocks))))) nil)
(entgetf '(0 2) ename))
)

(defun cprinc-init ()
(setq *console-lines* (cond (*console-lines*) (t 25))
*cprinc-msg* (cond (*cprinc-msg*) (t "--- Press any key ---"))
*cprinc-rubout*
(cond ( (or textpage *clear-screen*) "")
(t (strcat "\r" (repl " " (strlen *cprinc-msg*)) "\r")))
*cprinc-line* -1)
(cond (textpage (textpage))
(*clear-screen* (*clear-screen*))
(t (textscr) (terpri)))
)

(defun cprinc-page ()
(princ *cprinc-msg*)
(grread)
(cond (textpage (textpage))
(*clear-screen* (*clear-screen*))
(t (textscr)))
(princ *cprinc-rubout*)
(setq *cprinc-line* 0)
)

(defun cprinc (s)
(cond ( *cpage-disable*)
( (not *cprinc-line*)
(cprinc-init))
( (eq (setq *cprinc-line* (1+ *cprinc-line*))
(1- *console-lines*))
(cprinc-page)))
(write-line s)
)
11 REPLIES 11
Message 2 of 12
devitg
in reply to: Anonymous

Find attached your same LISP with the SAVE defun , it will save it to a CSV file , so you can open it on XLS.
Message 3 of 12
devitg
in reply to: Anonymous

The same as before , but it will add data to the same file.
Message 4 of 12
Anonymous
in reply to: Anonymous

Thanks for the help. I wanted to know how I would be able to apply the modification so that I can open a text file with the list of the drawings that I have to open and have it open and run the command with the block variable name i.e. "post1" without input from the user.. I have about 300 drawings and I need to search for that block and append a text file that has the name of the file and how many "posts" are in each file opened... any help would be appreciated.
Message 5 of 12
devitg
in reply to: Anonymous

Could you upload a bunch of your´s DWG and the xls wher you store the DWG names??
Give me also your ACAD VERSION , I run on 2006
I have some lisp that can be suited to do this.

Or you cand send me to my e-mail
devitg@gmail.com
Message 6 of 12
JanDebrouwere
in reply to: Anonymous

Hi,

 

I just noticed that Bcount doens't work on autocad 2014 for mac.

any chance that you could update this beautiful application?

or can u help me with another method to count blocks in in autocad 2014 mac

 

 

kind regards

Message 7 of 12
Lee_Mac
in reply to: JanDebrouwere

Hi Jan,

 

You could try one of my Block Counting applications:

 

Block Counter

Dynamic Block Counter

Nested Block Counter

Message 8 of 12
JanDebrouwere
in reply to: Lee_Mac

Hi Lee,

with block counter i get:
Command: COUNT
; error: vl-load-com not supported on "Mac OS X Version 10.9 (x86_64)"

with dynamic block counter i get:
Command: DBCOUNT
; error: no function definition: VLAX-GET-ACAD-OBJECT

Nested Block Counter works like a charm!
thanks a lot!!

Jan
Message 9 of 12
Lee_Mac
in reply to: JanDebrouwere


@JanDebrouwere wrote:

with block counter i get:
Command: COUNT
; error: vl-load-com not supported on "Mac OS X Version 10.9 (x86_64)"

Hi Jan,

 

Sorry, I should have mentioned that many of my programs utilise the ActiveX component of Visual LISP and are hence not compatible for use on AutoCAD for Mac.

 

I'm glad that my Nested Block Counter fits your needs Smiley Happy

 

Lee

Message 10 of 12
npccengineering
in reply to: Anonymous

Hey guy, I am still a AUTOCAD novice.  I also need a block counter in the Mac software.  I loaded the .lsp for the Block Counter but now what do I do?  I don't know what I am looking for to assign or modify a command alias to use the .lsp.   Any help would be appreciated.

Message 11 of 12
robert06
in reply to: Lee_Mac


@Lee_Mac wrote:

Hi Jan,

 

You could try one of my Block Counting applications:

 

Block Counter

Dynamic Block Counter

Nested Block Counter


Just a notice of what I've come across, DBCountV1-1.lsp does not count blocks residing inside Array objects.
In case developing this further on, it would be handy to have also possibility to count not necessarily all, but specific blocks either typing the name or even better, selecting the block (not all) from from screen or name from list window.

much appreciation for sharing the skills

 

Robert

 

Message 12 of 12
biondioaa
in reply to: JanDebrouwere

COMO DESCARGO EL PROGRAMA?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost