Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: transfer blocks to excel

  1. #11
    Member
    Join Date
    2012-09
    Posts
    16

    Default Re: transfer blocks to excel

    I tried to organize a lisp which you sent me from link so far . it didn't run. I have turned my lisp again. I send my lisp. Maybe you can add the my request.

    Thank you for help
    block count excel.LSP

  2. #12
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    397

    Default Re: transfer blocks to excel

    I see that its fixo's [fatty] code. I'm pretty sure he'll take a crack at the code for you

  3. #13
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,213

    Default Re: transfer blocks to excel

    Upload in attachment your sample drawing with few blocks,
    make sure that every block has description,
    I will try to help

    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  4. #14
    Member
    Join Date
    2012-09
    Posts
    16

    Default Re: transfer blocks to excel

    Hi I send the sample drawing. Thanks any help.
    TEST.dwg

  5. #15
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,213

    Default Re: transfer blocks to excel

    Could not convert your drawing on 2007 version
    It has unresolved .bmp file embedded, so you have to
    convert this drawing on 2007th but remove the images before,
    I will be back later
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  6. #16
    Member
    Join Date
    2012-09
    Posts
    16

    Default Re: transfer blocks to excel

    I converted it. I will wait your back.
    TEST1.dwg

  7. #17
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,213

    Default Re: transfer blocks to excel

    Try this one slightly edited, I can't upload the code as lsp file
    by reson of my browser is not support this option, so copy-paste
    the whole code and save it with appropriate name

    Code:
    ;;From man to man
    
    ;; written by Fatty 2005 All rights removed
    
    ;; helper function
    
    ;; group list into separate sublists
    
      (defun group-by-first (lst / ret tmp)
      (while (car lst)
      (setq tmp (list (vl-remove-if-not (function (lambda (a)
    			(eq a (car lst )))) lst)))
      (setq ret (cons (car tmp) ret))
      (setq lst (vl-remove-if (function (lambda (a)
    			(eq a (car lst )))) lst))
      (setq tmp nil))
      (setq ret (mapcar (function (lambda (x)
    		(list (car x) (length x)))) (reverse ret)))
        )
    
    ;; *** Main program *** ;;
    
    (defun C:BCEX  (/  acsp adoc aexc all_data awb blk_lst bname bnm brds cll clls colm cols com_lst csht data
    		data_list datum en filt fnt header_list i intr nwb rang row scol sht srow ss)
    
      (vl-load-com)
      (setq	adoc (vla-get-activedocument
    	       (vlax-get-acad-object)
    	       )
    	acsp (vla-get-modelspace adoc)
    	)
      (setq	blk_lst	nil
    	data nil
    	com_lst	nil)
    
      (setq	bname (getstring T
    			 "\nEnter a block name (case-sensitive) <*> : \n")) ;press enter to count all blocks
      (if (eq bname "")
        (setq bname "*"))				  ;change to default block name
    
      (setq	filt (list (cons 0 "INSERT")
    		   (cons 2 bname)
    		   (cons 410 (getvar 'ctab))))
      (if
    
        (setq ss (ssget "_X" filt))
         (progn
           (setq i -1)
           (repeat (sslength ss)
    	 (setq en (ssname ss (setq i (1+ i))))
    
    	 (setq bnm (vla-get-effectivename (vlax-ename->vla-object en)))
    	 (setq blk_lst (cons bnm blk_lst))
    	 )
           (setq com_lst (group-by-first blk_lst))
    
           (vlax-for blkdef	 (vla-get-blocks adoc)
    	 (foreach record  com_lst
    	   (if (eq (vla-get-name blkdef) (car record))
    	     (setq com_lst (subst (append record (list (vla-get-comments blkdef)))
    				  record
    				  com_lst)))
    	   )
    	 )
    
           (setq data     (append
    			(append (list (list "Layout" (getvar 'ctab))) com_lst))
    	     data     (append data (list (list "Subtotal : " (length blk_lst))))
    	     all_data (cons data all_data)
    	     blk_lst  nil
    	     com_lst  nil
    	     data     nil)
           )
         )
    ;;;  )
      (setq all_data (apply 'append (reverse all_data)))
    
      ;;=================header text ====================================;;
    
      (setq header_list '("Name" "Quantity" "Description") cols (length header_list))
      (setq data_list all_data)
      ;; *** Excel part *** ;;
    
      (setq	aexc (vlax-get-or-create-object "Excel.Application")
    	awb  (vlax-get-property aexc "Workbooks")
    	nwb  (vlax-invoke-method awb "Add")
    	sht  (vlax-get-property nwb "Sheets")
    	csht (vlax-get-property sht "Item" 1)
    	cll  (vlax-get-property csht "Cells")
    	)
      (vlax-put-property csht 'Name "BlockCountInfo")
      (vla-put-visible aexc :vlax-true)
      (setq	row 1
    	colm 1
    	)
      (vlax-put-property
        cll
        "Item"
        row
        colm
        (vl-princ-to-string "Block Count Info")
        )
    
      (setq	row  (1+ row)
    	colm 1
    	)
    
    
      (repeat (length header_list)
        (vlax-put-property
          cll
          "Item"
          row
          colm
          (vl-princ-to-string (car header_list))
          )
        (setq colm	      (1+ colm)
    	  header_list
    		      (cdr header_list)
    	  )
        )
      ;;	merge header cells :
    
    
      (setq	srow "A1"
    	scol (strcat (chr (1- (+ (ascii "A") cols)))
    		     "1"))
      (vlax-invoke-method csht "Activate")
      (setq	rang (vlax-get-property
    	       aexc
    	       'Range
    	       (vlax-make-variant srow)
    	       (vlax-make-variant scol)))
      (vlax-invoke-method rang "Activate")
      (vlax-invoke-method
        (vlax-get-property
          (vlax-get-property
    	rang
    	"Cells"
    	)
          "Columns"
          )
        "Merge"
        )
    ;;;	center alignment of header text :
      (vlax-put-property
        rang
        'Horizontalalignment
        (vlax-make-variant 3))
      ;;==============================change font=========================;;
    
      (setq fnt (vlax-get-property rang "Font"))
      (vlax-put-property fnt "Bold" (vlax-make-variant 1))
      (vlax-put-property fnt "Size" (vlax-make-variant 12))
    
      ;;	fill cells :
      (setq	row  (1+ row)
    	colm 1
    	)
      (repeat (length data_list)
        (setq datum (car data_list))
        (repeat (length datum)
          (vlax-put-property
    	cll
    	"Item"
    	row
    	colm
    	(vl-princ-to-string (car datum))
    	)
          (setq datum (cdr datum))
          (setq colm (1+ colm)))
    
        (setq colm 1
    	  row  (1+ row))
    
        (setq data_list (cdr data_list))
        )
      ;;=============================draw borders=========================;;
    
      (setq rang (vlax-get-property csht 'UsedRange))
      (vlax-invoke-method rang "Activate")
    
      (setq	clls
    	 (vlax-get-property
    	   rang
    	   "Cells"
    	   ))
      (setq	brds
    	 (vlax-get-property
    	   clls
    	   "Borders"
    	   ))
      (vlax-put-property brds "Linestyle" (vlax-make-variant 1))
    
      ;;==============================change font=========================;;
    
      (setq fnt (vlax-get-property rang "Font"))
      (vlax-put-property fnt "Italic" (vlax-make-variant 1))
      (vlax-put-property fnt "Size" (vlax-make-variant 10))
      (setq rang (vlax-get-property csht 'UsedRange))
      (vlax-invoke-method
        (vlax-get-property
          (vlax-get-property
    	rang
    	"Cells"
    	)
          "Columns"
          )
        "Autofit"
        )
    
      ;;==================================================================;;
    
      ;; automatically saving an Excel file :
    
      (vlax-invoke-method
        nwb
        'SaveAs
        (strcat (getvar "dwgprefix")
    	    (strcat "COUNT-"
    		    (vl-string-right-trim ".dwg" (getvar "dwgname")))
    	    )
        -4143
        nil
        nil
        :vlax-false
        :vlax-false
        1
        2
        )
      (vlax-release-object cll)
      (vlax-release-object rang)
      (vlax-release-object csht)
      (vlax-release-object sht)
      (vlax-release-object nwb)
      (vlax-release-object awb)
      (vlax-release-object aexc)
      (setq aexc nil)
      (gc)
      (gc)
      (princ)
      )
    (prompt "\n\t\t***\tBlock count info to Excel program is loaded\t***\n")
    (prompt "\n\t\t***\tType BCEX to execute\t***\n")
    (princ)
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  8. #18
    Member
    Join Date
    2012-09
    Posts
    16

    Default Re: transfer blocks to excel

    thank you so much, İt is very useful

  9. #19
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,213

    Default Re: transfer blocks to excel

    Glad to help
    Cheers
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

Page 2 of 2 FirstFirst 12

Similar Threads

  1. transfer point from AutoCAD to excel
    By e.mounir in forum AutoCAD General
    Replies: 7
    Last Post: 2010-08-18, 11:23 AM
  2. Transfer data from Dwg to excel
    By MAS2006 in forum AutoCAD General
    Replies: 3
    Last Post: 2010-02-03, 06:39 PM
  3. Transfer data from Dwg to excel
    By MAS2006 in forum DWG TrueConvert - General
    Replies: 1
    Last Post: 2010-02-03, 12:34 PM
  4. Use Excel to change properties of blocks
    By christopher.r.schroll in forum AutoLISP
    Replies: 1
    Last Post: 2008-04-23, 02:42 PM
  5. course on Tables (creatation and transfer from Excel)
    By Capt. Computer Crasher in forum ATP Course Wishlist
    Replies: 15
    Last Post: 2007-10-16, 09:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •