Results 1 to 3 of 3

Thread: Attribute to table as field, need help to modify please

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2017-09
    Posts
    3
    Login to Give a bone
    0

    Default Attribute to table as field, need help to modify please

    Hello,
    I started to modify a script for make a table that contains attribute of selected block as field.
    i know that is possible to extrat attribute value, but this script is faster and don't require .dxe file and similar.
    i obtain the 99% of the result but I don't understand how to remove the "block name" column from the table

    here the code and i also attach the file

    thanks in advance to everybody

    Code:
    (Defun c:itlist (/ at>att at>item at>set atable cnt cw ena nc nr pt rh)
       (vl-load-com)
       ;; GET_ATTS BY BILL KRAMER
       (defun get_ATTS (EN / EL ATTS)
    (setq EL (entget EN))
    (setq ENA (cdr (assoc 2 EL))) ; wiz
    (if (and (= (cdr (assoc 0 EL)) "INSERT")
    	 (= (cdr (assoc 66 EL)) 1)
        ) ;_ end and
        (progn
    	(setq EN (entnext EN)
    	      EL (entget EN)
    	) ;_ end setq
    	(while (= (cdr (assoc 0 EL)) "ATTRIB")
    	    (setq ATTS (cons (list
    				 (vla-get-ObjectID
    				     (vlax-ename->vla-object EN)
    				 ) ; wiz
    				 (cdr
    				     (assoc 2 EL)
    				 ) ;_ end_cdr
    				 (cdr (assoc 1 EL))
    			     ) ;_ end_list
    			     ATTS
    		       ) ;_ end_cons
    		  EN   (entnext EN)
    		  EL   (entget EN)
    	    ) ;_ end setq
    	) ;_ end while
    	(list ena (reverse ATTS)) ; wiz
        ) ;_ end progn
    ) ;_ end if
       ) ;_ end_defun
       (if	(setq at>set (ssget '((0 . "INSERT"))))
    (progn
        (setq at>att
    	     (mapcar 'get_atts
    		     (vl-remove-if
    			 'listp
    			 (mapcar 'cadr (ssnamex at>set))
    		     ) ;_ end_vl-remove-if
    	     ) ;_ end_mapcar
        ) ;_ end_setq
        (setq PT (getpoint "\nTable insertion point: ")
    	  RH (* 2.0 (getvar "TEXTSIZE"))
    	  CW (* 20.0 (getvar "TEXTSIZE"))
    	  NR (+ 2 (length at>att))
    	  NC (1+ (length (cadar at>att)))
        ) ;_ end_setq
        (setq
    	aTable (vla-addtable
    		   (vla-get-modelspace
    		       (vla-get-activedocument
    			   (vlax-get-acad-object)
    		       ) ;_ end_vla-get-activedocument
    		   ) ;_ end_vla-get-modelspace
    		   (vlax-3d-point PT)
    		   NR
    		   NC
    		   RH
    		   CW
    	       ) ;_ end_vla-addtable
        ) ;_ end_setq
        (vla-setcellvalue aTable 0 0 "Equipment List")
        (vla-setcellvalue aTable 1 0 "Block Name")
        (vla-setcellvalue aTable 1 1 "ITEM")
        (vla-setcellvalue aTable 1 2 "type_of_equipment")
        (vla-setcellvalue aTable 1 3 "AREA" )
        (vla-setcellvalue aTable 1 4 "dwg_data_sheet")
        (vla-setcellvalue aTable 1 5 "material")
        (vla-setcellvalue aTable 1 6 "flowrate")
        (vla-setcellvalue aTable 1 7 "empty_weight")
        (vla-setcellvalue aTable 1 8 "internal_diameter")
        (vla-setcellvalue aTable 1 9 "volume")
        (vla-setcellvalue aTable 1 10 "power")
        (setq CNT 2) ;_ end_setq
        (foreach Item at>att
    	(vla-setcellvalue aTable CNT 0 (car Item))
    	(setq at>item 1)
    	(while (<= at>item (length (cadar at>att)))
    	    (vl-catch-all-apply
    		'(lambda ()
    		     (vla-settext
    			 aTable
    			 CNT
    			 at>item
    			 (strcat
    			     "%<\\AcObjProp Object(%<\\_ObjId "
    			     (itoa (car (nth (1- at>item) (cadr Item))))
    			     ">%).TextString>%"
    			 ) ;_ end_strcat
    		     ) ;_ end_vla-setcellvalue
    		 ) ;_ end_lambda
    	    ) ;_ end_vl-catch-all-apply
    	    (setq at>item (1+ at>item))
    	) ;_ end_while
    	(setq CNT (1+ CNT))
    	;;ready next row
        ) ;_ end_foreach
    ) ;_ end_progn
       ) ;_ end_if
       (princ)
    ) ;_ end_Defun
    Attached Files Attached Files

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Attribute to table as field, need help to modify please

    Here, I modified it for you... My intervention is in blue and red color :

    Code:
    (defun c:itlist ( / get_atts at>att at>item at>set atable cnt cw ena nc nr pt rh )
      (vl-load-com)
      ;; GET_ATTS BY BILL KRAMER
      (defun get_atts ( EN / EL ATTS ENA )
        (setq EL (entget EN))
        (setq ENA (cdr (assoc 2 EL)))                                                                   ; wiz
        (if (and (= (cdr (assoc 0 EL)) "INSERT")
                 (= (cdr (assoc 66 EL)) 1)
            ) ;_ end and
          (progn
            (setq EN (entnext EN)
                  EL (entget EN)
            ) ;_ end setq
            (while (= (cdr (assoc 0 EL)) "ATTRIB")
              (setq ATTS (cons (list
                                 (vla-get-ObjectID
                                   (vlax-ename->vla-object EN)
                                 )                                                                      ; wiz
                                 (cdr
                                   (assoc 2 EL)
                                 ) ;_ end_cdr
                                 (cdr (assoc 1 EL))
                               ) ;_ end_list
                               ATTS
                         ) ;_ end_cons
                    EN   (entnext EN)
                    EL   (entget EN)
              ) ;_ end setq
            ) ;_ end while
            (list ENA (reverse ATTS))                                                                   ; wiz
          ) ;_ end progn
        ) ;_ end if
      ) ;_ end_defun
      (if (setq at>set (ssget '((0 . "INSERT"))))
        (progn
          (setq at>att
                 (mapcar 'get_atts
                         (vl-remove-if
                           'listp
                           (mapcar 'cadr (ssnamex at>set))
                         ) ;_ end_vl-remove-if
                 ) ;_ end_mapcar
          ) ;_ end_setq
          (setq PT (getpoint "\nTable insertion point: ")
                RH (* 2.0 (getvar "TEXTSIZE"))
                CW (* 20.0 (getvar "TEXTSIZE"))
                NR (+ 2 (length at>att))
                                                                                                        ; NC (1+ (length (cadar at>att)))  ; mod by M.R.
                NC (length (cadar at>att))                                                              ; mod by M.R.
          ) ;_ end_setq
          (setq
            aTable (vla-addtable
                     (vla-get-modelspace
                       (vla-get-activedocument
                         (vlax-get-acad-object)
                       ) ;_ end_vla-get-activedocument
                     ) ;_ end_vla-get-modelspace
                     (vlax-3d-point PT)
                     NR
                     NC
                     RH
                     CW
                   ) ;_ end_vla-addtable
          ) ;_ end_setq
          (vla-setcellvalue aTable 0 0 "Equipment List")
          ;|
          (vla-setcellvalue aTable 1 0 "Block Name")
          (vla-setcellvalue aTable 1 1 "ITEM")
          (vla-setcellvalue aTable 1 2 "type_of_equipment")
          (vla-setcellvalue aTable 1 3 "AREA")
          (vla-setcellvalue aTable 1 4 "dwg_data_sheet")
          (vla-setcellvalue aTable 1 5 "material")
          (vla-setcellvalue aTable 1 6 "flowrate")
          (vla-setcellvalue aTable 1 7 "empty_weight")
          (vla-setcellvalue aTable 1 8 "internal_diameter")
          (vla-setcellvalue aTable 1 9 "volume")
          (vla-setcellvalue aTable 1 10 "power")
          |;
          ;;(vla-setcellvalue aTable 1 0 "Block Name")
          (vla-setcellvalue aTable 1 0 "ITEM")
          (vla-setcellvalue aTable 1 1 "type_of_equipment")
          (vla-setcellvalue aTable 1 2 "AREA")
          (vla-setcellvalue aTable 1 3 "dwg_data_sheet")
          (vla-setcellvalue aTable 1 4 "material")
          (vla-setcellvalue aTable 1 5 "flowrate")
          (vla-setcellvalue aTable 1 6 "empty_weight")
          (vla-setcellvalue aTable 1 7 "internal_diameter")
          (vla-setcellvalue aTable 1 8 "volume")
          (vla-setcellvalue aTable 1 9 "power")
                                                                                                        ; mod by M.R.
          (setq CNT 2) ;_ end_setq
          (foreach Item at>att
                                                                                                        ; (vla-setcellvalue aTable CNT 0 (car Item))  ; mod by M.R.
            (setq at>item 1)
            (while (<= at>item (length (cadar at>att)))
              (vl-catch-all-apply
                '(lambda ( )
                   (vla-settext
                     aTable
                     CNT
                                                                                                        ; at>item  ; mod by M.R.
                     (1- at>item)                                                                       ; mod by M.R.
                     (strcat
                       "%<\\AcObjProp Object(%<\\_ObjId "
                       (itoa (car (nth (1- at>item) (cadr Item))))
                       ">%).TextString>%"
                     ) ;_ end_strcat
                   ) ;_ end_vla-setcellvalue
                 ) ;_ end_lambda
              ) ;_ end_vl-catch-all-apply
              (setq at>item (1+ at>item))
            ) ;_ end_while
            (setq CNT (1+ CNT))
            ;;ready next row
          ) ;_ end_foreach
        ) ;_ end_progn
      ) ;_ end_if
      (princ)
    ) ;_ end_defun
    HTH., M.R.

  3. #3
    Member
    Join Date
    2017-09
    Posts
    3
    Login to Give a bone
    0

    Default Re: Attribute to table as field, need help to modify please

    Quote Originally Posted by marko_ribar View Post
    Here, I modified it for you... My intervention is in blue and red color :

    Code:
    (defun c:itlist ( / get_atts at>att at>item at>set atable cnt cw ena nc nr pt rh )
      (vl-load-com)
      ;; GET_ATTS BY BILL KRAMER
      (defun get_atts ( EN / EL ATTS ENA )
        (setq EL (entget EN))
        (setq ENA (cdr (assoc 2 EL)))                                                                   ; wiz
        (if (and (= (cdr (assoc 0 EL)) "INSERT")
                 (= (cdr (assoc 66 EL)) 1)
            ) ;_ end and
          (progn
            (setq EN (entnext EN)
                  EL (entget EN)
            ) ;_ end setq
            (while (= (cdr (assoc 0 EL)) "ATTRIB")
              (setq ATTS (cons (list
                                 (vla-get-ObjectID
                                   (vlax-ename->vla-object EN)
                                 )                                                                      ; wiz
                                 (cdr
                                   (assoc 2 EL)
                                 ) ;_ end_cdr
                                 (cdr (assoc 1 EL))
                               ) ;_ end_list
                               ATTS
                         ) ;_ end_cons
                    EN   (entnext EN)
                    EL   (entget EN)
              ) ;_ end setq
            ) ;_ end while
            (list ENA (reverse ATTS))                                                                   ; wiz
          ) ;_ end progn
        ) ;_ end if
      ) ;_ end_defun
      (if (setq at>set (ssget '((0 . "INSERT"))))
        (progn
          (setq at>att
                 (mapcar 'get_atts
                         (vl-remove-if
                           'listp
                           (mapcar 'cadr (ssnamex at>set))
                         ) ;_ end_vl-remove-if
                 ) ;_ end_mapcar
          ) ;_ end_setq
          (setq PT (getpoint "\nTable insertion point: ")
                RH (* 2.0 (getvar "TEXTSIZE"))
                CW (* 20.0 (getvar "TEXTSIZE"))
                NR (+ 2 (length at>att))
                                                                                                        ; NC (1+ (length (cadar at>att)))  ; mod by M.R.
                NC (length (cadar at>att))                                                              ; mod by M.R.
          ) ;_ end_setq
          (setq
            aTable (vla-addtable
                     (vla-get-modelspace
                       (vla-get-activedocument
                         (vlax-get-acad-object)
                       ) ;_ end_vla-get-activedocument
                     ) ;_ end_vla-get-modelspace
                     (vlax-3d-point PT)
                     NR
                     NC
                     RH
                     CW
                   ) ;_ end_vla-addtable
          ) ;_ end_setq
          (vla-setcellvalue aTable 0 0 "Equipment List")
          ;|
          (vla-setcellvalue aTable 1 0 "Block Name")
          (vla-setcellvalue aTable 1 1 "ITEM")
          (vla-setcellvalue aTable 1 2 "type_of_equipment")
          (vla-setcellvalue aTable 1 3 "AREA")
          (vla-setcellvalue aTable 1 4 "dwg_data_sheet")
          (vla-setcellvalue aTable 1 5 "material")
          (vla-setcellvalue aTable 1 6 "flowrate")
          (vla-setcellvalue aTable 1 7 "empty_weight")
          (vla-setcellvalue aTable 1 8 "internal_diameter")
          (vla-setcellvalue aTable 1 9 "volume")
          (vla-setcellvalue aTable 1 10 "power")
          |;
          ;;(vla-setcellvalue aTable 1 0 "Block Name")
          (vla-setcellvalue aTable 1 0 "ITEM")
          (vla-setcellvalue aTable 1 1 "type_of_equipment")
          (vla-setcellvalue aTable 1 2 "AREA")
          (vla-setcellvalue aTable 1 3 "dwg_data_sheet")
          (vla-setcellvalue aTable 1 4 "material")
          (vla-setcellvalue aTable 1 5 "flowrate")
          (vla-setcellvalue aTable 1 6 "empty_weight")
          (vla-setcellvalue aTable 1 7 "internal_diameter")
          (vla-setcellvalue aTable 1 8 "volume")
          (vla-setcellvalue aTable 1 9 "power")
                                                                                                        ; mod by M.R.
          (setq CNT 2) ;_ end_setq
          (foreach Item at>att
                                                                                                        ; (vla-setcellvalue aTable CNT 0 (car Item))  ; mod by M.R.
            (setq at>item 1)
            (while (<= at>item (length (cadar at>att)))
              (vl-catch-all-apply
                '(lambda ( )
                   (vla-settext
                     aTable
                     CNT
                                                                                                        ; at>item  ; mod by M.R.
                     (1- at>item)                                                                       ; mod by M.R.
                     (strcat
                       "%<\\AcObjProp Object(%<\\_ObjId "
                       (itoa (car (nth (1- at>item) (cadr Item))))
                       ">%).TextString>%"
                     ) ;_ end_strcat
                   ) ;_ end_vla-setcellvalue
                 ) ;_ end_lambda
              ) ;_ end_vl-catch-all-apply
              (setq at>item (1+ at>item))
            ) ;_ end_while
            (setq CNT (1+ CNT))
            ;;ready next row
          ) ;_ end_foreach
        ) ;_ end_progn
      ) ;_ end_if
      (princ)
    ) ;_ end_defun
    HTH., M.R.
    it works like a charm!
    thank you!

Similar Threads

  1. Replies: 7
    Last Post: 2012-10-17, 08:47 PM
  2. Use extracted attribute table to modify block's attributes?
    By Neo_Richard_Blake in forum AutoCAD Tables
    Replies: 3
    Last Post: 2012-02-17, 07:59 PM
  3. use extracted attribute table to modify block's attributes
    By Neo_Richard_Blake in forum AutoCAD LT - General
    Replies: 7
    Last Post: 2011-06-29, 05:41 PM
  4. Attribute Value extraction into Table Field
    By steven_mott33 in forum Dynamic Blocks - Technical
    Replies: 7
    Last Post: 2010-09-04, 10:25 PM
  5. Replies: 1
    Last Post: 2008-11-04, 05:48 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
  •