Table for block values

Table for block values

harsh
Participant Participant
3,720 Views
16 Replies
Message 1 of 17

Table for block values

harsh
Participant
Participant

Hi

As a small estimation routene, I would like to extract block scale values  (not attributes)  into a table, and into excel. 

My drawing is mostly created out of scaled blocks.

From a selection window of items,  I would like to make out a table (and / or export to excel) :

 

Block Name

X Scale

Y scale

Z scale

Number of items of each type

 

I wouldnt know if its possible, to automatically number the items in the drawing, and correspond them with the table and excel, so we can relate the item with the sheet

 

I use Autocad release 13

 

Any suggestions ???

Thanks

0 Likes
Accepted solutions (3)
3,721 Views
16 Replies
Replies (16)
Message 2 of 17

Moshe-A
Mentor
Mentor

@harsh ,

 

You could do it by your own with ATTEXT command (exist in AutoCAD almost from day 1). you can explore this command from the AutoCAD help or google

 

Attached is sample template file to extract block Name+XYZ+ XScale

 

cheers,

Moshe

 

0 Likes
Message 3 of 17

pbejse
Mentor
Mentor

@harsh wrote:

I use Autocad release 13


Are you serious right now? 😀  a version for MS-DOS and Windows 3.11.?  The lowest version i can save a dwg file is 2004 using DWG TrueView.

 

or is that Autocad 2013 (Jaws)?

 

0 Likes
Message 4 of 17

Sea-Haven
Mentor
Mentor

2 suggestions, add a number attribute to your block, second is have a look at this post should give good ideas about quantities. 

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/list-sorting-strings/td-p/9848596

0 Likes
Message 5 of 17

harsh
Participant
Participant

Yes chief, 

I feel release 13 gives you all the basic tools for working. Anything more is Lisp-able. 

Do elaborate if you feel otherwise. 

 

AutoCad cost in our country is pretty high, and the yearly lease now is very high. In fact many users are shifting to cheaper non Autodesk clones. 

 

And yes, I too need to bring down the version when I receive upper release drawings. But the DWG Trueview convert is free 

🙂

0 Likes
Message 6 of 17

harsh
Participant
Participant

Thanks Moshe, for your suggestion...

But I am looking for a routine where you can choose a bunch of blocks, and create a table like this :


Name        x scale     y scale    z scale    Nos
Block 1         2000      20            2100        20

Block 2         1200       15            600         30
Block 3         600        10             1800       10

 

 

and so on....
And this could have an option to create a table in autocad itself, or a csv file for excel

 

 

Thanks

0 Likes
Message 7 of 17

harsh
Participant
Participant

Dear sea.haven, 

thanks for your suggestion... but i feel the thread you had referred to would not help the routine i am looking for ...

 

Without going into attributes to "complicate" anything for me, 

I would like to insert a basic different material blocks of 1mmx1mmx1mm, and while inserting, i would scale up the x/y/z values to get the size i need. Eventually i would like to extract the blocks as different materials, and get the dimensions from the x/y/z values along with the numbers of those blocks and do the rest of the calculations in excel.

🙂

0 Likes
Message 8 of 17

harsh
Participant
Participant

ooops..... i meant autocad 2013..... 

 

although i must confess, i did start with autocad release 10 officially.... and probably tested the version 2.6 in the year 1988 .....on an AT-386 PC......    a few generations ago...

 

My mistake in interpretation ... apologies  🙂

0 Likes
Message 9 of 17

Moshe-A
Mentor
Mentor
Accepted solution

@harsh ,

 

Here is a BLKOUT command to extract your blocks to csv file. (you can save it as xlsx and import it back to AutoCAD with TABLE command.)

blocks with the exact Name, xscale, yscale, zscale will be consider the same.

note that if there would be a small difference in scale, they will consider as 2, so blkout uses the current luprec (sysvar) to compare scales. this is 4 digits by default.

 

The following code lines declares two constants:

(setq PREC (getvar "luprec"))
(setq FUZZ (read (strcat "1e-" (itoa PREC))))

 

PREC controls the scale precision format for the csv file. you can set a new luprec value in your drawing or hardcode it in the lisp. FUZZ is for the scale comparison and it leans on PREC but you can hardcode it as well.

 

Note that DIMZIN is effecting scale values.

 

enjoy

Moshe

 

 

 

 

 

 

 

(defun c:blkout (/ is_equal nformat ; local functions
                   PREC FUZZ fname ss elist bname item0 item1 data^ f)

 (defun is_equal (itm0 itm1)
  (vl-every
   '(lambda (a0 a1)
     (cond
      ((= (type a0) 'STR) 
       (eq a0 a1)
      ) 
      ( t
       (equal a0 a1 FUZZ)
      )
     ); cond
    )
   itm0 itm1
  )
 ); is_equal
  
 (defun nformat (v)
  (rtos v 2 PREC)
 )

 ; here start c:blkout
 ; 
 ; const
 (setq PREC (getvar "luprec"))
 (setq FUZZ (read (strcat "1e-" (itoa PREC))))
  
 (if (and
       (setq fname (getfiled "Excel file name" (vl-filename-base (getvar "dwgname")) "csv" 1))  
       (setq ss (ssget '((0 . "insert"))))
     )
  (progn
   (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    (setq elist (entget ename))
    (setq bname (strcase (cdr (assoc '2 elist))))
    (setq item0 (list bname (cdr (assoc '41 elist)) (cdr (assoc '42 elist)) (cdr (assoc '43 elist))))
     
    (if (and (setq item1 (assoc bname data^))
             (is_equal item0 (reverse (cdr (reverse item1))))
        )
     (progn
      (setq item0 (append item0 (list (1+ (last item1))))) ; inc by 1
      (setq data^ (cons item0 (vl-remove item1 data^)))    ; replace item in data^
     )
     (setq data^ (cons (append item0 (list 1)) data^))     ; append new item to data^
    )
   ); foreach

   ; create excel file
   (if (not (setq f (open fname "w")))
    (prompt (strcat "\nfail to open " fname " for write."))
    (progn
     (prompt (strcat "\nCreating file " fname))
     (write-line "Name,x scale,y scale,z scale,Nos" f) ; header
   
     (foreach item data^
      (write-line (strcat "\n" (car item) "," (nformat (cadr item)) "," (nformat (caddr item)) "," (nformat (cadddr item)) "," (rtos (last item) 2 0)) f)
     )

     (setq f (close f))
    ); progn
   ); if
  ); progn
 ); if

 (princ)   
); c:blkout

 

 

 

 

 

 

0 Likes
Message 10 of 17

harsh
Participant
Participant

Dear Moshe,  

This is brilliant !!!! 

 

Let me test this program in a real world situation and revert

 

many thanks !!!!

 

0 Likes
Message 11 of 17

pbejse
Mentor
Mentor

@harsh wrote:

AutoCad cost in our country is pretty high, and the yearly lease now is very high. In fact many users are shifting to cheaper non Autodesk clones. 

...

ooops..... i meant autocad 2013..... 


No worries, i know you meant 2013, just playing with you 🙂

And because you apolgize, I will write a quick code for you.

 

 

0 Likes
Message 12 of 17

harsh
Participant
Participant

🙂

i will take you up on that !!!! 

Cheers !!!!

Thanks a lot

 

(I not only apologise, i also am very grateful to all you guys for your help !!!! ) 

🙂

0 Likes
Message 13 of 17

pbejse
Mentor
Mentor
Accepted solution

@harsh wrote:

i will take you up on that !!!! 

 


HYG

(defun c:BlkInfo ( / _rtos collection SaveFile ss ent data XYZ f fv pts)
(setq _rtos (lambda (n)(rtos n 2 0)))
 (if (and
       (setq collection nil
	      SaveFile (getfiled "Enter file name" (strcat (Getvar 'dwgprefix)
				(vl-filename-base (getvar 'dwgname))) "csv" 1))  
       (setq ss (ssget '((0 . "INSERT"))))
     )
   (progn
   	(repeat (setq i (sslength ss))
	  (setq ent (entget (ssname ss (setq i (1- i)))))
	  (setq data (mapcar '(lambda (d) (cdr (assoc d ent))) '(2 41 42 43)))
	  (setq XYZ (mapcar '_rtos (Cdr data)))
	  
	  (setq collection
		 (if (and
		       (setq f (assoc (car data)  collection))
		       (setq fv (equal (car (cadr f)) XYZ ))
		       (setq fv (list (Car f) (cons XYZ (1+ (cdr (cadr f))))))
		       )
		   	(subst fv f collection)
		   	(cons (list
				(Car data)
					(cons XYZ 1)) collection)
		   )
		)
	  )
	(setq opf (open SaveFile "w"))
     	(Write-line "Name,X Scale,Y Scale,Z Scale,Nos" opf)
     	(foreach itm collection
	  (setq pts (caadr itm) q (cdadr itm))
	  (Write-line (strcat (car itm)	"," (car pts) ","
			      (cadr pts) "," (caddr pts) "," (_rtos q)) opf))
     	(Close opf)
      ;;(startapp "notepad" SaveFile)
     )
   )
(princ)
)

HTH

 

0 Likes
Message 14 of 17

harsh
Participant
Participant

Pbsje and Moshe,

The programs work wonderfully !!!! what can i say, you guys are mentors, and are the best !!!! 

Many many thanks !!! 

its really going to help me in my work. 

 

I hope i am able to take you guys out for a drink someday !!!!

 

Cheers !!!!

0 Likes
Message 15 of 17

harsh
Participant
Participant

Hi @pbejse  and @Moshe-A .....

I have a strange issue with the program above.......

if i count the blocks in autocad, it shows a different number to the one extracted in excel. 

I cant put a finger on why this is happening.... 

any suggestions on where i am going wrong ????

I am attaching a block drawing with a count, and the extracted .csv sheet.....

autocad shows the number at 90, and the extraction shows 174..... (Pbeje)

autocad shows the number at 90, and the extraction shows  59..... (MosheA)

 

very strange....

thanks

0 Likes
Message 16 of 17

pbejse
Mentor
Mentor
Accepted solution

 

 

(defun c:BlkInfo ( / _rtos collection SaveFile ss ent data XYZ f fv pts)
(setq _rtos (lambda (n)(rtos n 2 0)))
 (if (and
       (setq collection nil
	      SaveFile (getfiled "Enter file name" (strcat (Getvar 'dwgprefix)
				(vl-filename-base (getvar 'dwgname))) "csv" 1))  
       (setq ss (ssget '((0 . "INSERT"))))
     )
   (progn
   	(repeat (setq i (sslength ss))
	  (setq ent (entget (ssname ss (setq i (1- i)))))
	  (setq data (mapcar '(lambda (d) (cdr (assoc d ent))) '(2 41 42 43)))
	  (setq XYZ (mapcar '_rtos (Cdr data)))
	  
	  (setq collection
		 (if 
		       (setq f (vl-some '(lambda (d)
					   (if (and (eq (car data) (car d))
							(equal (caadr d) XYZ)) d))
				 collection))
		   	(subst (list (Car f) (cons XYZ (1+ (cdr (cadr f))))) f collection)
		   	(cons (list
				(Car data)
					(cons XYZ 1)) collection)
		   )
		)
	  )
	(setq opf (open SaveFile "w"))
     	(Write-line "Name,X Scale,Y Scale,Z Scale,Nos" opf)
     	(foreach itm collection
	  (setq pts (caadr itm) q (cdadr itm))
	  (Write-line (strcat (car itm)	"," (car pts) ","
			      (cadr pts) "," (caddr pts) "," (_rtos q)) opf))
     	(Close opf)
      ;;(startapp "notepad" SaveFile)
     )
   )
(princ)
)

 

HTH

AND in case you are using Dynamic blocks

(defun c:BlkInfo ( / _rtos collection SaveFile ss ent bnm data XYZ f fv pts)
(setq _rtos (lambda (n)(rtos n 2 0)))
 (if (and
       (setq collection nil
	      SaveFile (getfiled "Enter file name" (strcat (Getvar 'dwgprefix)
				(vl-filename-base (getvar 'dwgname))) "csv" 1))  
       (setq ss (ssget '((0 . "INSERT"))))
     )
   (progn
   	(repeat (setq i (sslength ss))
	  (setq ent (entget (setq e (ssname ss (setq i (1- i))))))
	  (setq bnm (getpropertyvalue e "BlockTableRecord/Name"))
	  (setq data (mapcar '(lambda (d) (cdr (assoc d ent))) '(41 42 43)))
	  (setq XYZ (mapcar '_rtos data))
	  
	  (setq collection
		 (if 
		       (setq f (vl-some '(lambda (d)
					   (if (and (eq bnm (car d))
							(equal (caadr d) XYZ)) d))
				 collection))
		   	(subst (list (Car f) (cons XYZ (1+ (cdr (cadr f))))) f collection)
		   	(cons (list
				bnm
					(cons XYZ 1)) collection)
		   )
		)
	  )
	(setq opf (open SaveFile "w"))
     	(Write-line "Name,X Scale,Y Scale,Z Scale,Nos" opf)
     	(foreach itm collection
	  (setq pts (caadr itm) q (cdadr itm))
	  (Write-line (strcat (car itm)	"," (car pts) ","
			      (cadr pts) "," (caddr pts) "," (_rtos q)) opf))
     	(Close opf)
      (startapp "notepad" SaveFile)
     )
   )
(princ)
)

 

0 Likes
Message 17 of 17

harsh
Participant
Participant

Chief !!!! tried the normal block info ..... And it works !!!!! and better than before !!!!

Thank you sooooo much once again !!!!

0 Likes