Results 1 to 9 of 9

Thread: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

  1. #1
    Login to Give a bone
    0

    Exclamation LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    Hi Guys,

    I already have a lisp for selecting blocks and giving me a count of them and their atributtes, for now, I want to include in that same Lisp a way to appear the block symbol itself..
    Would be very nice if I have at the same time a count of items on the first collumn of the table..

    I put as an attachment a DWG arquive showing how the table it is today and how i would like to be.. and the lisp i already have as well

    Thank you!!!
    Attached Files Attached Files

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL
    Posts
    3,499
    Login to Give a bone
    0

    Default Re: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    Lee Mac's code creates a block table with the symbol, name, and count: http://www.lee-mac.com/blockcounter.html
    Tom Beauford P.S.M. - Civil 2020 on Windows 10 Enterprise
    Design Analysis - Leon County Public Works/Engineering Wrap [CODE] tags around selected text
    2280 Miccosukee Rd. Tallahassee, FL 32308-5310
    Ph# (850)606-1516 Home Page

  3. #3
    Login to Give a bone
    0

    Default Re: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    Yeah!! Sure! i have that one as well!! my need is actually to compile that both lisps.... because lee Mac's doesnt give me the atributes from the blocks...

  4. #4
    I could stop if I wanted to
    Join Date
    2003-07
    Posts
    481
    Login to Give a bone
    0

    Default Re: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    Try this pick as many different blocks it uses name to sort the blocks and do counts.

    Code:
    ;http://forums.augi.com/showthread.php?171762-Extracted-attributes-from-AutoCAD-into-excel-pre-formatted-spread-sheet
    ; Bill tillman also
    
    ;  Take a block atts and make them into a table 
    ; counting the blocks also
    ; by Alan H April 2018
    
    (defun AH:block-atts ( / x  k obj obj2 ans ans2 comparelems AH:gotable)
    
    (defun  AH:gotable (  / txt)
    (setq rownum (vla-get-rows obj2))
    (vla-InsertRows obj2  rownum  (vla-GetRowHeight obj2 (- rownum 1)) 1)
    (repeat (setq k (length ans))
    (setq txt  (nth (setq k (- k 1)) ans))
    (vla-settext obj2 rownum  k  txt)
    )
    (vla-settext obj2 rownum   (- numcols  1) (rtos tot 2 0))
    (setq tot 1)
    )
    
    (defun comparelems (  / )
    (if (and
    (= (nth 0 ans)(nth 0 ans2))
    (= (nth 1 ans)(nth 1 ans2))
    )
    (setq tot (+ tot 1))
    (AH:gotable )
    )
    )
    
    (setq lst '())
    (setq ss (ssget '((0 . "insert"))))
    
    (repeat (setq  x (sslength ss))
    (setq lst2 '())
    (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
    (if (and (vlax-property-available-p obj "hasattributes")
    (setq atts (vlax-invoke obj "getattributes"))
    )
    (progn
    (setq lst2 (cons (vla-get-EffectiveName obj) lst2))
    (foreach att atts
    (setq lst2 (cons (vla-get-textstring att) lst2))
    )
    (setq lst (cons (reverse lst2) lst))
    )
    )
    )
    
    ; sorts on 1st two items
    (setq lst (vl-sort lst '(lambda (x y)
    (cond
    ((= (cadr x)(cadr y))
    (< (car x)(car y)))
    ((< (cadr x)(cadr y)))
    ))))
    
    (setq  numcols 1)
    (repeat (setq  x (length lst))
    (setq len (length (nth (setq x (- x 1)) lst)))
    (if (> len  numcols)
    (setq  numcols  len)
    )
    )
    (setq numcols (+ len 1))
    
    ; add better pick
    (setq obj2 (vlax-ename->vla-object (car (entsel "pick table or any other object to create a table"))))
    (if (/= (vla-get-objectname obj2) "AcDBtable")
    (progn
    (if (not AH:table_make)(load "table create2"))
    (AH:table_make  numcols)
    (setq obj2 (vlax-ename->vla-object (entlast)))
    )
    (princ)
    )
    
    (setq x 0)
    (setq tot 1)
    (setq ans (nth x lst))
    (repeat (- (length lst) 1)
    (setq ans2 (nth (setq x (+ x 1)) lst))
    (comparelems)
    (setq ans ans2)
    )
    )
    (AH:block-atts)

  5. #5
    Login to Give a bone
    0

    Default Re: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    Big-Al.. i couldnt get this code to run... but looking into it, i think thats not what i need... to be more precise i just need to know how to increment my table so i can show the symbol of the block (it could make a copy of the block itself and put into a column..) so i can see witch block it is refering not just by seeing the name of it..

    Thank you!!

  6. #6
    I could stop if I wanted to
    Join Date
    2003-07
    Posts
    481
    Login to Give a bone
    0

    Default Re: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    This is an example of how to put a block in a table

    Code:
    ; Thanks to FIXO for code ideas
    ; block in table example by Alan H
    ; May 2018
    
    (setq objtable (vlax-ename->vla-object (car (entsel "\nPick table"))))
    (setq row 3 col 2)
    (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
    (setq blkcount (vla-get-count (vla-get-blocks adoc)))
    (setq i 1)
    (repeat blkcount
    (setq bitem (vla-item (vla-get-blocks adoc) i))
    (if (= "NORTHN" (vla-get-Name bitem )) ; block name North for testing
    (progn
    (setq blkID (vla-get-objectid bitem))
      (vla-setblocktablerecordid objtable row col blkID :vlax-true)
      (vla-setblockscale objtable row col 0.75)
      (vla-setcellalignment objtable row col acMiddlecenter)
      ;(vla-setcellcontentcolor objtable row col acmcol)
      (setq i (- blkcount 1))
    )
    )
    (princ(setq i (+ i 1)))
    )

  7. #7
    Member
    Join Date
    2020-10
    Posts
    2
    Login to Give a bone
    0

    Default Re: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    please advise me to change the lisp, i have PTNO-S, DESC-S, QTY-S , attributes. my QTY-S have the quantity of items, so it must be count for total quantity. i don't want block name and count. please help
    Attached Images Attached Images
    Attached Files Attached Files

  8. #8
    Member
    Join Date
    2020-10
    Posts
    2
    Login to Give a bone
    0

    Default Re: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    please advise me to change the lisp, i have PTNO-S, DESC-S, QTY-S , attributes. my QTY-S have the quantity of items, so it must be count for total quantity. i don't want block name and count. please help
    Attached Images Attached Images
    Attached Files Attached Files

  9. #9
    I could stop if I wanted to
    Join Date
    2003-07
    Posts
    481
    Login to Give a bone
    0

    Default Re: LISP FOR SELECTING BLOCKS AND GIVING AN TABLE WITH ATRIBUTTES, BLOCK SYMBOL AND COUNT

    Start by Googling "block count.lsp" the issue you have is that the blocks do not appear to have the description so you would have to do a "lookup" procedure for the text that matches the block name. If this is like a 100 blocks a file may be best way to go.

Similar Threads

  1. Replies: 1
    Last Post: 2017-01-15, 12:22 AM
  2. Count and group Block Parameter by lisp,
    By hoangtungxd8947436 in forum AutoLISP
    Replies: 2
    Last Post: 2015-02-09, 11:56 PM
  3. Block editor selecting multiple blocks
    By KMiller.138083 in forum AutoCAD General
    Replies: 3
    Last Post: 2009-02-13, 08:49 PM
  4. Is there a way to count dynamic blocks and have a table update
    By thomas.stright in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2006-08-08, 03:00 PM
  5. LISP for selecting block and replacing with another
    By ken_nofuente in forum AutoLISP
    Replies: 2
    Last Post: 2006-06-29, 04:53 PM

Tags for this Thread

Posting Permissions

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