Jump to content

Text to Attribute Text - Quick Answer please!


harrison-matt

Recommended Posts

Does anyone know a way to convert text or mtext into an attribute instead of creating an attribute and placing the text in the same location? Is there a way to code this through VL, or DXF? If there is any tips on how or a way to start, please point me in the right direction.

 

Thank you,

Matthew

Link to comment
Share on other sites

Give this a shot:

 

[i][color=#990099];; Txt2Att  ( Lee Mac )[/color][/i]
[i][color=#990099];; Converts Single-line Text to Attribute Definition[/color][/i]

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:txt2att [b][color=RED]([/color][/b] [b][color=BLUE]/[/color][/b] StringSubst RemovePairs ss ent eLst str dx73 [b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b]
 [i][color=#990099];; Lee Mac  ~  27.04.10[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] StringSubst [b][color=RED]([/color][/b] new pat str [b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-string-search[/color][/b] pat str[b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] str [b][color=RED]([/color][/b][b][color=BLUE]vl-string-subst[/color][/b] new pat str[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED])[/color][/b]
   str
 [b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] RemovePairs [b][color=RED]([/color][/b] lst pairs [b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]vl-remove-if[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] pair [b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]vl-position[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] pair[b][color=RED])[/color][/b] pairs[b][color=RED])[/color][/b]
       [b][color=RED])[/color][/b]
     [b][color=RED])[/color][/b]
     lst
   [b][color=RED])[/color][/b]
 [b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#a52a2a]"_:L"[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#a52a2a]"TEXT"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   
   [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] i [b][color=RED])[/color][/b]
       
       [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] eLst [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b]
               str  [b][color=RED]([/color][/b]StringSubst [b][color=#a52a2a]"_"[/color][/b] [b][color=#a52a2a]" "[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b] eLst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
               dx73 [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]73[/color][/b] eLst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

         [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] eLst [b][color=RED]([/color][/b]RemovePairs eLst [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]100[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]73[/color][/b] [b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

         [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entmake[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]append[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#a52a2a]"ATTDEF"[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] eLst [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]70[/color][/b]    [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]
                                                             [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]74[/color][/b] dx73[b][color=RED])[/color][/b]
                                                             [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]1[/color][/b]   str[b][color=RED])[/color][/b]
                                                             [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]2[/color][/b]   str[b][color=RED])[/color][/b]
                                                             [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]3[/color][/b]   str[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]entdel[/color][/b] ent[b][color=RED])[/color][/b]
         [b][color=RED])[/color][/b]
       [b][color=RED])[/color][/b]
     [b][color=RED])[/color][/b]
     [b][color=#009900]-1[/color][/b]
   [b][color=RED])[/color][/b]
 [b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

Link to comment
Share on other sites

There you go. Text replaced with attributes.

 

Nice coding Lee.

 

Cheers Alan - its actually come up in the past, so I refined some old code - its amazing how your coding standard changes over time...

Link to comment
Share on other sites

Cheers Alan - its actually come up in the past, so I refined some old code - its amazing how your coding standard changes over time...

HaHa no kidding.

I find myself apologizing for posting older code.

 

Slick thinking on RemovePairs. :thumbsup: A nice inverse of what I was thinking in that thread at the Swamp last week, when Hangman (I think) was trying to edit dxf codes.

Link to comment
Share on other sites

Thanks mate - that approach works Ok to do it with Text, because Text and Attdefs share quite a lot of DXF codes, but MText might be more troublesome...

Link to comment
Share on other sites

Thanks mate - that approach works Ok to do it with Text, because Text and Attdefs share quite a lot of DXF codes, but MText might be more troublesome...

Most definitely. Plus, you'd be forced to strip out all formatting. What a pain.

Link to comment
Share on other sites

Lee,

 

I really need to pick your brain on VL, I admit it is fantastic.

 

Thanks.

 

Kind Regards,

Matthew

Link to comment
Share on other sites

Well Lee,

 

I feel more can be done through VL and I would love to have a shot at it, however, i haven't found much material or well written code with examples. I also hear it is much faster, more resilient at catching errors, and more complex. All of which intrigues me.

 

-Matt

Link to comment
Share on other sites

Well Lee,

 

I feel more can be done through VL and I would love to have a shot at it, however, i haven't found much material or well written code with examples. I also hear it is much faster, more resilient at catching errors, and more complex. All of which intrigues me.

 

-Matt

Have you looked through the AutoCAD help file(s), specifically under AutoLISP, Visual LISP, DXF?

Link to comment
Share on other sites

Help files, Visual LISP Developer's Bible and AutoCAD 2000 AutoLISP Reference (includes VLisp) are your best resources. They are floating around the internet, but if you'll PM me your email addy, I'll shoot them over.

Link to comment
Share on other sites

I agree with Alan, that the VLIDE help files are your best resource, coupled with coding examples - just search the forums, Alan and I have posted thousands of examples.

 

Oh and FYI AutoLISP using DXF is actually faster than VL :)

Link to comment
Share on other sites

I agree with Alan, that the VLIDE help files are your best resource, coupled with coding examples - just search the forums, Alan and I have posted thousands of examples.

HaHa, how very true. :)

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