Does anybody have a routine for converting text to attributes inside the block?
In my drawing I hv some attribute blocks having some Text in it. I need to change the Texts inside the blocks as Attribute Texts. Please help.. Here I am attaching sample Blocks drawing..
@savinirsb4u wrote:Does anybody have a routine for converting text to attributes inside the block?
In my drawing I hv some attribute blocks having some Text in it. I need to change the Texts inside the blocks as Attribute Texts. Please help.. Here I am attaching sample Blocks drawing..
Listen, You dont have to go thru all the trouble of converting. If you only need to "export" the values to Excel, a lisp routine can do that for you. [at least from what i understand from your PM message]
Data extraction has its limitations [at least here in A2009] .IT can only show you count for similar values but not the TOTAL or sum of the values.
Personally i wouldnt "destroy" the current state of the Dynamic blocks just to create a table.
You couldn't convert a text to attribute in this block by reason of this text is linked with Visibility properties , thus its owner is BlockOwnerHolder, so,
try to redefine (recreate) block, in my opinion only of course
For non dynamic block it may helps:
;; Convert text within block to attribute ;; fixo () 2013 * all rights removed ;; just basic routine and has no error handling ;; you might be able to adapt some of it to your suit. ;; 5/4/13 (defun C:TAT(/ adoc blkdef blkent blkname blkobj cme newattdef taglist tagstr txt txtent txtlist txtobj txtpt txtstr) (alert "Create a copy of drawing before\nthen execute command again!") (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (setq cme (getvar "cmdecho")) (setvar "cmdecho" 0) (if (not (and (setq txt (nentsel "\nSelect text within block: ")) (eq "TEXT" (dxf 0 (entget (car txt)))) ) ;_ end of and ) ;_ end of not (progn (alert "Not a text, exit") (exit) (princ) ) ;_ end of progn ) ;_ end of if (vla-endundomark adoc) (vla-startundomark adoc) (setq txtent (car txt)) (setq blkent (car (last txt))) (setq blkobj (vlax-ename->vla-object blkent)) (if (eq :vlax-true (vla-get-isdynamicblock blkobj)) (progn (alert "This program does not work with dynamic blocks, exit.") (exit) (princ) ) ;_ end of progn ) ;_ end of if (vl-catch-all-apply '(lambda () (progn (foreach a (vlax-invoke blkobj 'getattributes) (setq taglist (cons (vla-get-tagstring a) taglist)) ) ;_ end of foreach (while (member (setq tagstr (strcase (getstring "\nEnter a tag for the attribute: ") ) ;_ end of strcase ) ;_ end of setq taglist ) ;_ end of member (alert "This attribute tag is in use, put another tag!") ) ;_ end of while ) ;_ end of progn ) ;_ end of lambda ) ;_ end of vl-catch-all-apply (setq txtent (car txt) txtpt (trans (dxf 10 (setq txtlist (entget txtent))) blkent 0) txtstr (dxf 1 txtlist) ) ;_ end of setq (setq blkname (vla-get-effectivename blkobj)) (setq blkdef (vla-item (vla-get-blocks adoc) blkname)) (vlax-for obj blkdef (if (and (eq (vla-get-objectname obj) "AcDbText") (eq (vla-get-textstring obj) txtstr) ) ;_ end of and (progn (setq txtobj obj) (setq newattdef (vla-addattribute blkdef (vla-get-height txtobj) acattributemodeverify tagstr (vla-get-insertionpoint txtobj) tagstr (vla-get-textstring txtobj) ) ;_ end of vla-addattribute ) ;_ end of setq (vla-put-alignment newattdef (vla-get-alignment txtobj)) (if (not (zerop (vla-get-alignment txtobj))) (progn (vla-put-textalignmentpoint newattdef (vla-get-textalignmentpoint txtobj) ) ;_ end of vla-put-TextAlignmentPoint ;;; (vla-put-insertionpoint ;;; newattdef ;;; (vla-get-insertionpoint newattdef) ;;; ) ;_ end of vla-put-insertionpoint ) ;_ end of progn ) ;_ end of if (vla-put-layer newattdef (vla-get-layer txtobj)) (vla-put-truecolor newattdef (vla-get-truecolor txtobj)) (vla-put-stylename newattdef (vla-get-stylename txtobj)) (vla-put-rotation newattdef (vla-get-rotation txtobj)) (vla-put-scalefactor newattdef (vla-get-scalefactor txtobj)) (vla-update newattdef) (vla-delete txtobj) ) ;_ end of progn ) ;_ end of if ) ;_ end of vlax-for ;; syncronize all block instances, this line may be commented to your suit (command "_attsync" "_N" blkname ) (setvar "cmdecho" cme) (vla-endundomark adoc) (princ) ) (prompt "\n\t--\tStart command with TAT\t---") (prin1) (or (vl-load-com)(princ))
@Hallex wrote:You couldn't convert a text to attribute in this block by reason of this text is linked with Visibility properties , thus its owner is BlockOwnerHolder, so,
try to redefine (recreate) block, in my opinion only of courseFor non dynamic block it may helps:
;; Convert text within block to attribute ;; fixo () 2013 * all rights removed ;; just basic routine and has no error handling ;; you might be able to adapt some of it to your suit. ;; 5/4/13.....
Nice Oleg.
My concern really is how to "sum" the values collected form "QUANTITY" tag just by using DATA Extraction alone. Not sure with newer version though.
So my thoughts on this is leave the current state of the blocks and write a routine to "EXTRACT" the values.
Then save the data to a CSV or even XLS file [Not really into this one myself, truth is, i'm lacking the knowledge for it ]
I'm proposing this. [notice how the data are hard-coded] and it lacks the lines to write to a file.
<see attached file> to work exclusively on the drawing file from the OP.
[thoughts].... Perhaps using Xdata for data wouldb be better.
EDIT: attached drawing file to test included on this post
Hi pbejse, friend,
I've tried to write all blocks data
inthe named ranges in Excel, attached are 2 routines to write / read
all this data, take a look at please
Sorry, my bad
I used whole library so this function is part of them
and automatically loaded:
;; ;; ;; = return column name by column number = ;; ;; ;; (defun columnchar (col / fst snd) ;; author VK (Vladimir Kleshev) (cond ((or (minusp col) (> col 256)) nil ) ((<= col 26) (chr (+ col 64))) (T (setq fst (rem col 26) snd (fix (/ col 26))) (if (zerop fst) (progn (setq fst 26 snd (1- snd))) ) (strcat (chr (+ snd 64)) (chr (+ fst 64))) ) ) )
Hi Oleg,
Tried your code, but I get a message:
Select text within block: ; error: no function definition: DXF
Is it possible to look at this?
Thanks,
John
Hi John
Unfortunately I don't have news from Oleg for a long time...
But maybe something like this will do the trick.
(defun dxf (a ent) (cdr (assoc a ent)))
Hope that helps
Henrique