TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Arthur Gan on October 10, 2008, 11:48:49 AM

Title: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 10, 2008, 11:48:49 AM
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?
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Matt__W on October 10, 2008, 11:55:17 AM
What's wrong with the EATTEXT?  (I think that's the command name).
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: T.Willey 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.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: fixo 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)
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan 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)
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: fixo 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'~

Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan 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.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan 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).
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Matt__W 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?
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: CAB 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:
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan 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'~


Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan 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?
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Matt__W on October 10, 2008, 03:53:10 PM
oh.. we're trying out on Bricscad Version 9, not AutoCAD..
Nevermind then.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: fixo 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'~
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan 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.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: fixo on October 11, 2008, 01:06:46 PM
Okay, draw this table manually, please, say 3-4 rows
Not clearly enough for me how it must looks like
Then upload screenshot here :oops:

~'J'~
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 11, 2008, 02:52:03 PM
thanks for continuing, here's my sketch of the user interface..
let me know if you need explanation.
thanks!
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: fixo on October 11, 2008, 04:00:17 PM
Still swamped..
Check your post, please

~'J'~
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 13, 2008, 01:23:45 AM
just checkout AutoCAD's EATTEXT, your are right, it is similar to what this BOM request.
i've not worked with AutoCAD since R14 and neither any of our customers have shown us this feature..
this request was conceived when we visited a prospect who was requesting to evaluate Bricscad and i take is as our responsibility to understand their drafting requirements to proposed them a suitable product or how best Bricscad can work for them..
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: GDF on October 13, 2008, 11:43:33 AM
I'm late to the party...go to this site:
www.waun.org

Ask Peter Jamtgaard for the routine below:

Code: [Select]
    ;***************************************************************************************
    ;***************************************************************************************

    ; Table Magic Autodesk University 2006 Lecture
    ; Written By: Peter Jamtgaard P.E. copr 2007 all rights reserved
    ; The compilation of Visual LISP functions create AutoCAD tables
    ; Each function or subroutine has a header to explain its function
    ; along with a listing of variables descriptions.
    ; These routines are based on AutoCAD 2007 Visual LISP functions.

    ; This file includes: C:BillOfMaterials
    ; C:BOMDialog
    ;                       C:CSVFileToTable
    ;                       C:Schedule

    ;***************************************************************************************
    ;***************************************************************************************

    ; This functions uses a dialog box to allow the user to change the costs of blocks
    ; and to exclude blocks from the bill of materials


Gary
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: CAB on October 13, 2008, 12:15:02 PM
Download can be found here:
http://forums.augi.com/showthread.php?t=51846&highlight=table+magic
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: T.Willey on October 13, 2008, 01:28:11 PM
Here is my contribution ( I was bored ).  I'm sure you will have to change the row height and column width ( colored in red ), but it works.  Just place all code in one file, and place the .dcl file in a support path, and load the file and run it.  Enjoy.  Hope you learn from it also.   :-)

Edit: Updated code.  I was going to leave the old, but you can't strike through in code, so I just took it out.  I was getting some errors, so I fixed them.
Code: [Select]
(defun c:Test (/ ActDoc cSpace ss cnt Ent EntData tempList tempName BlkNameList DiaRtn TagNValueList BlkName RowCnt tempDiaRtn
    tempInsPt ValueList tempTbl ColCnt MaxRowCnt)
   
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vla-EndUndoMark ActDoc)
    (vla-StartUndoMark ActDoc)
    (setq cSpace (vlax-get ActDoc (if (equal (getvar 'CVport) 1) 'PaperSpace 'ModelSpace)))
    (if
        (and
            (setq ss (ssget "x" '((0 . "INSERT") (66 . 1))))
            (setq cnt -1)
            (while (setq Ent (ssname ss (setq cnt (1+ cnt))))
                (setq EntData (entget Ent))
                (if (setq tempList (assoc (setq tempName (cdr (assoc 2 EntData))) BlkNameList))
                    (setq BlkNameList (subst (cons tempName (cons Ent (cdr tempList))) tempList BlkNameList))
                    (setq BlkNameList (cons (list tempName Ent) BlkNameList))
                )
            )
            (setq BlkNameList (vl-sort BlkNameList '(lambda (a b) (< (strcase (car a)) (strcase (car b))))))
            (setq DiaRtn (MultiSelect (mapcar 'car BlkNameList) "Select blocks to extract attributes." nil))
        )
        (foreach i DiaRtn
            (setq TagNValueList nil)
            (setq ValueList nil)
            (setq tempList (nth i BlkNameList))
            (setq BlkName (car tempList))
            (setq RowCnt (1+ (length tempList)))
            (setq MaxRowCnt RowCnt)
            (setq Ent (cadr tempList))
            (while
                (and
                    (setq Ent (entnext Ent))
                    (setq EntData (entget Ent))
                    (= (cdr (assoc 0 EntData)) "ATTRIB")
                )
                (setq TagNValueList (cons (list (cdr (assoc 2 EntData)) (cdr (assoc 1 EntData))) TagNValueList))
            )
            (if
                (and
                    (setq tempDiaRtn (MultiSelect (mapcar 'car TagNValueList) "Select attributes to extract." nil))
                    (setq tempInsPt (getpoint "\n Select upper left hand corner for table insert."))
                )
                (progn
                    (foreach j tempDiaRtn
                        (setq ValueList (cons (nth j TagNValueList) ValueList))
                    )
                    (foreach j (cddr tempList)
                        (setq Ent j)
                        (while
                            (and
                                (setq Ent (entnext Ent))
                                (setq EntData (entget Ent))
                                (= (cdr (assoc 0 EntData)) "ATTRIB")
                            )
                            (if (setq tempList (assoc (setq tempTag (cdr (assoc 2 EntData))) ValueList))
                                (setq ValueList (subst (cons tempTag (cons (cdr (assoc 1 EntData)) (cdr tempList))) tempList ValueList))
                            )
                        )
                    )
                    (setq tempTbl
                        (vlax-invoke
                            cSpace
                            'AddTable
                            tempInsPt
                            RowCnt
                            (setq ColCnt (length ValueList))
                            [color=red](/ 3 32.)
                            0.5[/color]
                        )
                    )
                    (vla-put-RegenerateTableSuppressed tempTbl :vlax-true)
                    (vla-put-TitleSuppressed tempTbl :vlax-false)
                    (vla-SetText tempTbl 0 0 BlkName)
                    (vl-catch-all-apply 'vla-MergeCells (list tempTbl 0 0 0 (1- ColCnt)))
                    (vla-put-HeaderSuppressed tempTbl :vlax-false)
                    (setq ColCnt 0)
                    (foreach j ValueList
                        (setq RowCnt 1)
                        (foreach k j
                            (if (< RowCnt MaxRowCnt)
                                (vla-SetText tempTbl RowCnt ColCnt k)
                                (prompt (strcat "\n Extra value in block: " BlkName ", Tag: " (car j) ", Value: " k))
                            )
                            (setq RowCnt (1+ RowCnt))
                        )
                        (setq ColCnt (1+ ColCnt))
                    )
                    (vla-put-RegenerateTableSuppressed tempTbl :vlax-false)
                )
            )
        )
    )
    (vla-Regen ActDoc acActiveViewport)
    (vla-EndUndoMark ActDoc)
    (princ)
)
Sub needed
Code: [Select]
(defun MultiSelect (Listof Message Toggle / DiaLoad tmpStr tmpTog tmpList)

(setq DiaLoad (load_dialog "MyDialogs.dcl"))
(if (new_dialog "MultiSelect" DiaLOad)
(progn
(start_list "listbox" 3)
(mapcar 'add_list Listof)
(end_list)
(if Message
(set_tile "text1" Message)
)
(if (not Toggle)
(mode_tile "toggle1" 1)
)
(mode_tile "listbox" 2)
(action_tile "accept"
"(progn
(setq tmpStr (get_tile \"listbox\"))
(if Toggle
(setq tmpTog (get_tile \"toggle1\"))
)
(done_dialog 1)
)"
)
(action_tile "cancel" "(done_dialog 0)")
(if (= (start_dialog) 1)
(progn
(if tmpStr
(setq tmpList (read (strcat "(" tmpStr ")")))
)
(if (= tmpTog "1")
(cons T tmpList)
tmpList
)
)
)
)
)
)
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 13, 2008, 02:26:15 PM
I've copied the codes and run it successfully, it'll be good if the totals can be calculated and display in the last row, can enhance this program?
For the width and height, I made a wild guess and after several tries I got it right, you see I do not know Autolisp, did not write a single program...
And I'm amazed by the codings.. did you type every single letter?
I used Notepad and it is cumbersome to make sure the file type is All Files to save as .lsp and not getting easier to copy files into certain folders using Microsoft XP.
May I ask which text/program editor you used to code it?
Thank you very much for your contribution, it is most appreciated!
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: T.Willey on October 13, 2008, 02:45:16 PM
It could be done, but I don't have time now, real work has happened.   :|

I use Notepad++ to write my lisp code in.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: CAB on October 13, 2008, 03:00:28 PM
Arthur,
You may type VLIDE at the command prompt to activate the LISP editor within ACAD.
Open your lisp in there. You will find are many features to help you edit & troubleshoot the lisp.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: fixo on October 14, 2008, 09:43:58 AM
thanks for continuing, here's my sketch of the user interface..
let me know if you need explanation.
thanks!
Thank you mr. Picasso for the nice picture
Give this a try again

~'J'~

Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 15, 2008, 12:43:18 PM
Thanks for this version A2T-v3, tried but failed.. it prompts for sample_att_ext_table.dcl?
Is there a .dcl file needed?
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: CAB on October 15, 2008, 02:36:21 PM
The routine creates its own dcl files in the folder where the DWG is found.
It uses a full path so it should be able to find them again.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 15, 2008, 03:16:58 PM
Here's a screen dump of the error, it doesn't seem to able to find the .dcl file though I've included in the Support File search path (Settings/Support/Files...)
Can you please help identify the problem?
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: CAB on October 15, 2008, 04:09:34 PM
Try this version.
It was finding the file but there was a bug in the DCL syntax.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: It's Alive! on October 15, 2008, 05:51:11 PM
You guys are fast, I’m still working on mine
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: CAB on October 15, 2008, 07:25:43 PM
Wow, that looks good. :-o
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: T.Willey on October 15, 2008, 07:26:44 PM
Dan is cheating though.  That isn't plan dcl.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: It's Alive! on October 15, 2008, 08:10:04 PM
Dan is cheating though.  That isn't plan dcl.

 :evil:
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: fixo on October 16, 2008, 05:44:13 AM
Try this version.
It was finding the file but there was a bug in the DCL syntax.


Thanks, Alan
Regards,

Oleg

~'J'~
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 16, 2008, 05:53:54 AM
I tried with this edited version, the .dcl works but then the program terminates with the attached error.
Is there any prior settings needed before running the program?
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: T.Willey on October 16, 2008, 12:32:34 PM
Can you show a picture of the finished table you desire?  Maybe we can help better with that information.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 16, 2008, 09:06:02 PM
Hi pietari,
The DCL works now but after it prompts to insert the table, it bumps out with the error message.
No table was inserted. Can you help?

Try this version.
It was finding the file but there was a bug in the DCL syntax.


Thanks, Alan
Regards,

Oleg

~'J'~
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 16, 2008, 09:21:27 PM
Here's a brief output format I made from Ms-Excel.
The Item Description is the Block Name and the Area, Model Name, Cost... are the attributes extracted from the blocks.
The totals and quantities are important as it'll serve this program objective.
For AutoCAD's EATTEXT, it does not provide the total and quantities so I'm sure AutoCAD users also find this version useful too.
Can you show a picture of the finished table you desire?  Maybe we can help better with that information.
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: It's Alive! on October 16, 2008, 10:09:50 PM
So from every block you would only need to extract the attribute tags
Area, Model Name, and Cost?
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 17, 2008, 02:11:12 AM
the blocks and attribute tags are variables, one may select certain blocks and certain of the attributes tags to extract only.
the program will be too rigid and limited to use with specific block names and specific attribute tags only.
you see, in a building plan there are room names, furniture, electrical, mechanical, plumbing block symbols...floor tiles.. so the BOM utility should be flexible to allow for selective Blocks and Attribute Tags to be extracted with a quantity and total summary.
the AutoCAD's EATTEXT is what we need in this BOM utility but unfortunately it does not calculate the quantities and totals.
the quantities and totals should also allow an option to break-on Block's category, if possible. ie. Windows/Casement Windows, Windows/Sliding Windows.. etc. the group is Windows and the categories are Casement and Sliding..
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: fixo on October 17, 2008, 11:33:20 AM
You guys are fast, I’m still working on mine
The same with me :)

~'J'~
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: It's Alive! on October 17, 2008, 11:49:43 AM
So this is where it gets tricky..
BTY Eattext will calculate the total number of equal blocks…. Since the output of EatText can be a table entity, the end user can add columns, rows and cells that can contain formulas to do their calculations. See the attached Drawing and picture.

Unfortunately Bricscad does not yet support table entities or the field entities needed to contain the formulas. This would mean that if totals (calculations) are needed,  the code would have to look for a specific attribute tags, I.e. “Cost” and know that the attribute text is a floating point number with a currency precision.  IMHO something this complex is not worth pursuing until those needed entities are implemented, given the dynamic nature of blocks ( it would be nearly impossible to cover everyone’s needs)

The good news is that Table entities and fields seem to be implemented in the ODA libraries. So if a specific company had a library of blocks that conformed to a standard and where specific attributes needed to be calculated the code could be written to look for those specific attributes and perform the calculations needed.


Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: It's Alive! on October 17, 2008, 11:50:59 AM
You guys are fast, I’m still working on mine
The same with me :)

~'J'~

Copy Cat  :-D
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 17, 2008, 12:59:58 PM
good to learn of AutoCAD's Table entity and feature to add formulas.
since Bricscad does not have it, i'm not aware of it since most AutoCAD customers do not highlight it to me, this goes to tell how many customers here are aware or knows how to use blocks with attributes!
anyway, i look forward to your finished code..

So this is where it gets tricky..
BTY Eattext will calculate the total number of equal blocks…. Since the output of EatText can be a table entity, the end user can add columns, rows and cells that can contain formulas to do their calculations. See the attached Drawing and picture.

Unfortunately Bricscad does not yet support table entities or the field entities needed to contain the formulas. This would mean that if totals (calculations) are needed,  the code would have to look for a specific attribute tags, I.e. “Cost” and know that the attribute text is a floating point number with a currency precision.  IMHO something this complex is not worth pursuing until those needed entities are implemented, given the dynamic nature of blocks ( it would be nearly impossible to cover everyone’s needs)

The good news is that Table entities and fields seem to be implemented in the ODA libraries. So if a specific company had a library of blocks that conformed to a standard and where specific attributes needed to be calculated the code could be written to look for those specific attributes and perform the calculations needed.



Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 17, 2008, 01:03:43 PM
this code still does not work, can you help to make it work?
Try this version.
It was finding the file but there was a bug in the DCL syntax.

Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 17, 2008, 01:10:33 PM
i tried this edited version from cab?
is this originally coded by you?
would appreciate if can you help to make it run?
You guys are fast, I’m still working on mine
The same with me :)

~'J'~
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: It's Alive! on October 20, 2008, 03:35:02 PM
Getting Close

Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: It's Alive! on October 20, 2008, 10:58:25 PM
Give this a try, there is still lots of work to do as you will see. 
The command it A2T


Oh yea .. you will need .NET 2.0 or better to run this
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: Arthur Gan on October 21, 2008, 12:29:10 AM
Excellent beta! the program logic is correct but the table labels need to be corrected ie.
Block Table should be name of Block or one of the defined attribute tag eg. Door, Windows or Toilet so if Toilet there should be an attribute tag named Group such that wash basin, urinals, water closets can be grouped into one table named Toilets
There should also be header labels for Model Number, Tradename, Product and Material
Title: Re: BOM Utility to extract selective attributes from blocks with tabulation
Post by: It's Alive! on October 21, 2008, 12:39:16 AM
I also need to tally up the duplicate blocks and provide a quantity column. There seems to be something weird going on with the row height, it doesn’t want to stick in certain instances. 

Strange how the background on the form is black, I thought I hard coded it to be white..hmmm

Dan