Author Topic: BOM Utility to extract selective attributes from blocks with tabulation  (Read 9280 times)

0 Members and 1 Guest are viewing this topic.

Arthur Gan

  • Guest
May I ask if someone (Daniel) can help to code a BOM Utility to extract selective attributes from blocks and tabulate the summarised attribute information in a table format inserted into the drawing?

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #1 on: October 10, 2008, 11:55:17 AM »
What's wrong with the EATTEXT?  (I think that's the command name).
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

T.Willey

  • Needs a day job
  • Posts: 5218
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #2 on: October 10, 2008, 11:55:18 AM »
How much help do you need?  Would pseudo code be enough?  Or do you have one particular problem that seems to be causing you headaches?

Welcome to theSwamp Arthur.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

fixo

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #3 on: October 10, 2008, 01:46:00 PM »
May I ask if someone (Daniel) can help to code a BOM Utility to extract selective attributes from blocks and tabulate the summarised attribute information in a table format inserted into the drawing?

This one seems to be working for me, give that a try

Code: [Select]
(defun C:A2T  (/ acsp adoc alist at atable atlist blklist bname cnt col columns data elist en ent headers item obj_list row rows ss tag)
  (setq atlist (nentsel "\nSelect attribute you need:"))
  (setq at (car atlist)
alist (entget at)
tag (cdr (assoc 2 alist))
blklist (cdr (assoc 330 alist))
bname (cdr (assoc 2 (entget blklist)))
)
  (alert "Select blocks to summ attribute values")
  (setq ss (ssget (list (cons 0 "INSERT") (cons 2 bname))))
  (while (setq en (ssname ss 0))
    (setq elist (entget en))
    (while (/= "SEQEND" (setq ent (cdr (assoc 0 elist))))
      (if
(and
  (eq "ATTRIB" ent)
  (eq tag (cdr (assoc 2 elist)))
  )
(setq data (cons (cons (cdr (assoc 2 elist)) (cdr (assoc 1 elist)))
  data))
)
      (setq elist (entget (entnext (cdr (assoc -1 elist)))))
      )
    (ssdel en ss)
    )
  (setq data (append data
     (list
       (cons "Summ:" (apply '+ (mapcar 'atof (mapcar 'cdr data)))))))
  (setq data (append (list (cons "Tag" "Value")) data))
  (print data)
  (if data
    (progn
    (vl-load-com)
 
  (or adoc
    (setq adoc (vla-get-activedocument
  (vlax-get-acad-object))))
  (or acsp (setq acsp (if (= (getvar "TILEMODE") 0)
  (vla-get-paperspace
  adoc)
  (vla-get-modelspace
  adoc))
  )
  )
    (setq columns 2
rows (length data)
  )

  (setq atable (vla-addtable
acsp
(vlax-3d-point (getpoint "\nUpper left table insertion point: \n"))
(+ 2 rows)
columns
;; rows height (change by suit):
(* (getvar "dimtxt") 1.667)
;; columns width (change by suit):
(* (getvar "dimtxt") 8.333)
       )
  )
  (vla-put-regeneratetablesuppressed atable :vlax-true) 
  (vla-settext atable 0 0 "TITLE") ;(change by suit)

  (setq headers '("1" "2");(change by suit)
  )
 
  (setq col 0
row 1
  )
  (foreach a headers
    (vla-settext atable row col a)
    (setq col (1+ col))
  )

  (setq cnt 1 ;counter
row 2)
   
  (repeat rows
    (setq col 0
  item (car data)
    )
      (vla-settext
atable
row
col
(car item)
      )
     (setq col    (1+ col))
      (vla-settext
atable
row
col
(cdr item)

      )

    (setq row (1+ row)
  col    0
  cnt (1+ cnt)
  data (cdr data)
    )
  )
  (vla-put-regeneratetablesuppressed atable :vlax-false)
  (vlax-release-object atable)
    )
    )
  (princ)
)
(prompt
  "\n\t\t\t   |-----------------------------|\n"
)
(prompt
  "\n\t\t\t  <|  Start with A2T to execute  |>\n"
)
(prompt
  "\n\t\t\t   |-----------------------------|\n"

(princ)

Arthur Gan

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #4 on: October 10, 2008, 02:44:00 PM »
Basically the block has a number of attributes defined for eg. Model, Manufacturer, Cost, Tel, Fax
It'll be good if the utility prompts to select the block, then pop-up a dialogue for us to check (select the attributes) we want to extract, next it prompts to select the blocks and summarises the total with header (eg. Model, Cost if this is the only 2 attributes selected) in atable inserted in the drawing.
The utility (A2T) below has the structure but would you be able to prompt to select the attributes to extract and use the attribute names as headers in the table?

May I ask if someone (Daniel) can help to code a BOM Utility to extract selective attributes from blocks and tabulate the summarised attribute information in a table format inserted into the drawing?

This one seems to be working for me, give that a try

Code: [Select]
(defun C:A2T  (/ acsp adoc alist at atable atlist blklist bname cnt col columns data elist en ent headers item obj_list row rows ss tag)
  (setq atlist (nentsel "\nSelect attribute you need:"))
  (setq at (car atlist)
alist (entget at)
tag (cdr (assoc 2 alist))
blklist (cdr (assoc 330 alist))
bname (cdr (assoc 2 (entget blklist)))
)
  (alert "Select blocks to summ attribute values")
  (setq ss (ssget (list (cons 0 "INSERT") (cons 2 bname))))
  (while (setq en (ssname ss 0))
    (setq elist (entget en))
    (while (/= "SEQEND" (setq ent (cdr (assoc 0 elist))))
      (if
(and
  (eq "ATTRIB" ent)
  (eq tag (cdr (assoc 2 elist)))
  )
(setq data (cons (cons (cdr (assoc 2 elist)) (cdr (assoc 1 elist)))
  data))
)
      (setq elist (entget (entnext (cdr (assoc -1 elist)))))
      )
    (ssdel en ss)
    )
  (setq data (append data
     (list
       (cons "Summ:" (apply '+ (mapcar 'atof (mapcar 'cdr data)))))))
  (setq data (append (list (cons "Tag" "Value")) data))
  (print data)
  (if data
    (progn
    (vl-load-com)
 
  (or adoc
    (setq adoc (vla-get-activedocument
  (vlax-get-acad-object))))
  (or acsp (setq acsp (if (= (getvar "TILEMODE") 0)
  (vla-get-paperspace
  adoc)
  (vla-get-modelspace
  adoc))
  )
  )
    (setq columns 2
rows (length data)
  )

  (setq atable (vla-addtable
acsp
(vlax-3d-point (getpoint "\nUpper left table insertion point: \n"))
(+ 2 rows)
columns
;; rows height (change by suit):
(* (getvar "dimtxt") 1.667)
;; columns width (change by suit):
(* (getvar "dimtxt") 8.333)
       )
  )
  (vla-put-regeneratetablesuppressed atable :vlax-true) 
  (vla-settext atable 0 0 "TITLE") ;(change by suit)

  (setq headers '("1" "2");(change by suit)
  )
 
  (setq col 0
row 1
  )
  (foreach a headers
    (vla-settext atable row col a)
    (setq col (1+ col))
  )

  (setq cnt 1 ;counter
row 2)
   
  (repeat rows
    (setq col 0
  item (car data)
    )
      (vla-settext
atable
row
col
(car item)
      )
     (setq col    (1+ col))
      (vla-settext
atable
row
col
(cdr item)

      )

    (setq row (1+ row)
  col    0
  cnt (1+ cnt)
  data (cdr data)
    )
  )
  (vla-put-regeneratetablesuppressed atable :vlax-false)
  (vlax-release-object atable)
    )
    )
  (princ)
)
(prompt
  "\n\t\t\t   |-----------------------------|\n"
)
(prompt
  "\n\t\t\t  <|  Start with A2T to execute  |>\n"
)
(prompt
  "\n\t\t\t   |-----------------------------|\n"

(princ)

fixo

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #5 on: October 10, 2008, 02:48:43 PM »
Ah, forgot to say first - welcome on board!
Can you upload the sample drawind with blocks
and remove from there all unused information before
I'm so lazy today to create similar blocks :)

~'J'~


Arthur Gan

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #6 on: October 10, 2008, 02:49:25 PM »
if psuedo code means a lisp utility, it'll be more than what we're asking for.
This utility would be very useful to extract an tabulate items in a drawing.
The items can range from a column, a door, a basin, a chair to a piece of floor tile...

How much help do you need?  Would pseudo code be enough?  Or do you have one particular problem that seems to be causing you headaches?

Welcome to theSwamp Arthur.

Arthur Gan

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #7 on: October 10, 2008, 02:53:59 PM »
I'm afraid the command EATTEXT is not recognised, you mean attext?
Using Attext requires templates.. does not summarise the totals into a table format..

What's wrong with the EATTEXT?  (I think that's the command name).

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #8 on: October 10, 2008, 03:02:15 PM »
I'm afraid the command EATTEXT is not recognised, you mean attext?
Using Attext requires templates.. does not summarise the totals into a table format..

What's wrong with the EATTEXT?  (I think that's the command name).

No, EATTEXT is the command name.  What version of ACAD are you running?
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

CAB

  • Global Moderator
  • Seagull
  • Posts: 10376
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #9 on: October 10, 2008, 03:03:38 PM »
if psuedo code means a lisp utility, it'll be more than what we're asking for.
This utility would be very useful to extract an tabulate items in a drawing.
The items can range from a column, a door, a basin, a chair to a piece of floor tile...
Pseudo Code is a list of procedures you want to preform in the order needed.
Something like this:
  • prompt user to select a block for identification
  • Dialog to select attributes to use
  • Prompt user to select blocks with filter to the pattern block
  • Or use all matching blocks in current space
  • Or use all matching blocks in drawing
  • Create a TABLE, structure to be defined
« Last Edit: October 11, 2008, 03:18:54 PM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Arthur Gan

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #10 on: October 10, 2008, 03:45:59 PM »
Here's a simple sample drawing with blocks - (the blocks with attributes are within the circle area).
Thanks you very much for your efforts!

Ah, forgot to say first - welcome on board!
Can you upload the sample drawind with blocks
and remove from there all unused information before
I'm so lazy today to create similar blocks :)

~'J'~



Arthur Gan

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #11 on: October 10, 2008, 03:48:07 PM »
oh.. we're trying out on Bricscad Version 9, not AutoCAD..

I'm afraid the command EATTEXT is not recognised, you mean attext?
Using Attext requires templates.. does not summarise the totals into a table format..

What's wrong with the EATTEXT?  (I think that's the command name).

No, EATTEXT is the command name.  What version of ACAD are you running?

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #12 on: October 10, 2008, 03:53:10 PM »
oh.. we're trying out on Bricscad Version 9, not AutoCAD..
Nevermind then.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

fixo

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #13 on: October 10, 2008, 04:22:29 PM »
Here's a simple sample drawing with blocks - (the blocks with attributes are within the circle area).
Thanks you very much for your efforts!

Ah, forgot to say first - welcome on board!
Can you upload the sample drawind with blocks
and remove from there all unused information before
I'm so lazy today to create similar blocks :)

~'J'~



Try edited version

Code: [Select]
;;======================A2T.lsp===================;;
;;local defun
(defun create-attrib-dcl ()
(setq fname (strcat (getvar "dwgprefix")(vl-filename-base(getvar "dwgname"))".dcl"))
;;;(setq fname (vl-filename-mktemp "summ_atts.dcl"))
(setq fn (open fname "w")) 
(write-line " summattributes : dialog {" fn)
(write-line " label = \"Summarize attributes\";" fn)
(write-line " : text_part {" fn)
(write-line " key = \"txt\";" fn)
(write-line " width = 20;}" fn)
(write-line " : text_part {" fn)
(write-line " label = \"Select attributes\";" fn)
(write-line " width = 20;}" fn)
(write-line " : list_box {" fn)
(write-line " key = \"atts\";" fn)
(write-line " allow_accept=true;" fn)
(write-line " multiple_select=true;" fn) 
(write-line " height = 20;}" fn)
(write-line " ok_cancel;}" fn)
(close fn)
  fname
)
;;local defun
(defun group-by-first (lst / ret tmp)
  (while (car lst)
  (setq tmp (vl-remove-if-not (function (lambda (a)
(eq (car a) (caar lst )))) lst))
  (setq ret (cons tmp ret))
  (setq lst (vl-remove-if (function (lambda (a)
(eq (car a) (caar lst )))) lst))
  (setq tmp nil))
  ret
    )
;;main part
(defun C:A2T(/ acsp adoc atable att_list bname cnt col columns data dcl_id dcl_name elist en ent headers item row rows ss tags user_click)
  (alert "Select single block")
  (setq ss (ssget "+.:S:E" (list (cons 0 "INSERT"))))
  (setq en (ssname ss 0))
    (setq elist (entget en))
    (setq bname (cdr (assoc 2 elist)))
    (while (/= "SEQEND" (setq ent (cdr (assoc 0 elist))))
      (if
  (eq "ATTRIB" ent)

(setq tags (cons (cdr (assoc 2 elist)) tags))

)
      (setq elist (entget (entnext (cdr (assoc -1 elist)))))
      )

(if
   (and
    (setq dcl_name (create-attrib-dcl))
    (> (setq dcl_id (load_dialog dcl_name)) 0))
    (progn
    (new_dialog "summattributes" dcl_id)
    (start_list "atts")
    (mapcar 'add_list tags)
    (end_list)

    (action_tile "cancel" "(done_dialog 0)")
    (action_tile
        "accept"
        (strcat
        "(progn "
        "(setq att_list (mapcar '(lambda (x)(cons x (get_tile x))) tags))"
        "(done_dialog 1))")
    )


    (setq user_click (start_dialog))
    (not (unload_dialog dcl_id))
    (vl-file-delete dcl_name)
    (setq att_list (mapcar 'car att_list))
    (if att_list
      (progn
(alert "Select blocks to summ attribute values")
(setq ss (ssget (list (cons 0 "INSERT")(cons 2 bname))))
  (while (setq en (ssname ss 0))
            (setq elist (entget en))
(while (/= "SEQEND" (setq ent (cdr (assoc 0 elist))))
      (if
(and
  (eq "ATTRIB" ent)
  (member (cdr (assoc 2 elist)) att_list)
  )

(setq data (cons (cons (cdr (assoc 2 elist)) (cdr (assoc 1 elist)))
  data))
)
      (setq elist (entget (entnext (cdr (assoc -1 elist)))))
      )
    (ssdel en ss)
    )
)
      )
    (setq data (group-by-first data))
    (setq data (mapcar (function (lambda(x)(cons (caar x)(mapcar 'cdr x)))) data))
    (if data
    (progn
    (vl-load-com)
 
  (or adoc
    (setq adoc (vla-get-activedocument
  (vlax-get-acad-object))))
  (or acsp (setq acsp (if (= (getvar "TILEMODE") 0)
  (vla-get-paperspace
  adoc)
  (vla-get-modelspace
  adoc))
  )
  )
    (setq columns (length data)
rows (length (car data))
  )

  (setq atable (vla-addtable
acsp
(vlax-3d-point (getpoint "\nUpper left table insertion point: \n"))
(+ 2 rows)
columns
;; rows height (change by suit):
(* (getvar "dimtxt") 1.667)
;; columns width (change by suit):
(* (getvar "dimtxt") 8.333)
       )
  )
  (vla-put-regeneratetablesuppressed atable :vlax-true) 
  (vla-settext atable 0 0 "TITLE") ;(change by suit)

  (setq headers (mapcar 'car data)
  )
 
  (setq col 0
row 1
  )
  (foreach a headers
    (vla-settext atable row col a)
    (setq col (1+ col))
  )
    (setq data (mapcar 'cdr data))

  (setq cnt 1 ;counter
col 0)
   
  (repeat columns
    (setq row 2
  item (car data)
    )
    (foreach i item
      (vla-settext
atable
row
col
i
      )
     (setq row    (1+ row))
      (vla-settext
atable
row
col
(vl-princ-to-string (apply '+ (mapcar 'atof item)))
      )
      )
    (setq col (1+ col)
  row    2
  cnt (1+ cnt)
  data (cdr data)
    )
    )
  (vla-put-regeneratetablesuppressed atable :vlax-false)
  (vlax-release-object atable)
    )
    )
    )
    )
  (princ)
  )
(prompt
  "\n\t\t\t   |-----------------------------|\n"
)
(prompt
  "\n\t\t\t  <|  Start with A2T to execute  |>\n"
)
(prompt
  "\n\t\t\t   |-----------------------------|\n"

(princ)

~'J'~

Arthur Gan

  • Guest
Re: BOM Utility to extract selective attributes from blocks with tabulation
« Reply #14 on: October 11, 2008, 11:06:31 AM »
The interface is right about the purpose of the utility but I'm afraid it does not work now, the text does not display in the table. (refer screen dump).
For the user interface, may I suggest that upon running the command A2T instead of "Select single block", a list of all blocks in the drawings only with Attributes are displayed for us to select multiply Blocks, next all the Attributes of the selected Blocks are displayed in columns corresponding the selected Blocks for us to select multiple Attributes to be extracted.
It then follows with the prompt to select all Blocks within the area and prompt to insert the Table in the drawing.
I hope it is not too much to request for this tool which is surely helpful.
Thanks.