Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert Text to Attribute inside Block

14 REPLIES 14
Reply
Message 1 of 15
savinirsb4u
5033 Views, 14 Replies

Convert Text to Attribute inside Block

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..

14 REPLIES 14
Message 2 of 15
pbejse
in reply to: savinirsb4u


@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.

 

Message 3 of 15
Hallex
in reply to: savinirsb4u

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))

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 15
pbejse
in reply to: Hallex


@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 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..... 

 


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 Smiley LOL]

 

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

 

Message 5 of 15
Hallex
in reply to: pbejse

I will be see your files later, sorry, friend
Regards,
Oleg
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 15
Hallex
in reply to: pbejse

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

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 7 of 15
pbejse
in reply to: Hallex

Missing sub:  - >  columnchar

 

Can you post the code my friend Smiley Happy

 

 

Message 8 of 15
Hallex
in reply to: pbejse

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)))
	 )
	)
  )

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 9 of 15
pbejse
in reply to: Hallex

Great.

Thank you Oleg
Message 10 of 15
Hallex
in reply to: pbejse

Would you post the rest of code to do the job?
I'm stacked completely to solve it, sorry 🙂
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 11 of 15
pbejse
in reply to: Hallex


@Hallex wrote:
Would you post the rest of code to do the job?
I'm stacked completely to solve it, sorry 🙂

 

No problem Oleg.I'll take care of it. 

 

 Wish the OP start responding soon. Nevertheless I will keep your code and hope to learn from it.

 

Appreciate your help. Cheers  thumbsup.gif

Message 12 of 15
JEeten
in reply to: Hallex

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

Message 13 of 15
hmsilva
in reply to: JEeten

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

 

 

 

EESignature

Message 14 of 15
JEeten
in reply to: hmsilva

Thanks, that did the Trick! Smiley Happy

Message 15 of 15
hmsilva
in reply to: JEeten

You're welcome, John
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost