Jump to content

Recommended Posts

Posted

I am creating blocks witch run from tag_1 to tag_6 and then from tag_7 to tag_12 for the next dwg and so on and takes time renaming all the tags for each block. So I like the create my tag_1 to tag_40 in excel, copy it to Autocad, explode in to single line txt and then convert the text to be my attribute tag and then it be just a matter of making the blocks containing of 6 tags each.

 

I've found a txt2att.lsp somewhere but it converts the txt to the attribute value and set the tag name to 'label'. I need it to convert the singe line text to attribute tag.

 

Thanx for any advice or lisp program for that matter. :wink:

Posted

Quick and dirty:

 

(defun c:txt2tag (/ oldcmd ss)
 (setq oldcmd (getvar "CMDECHO")) (setvar "CMDECHO" 0)
 (if (setq ss (ssget (list (cons 0 "TEXT")
   (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
      (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
      (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    (command "-attdef" "" (cdr (assoc 1 (entget e))) "" ""
         (cdr (assoc 10 (entget e))) "")
    (entdel e)))
   (princ "\n<!> No Text Selected <!>"))
 (setvar "CMDECHO" oldcmd)
 (princ))

  • Thanks 2
Posted

O you are a star Lee Mac. Thank you very much!!

Posted

Is it possible to make it select more than one text at a time. I seems like it suppose to do that but it gives an error and just converting one of them.

 

thanx again

Posted

It seems to work for me when I try it on multiple text objects - what error does it give?

Posted

Here is the text after selecting 2 objects and it then continues converting only the 1ste selected one after the rotation is entered:

 

Command: TXT2TAG

Select objects: 1 found

 

Select objects: 1 found, 2 total

 

Select objects:

Requires valid numeric angle or second point.

; error: Function cancelled

 

Specify rotation angle of text :

Posted

Try this for multiple selections

[b][color=BLACK]([/color][/b]defun c:txt2atta [b][color=FUCHSIA]([/color][/b]/ ss i en ed[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not ss[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\nSelect TEXT to Convert to ATTDEF:   "[/color][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"TEXT"[/color][b][color=BLUE])[/color][/b]
                              [b][color=BLUE]([/color][/b]if [b][color=RED]([/color][/b]getvar [color=#2f4f4f]"CTAB"[/color][b][color=RED])[/color][/b]
                                  [b][color=RED]([/color][/b]cons 410 [b][color=PURPLE]([/color][/b]getvar [color=#2f4f4f]"CTAB"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                                  [b][color=RED]([/color][/b]cons 67 [b][color=PURPLE]([/color][/b]- 1 [b][color=TEAL]([/color][/b]getvar [color=#2f4f4f]"TILEMODE"[/color][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq i [b][color=NAVY]([/color][/b]sslength ss[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]minusp [b][color=GREEN]([/color][/b]setq i [b][color=BLUE]([/color][/b]1- i[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq en [b][color=MAROON]([/color][/b]ssname ss i[b][color=MAROON])[/color][/b]
              ed [b][color=MAROON]([/color][/b]entget en[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]wcmatch [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 1 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#2f4f4f]"* *"[/color][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]alert [color=#2f4f4f]"\nString Contains Spaces - Try Again..."[/color][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]progn
              [b][color=GREEN]([/color][/b]entmake [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]cons 0 [color=#2f4f4f]"ATTDEF"[/color][b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 8 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 10 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 11 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 7 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 40 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 41 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 50 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 51 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]cons 70 0[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 71 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 72 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]cons 74 [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 73 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]assoc 210 ed[b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]cons 1 [color=#2f4f4f]""[/color][b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]cons 2 [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 1 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]cons 3 [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 1 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]if [b][color=PURPLE]([/color][/b]assoc 6 ed[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]assoc 6 ed[b][color=PURPLE])[/color][/b]'[b][color=PURPLE]([/color][/b]6 . [color=#2f4f4f]"BYLAYER"[/color][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]if [b][color=PURPLE]([/color][/b]assoc 39 ed[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]assoc 39 ed[b][color=PURPLE])[/color][/b]'[b][color=PURPLE]([/color][/b]39 . 0[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                             [b][color=RED]([/color][/b]if [b][color=PURPLE]([/color][/b]assoc 62 ed[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]assoc 62 ed[b][color=PURPLE])[/color][/b]'[b][color=PURPLE]([/color][/b]62 . 256[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
              [b][color=GREEN]([/color][/b]entdel en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]redraw[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

-David

Posted

thanx david. that works like a dream.

 

(man, i really need to teach myself this programming stuff) :wink:

Posted

Thanks David, but I can't work out why mine won't work though :(

Posted

Lee,

 

It's the ATTDEF ( and TEXT ) prompts that differ when a text style has not been defined yet. That's been around a long long time and has alwys been a pain.

 

Open a new DWG and go thru the prompts

 

Open a DWG that has a STYLE defined

 

There is an extra prompt for text height. -David

 

PS I try never to use ( command ) for either TEXT or ATTDEF. Way too many that that can get whacky.

Posted
Lee,

 

It's the ATTDEF ( and TEXT ) prompts that differ when a text style has not been defined yet. That's been around a long long time and has alwys been a pain.

 

Open a new DWG and go thru the prompts

 

Open a DWG that has a STYLE defined

 

There is an extra prompt for text height. -David

 

PS I try never to use ( command ) for either TEXT or ATTDEF. Way too many that that can get whacky.

 

Ahh, I see now, thanks. No wonder when I tested it on my machine it worked, but maybe not elsewhere.

 

Yes, I must admit, I have had that experience with TEXT, so I resorted to the entmake with that - but I didn't know it applied to ATTDEF also.

 

Many thanks for the heads-up :)

 

Lee

  • 3 months later...
Posted
Try this for multiple selections

 

Not woking when the text has spaces

 

Coud the lisp replace spaces with _ or what ever to be able to convert to attaribute

And add the txt string as a default

Posted

This should deal with spaces:

 

(defun c:txt2atta (/ ss i en ed)
 (vl-load-com)
 (while (not ss)
        (princ "\nSelect TEXT to Convert to ATTDEF:   ")
        (setq ss (ssget (list (cons 0 "TEXT")
                              (cons 410 (getvar "CTAB"))))))
 (setq i (sslength ss))
 (while (not (minusp (setq i (1- i))))
        (setq en (ssname ss i)
              ed (entget en)
              ed (subst (cons 1
                          (vl-string-subst "_" " "
                            (cdr (assoc 1 ed))))
                        (assoc 1 ed) ed))
   (entmake (list (cons 0 "ATTDEF")
                  (assoc 8 ed)
                  (assoc 10 ed)
                  (assoc 11 ed)
                  (assoc 7 ed)
                  (assoc 40 ed)
                  (assoc 41 ed)
                  (assoc 50 ed)
                  (assoc 51 ed)
                  (cons 70 0)
                  (assoc 71 ed)
                  (assoc 72 ed)
                  (cons 74 (cdr (assoc 73 ed)))
                  (assoc 210 ed)
                  (assoc 1 ed)
                  (cons 2 (cdr (assoc 1 ed)))
                  (cons 3 (cdr (assoc 1 ed)))
                  (if (assoc 6 ed) (assoc 6 ed)'(6 . "BYLAYER"))
                  (if (assoc 39 ed) (assoc 39 ed)'(39 . 0))
                  (if (assoc 62 ed) (assoc 62 ed)'(62 . 256))))
   (entdel en))
 (redraw)
 (prin1))

  • Like 1
Posted

What a great guy u r.

 

by the way i edited thr thread

And add the txt string as a default
  • 10 months later...
Posted

above code dealing with space not spaces

the routine can deal with txt txt

but cant with txt txt txt txt

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