Jump to content

Convert text to attribute


rustym

Recommended Posts

Latest code:

 

;; Txt2Att  ( Lee Mac )
;; Converts Single-line Text to Attribute Definition

(defun c:txt2att ( / StringSubst RemovePairs ss ent eLst str dx73 )
 (vl-load-com)
 ;; Lee Mac  ~  27.04.10

 (defun StringSubst ( new pat str )
   (while (vl-string-search pat str)
     (setq str (vl-string-subst new pat str))
   )
   str
 )

 (defun RemovePairs ( lst pairs )
   (vl-remove-if
     (function
       (lambda ( pair )
         (vl-position (car pair) pairs)
       )
     )
     lst
   )
 )

 (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
   
   ( (lambda ( i )
       
       (while (setq ent (ssname ss (setq i (1+ i))))
         (setq eLst (entget ent)
               str  (StringSubst "_" " " (cdr (assoc 1 eLst)))
               dx73 (cdr (assoc 73 eLst)))

         (setq eLst (RemovePairs eLst '( 0 100 1 73 )))

         (if (entmake (append '( (0 . "ATTDEF") ) eLst (list (cons 70    0)
                                                             (cons 74 dx73)
                                                             (cons 1   str)
                                                             (cons 2   str)
                                                             (cons 3   str))))
           (entdel ent)
         )
       )
     )
     -1
   )
 )

 (princ))

  • Like 1
Link to comment
Share on other sites

Not much difference really, the code is what is typed, the LISP is the file itself perhaps, and the routine may refer to the program algorithm

Link to comment
Share on other sites

  • 1 year later...

Lee,

 

Is there any chance I can convince you to go back to this useful utility and adapt it for converting multiline text to multiline attribute? I guess it would need to handle multiple single-line texts and MText as well. Or, at least, it should handle MText since Express Tools has a Text2MText tool that can be used, if necessary.

 

I appreciate you even considering it. Thanks!

 

 

-Patch

Link to comment
Share on other sites

  • 1 year later...

Hi sir,

I am searching a lisp for converting text (inside block) to attribute definition. like your program txt2att. Can you help me. Thanks in advance

 

Manigandan

Link to comment
Share on other sites

  • 1 year later...

Lee, is there any way to modify a line of that code to get to it insert a default "PROMPT" of Drawing Number: .... with the semicolon at the end? Would be awesome if I can change it easily to whatever default I want....even if it means modifying the code.

Link to comment
Share on other sites

Lee, is there any way to modify a line of that code to get to it insert a default "PROMPT" of Drawing Number: .... with the semicolon at the end? Would be awesome if I can change it easily to whatever default I want....even if it means modifying the code.
I think the 3 value is the one you want to change, i.e., substitute your prompt string in place of str in that case. Also, I think the colon is automatically provided by AutoCAD.
Link to comment
Share on other sites

  • 1 year later...

Hi everybody.

 

I need the result of that entmake as an SSGET selection

 

Is there an obvious way of doing that?

 

----

 

(setq result (entmake (list (cons 0 "ATTDEF") ....

 

then I have a function that requires the result of an SSGET

I want to feed result to that function

 

I know Lee Mac has such conversion functions, like (LM:ss->vla ss)

Is there something like a (LM:entmake->ss result) ?

Link to comment
Share on other sites

I need the result of that entmake as an SSGET selection

 

Is there an obvious way of doing that?

 

Use entmakex in place of entmake and add the entity name returned by this function to a selection set using ssadd.

Link to comment
Share on other sites

  • 10 months later...

Lee, It's wonderful lisp,

For example we can converts 100 text to 100 tags

But can we convert 100 tags to 100 blocks?

Txt2Tag2Block

Blocks name should be same.

Link to comment
Share on other sites

Could you explain that question a little more thoroughly?

 

 

What exactly are you starting with? ATTDEF entities loose in the dwg, or is it still text entities ?

 

 

And now you want each of these values in a ATTDEF inside a block.

And presumably you want the block to be inserted, so that the attribute stays in the same position as the text used to be?

 

 

The block definition already exists, it has 1 (or more) attribute , ...

 

 

Right?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...