Author Topic: Putting selected text string as Default Value for selected attribute  (Read 3028 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
Hey guys I am creating block grids for our library. I have laid them out and have preliminary codes underneath them and once these codes are approved I will need to take the text and put it as the default value for the attribute. I already have the text and attribute in place but what I need help with is taking the text string and putting it as the default attribute value. Has anyone done anything like this that they'd be willing to share with me. See the attached file. Thanks

ELOQUINTET

  • Guest
Re: Putting selected text string as Default Value for selected attribute
« Reply #1 on: April 15, 2008, 05:00:33 PM »
Hey guys I posted this awhile back but got no hits for whatever reason. I am bumping it because now I actually need help on this. I found a routine that will allow me to select dtext and it will convert it into an attribute but there are a few problems still. The first one is that the justification of the text is middle center but when I run the routine it changes this to left. I need the attribute justification to be middle center but when I change it the text moves and with the strings being different lengths it's a disaster. I would like it to work on mtext to begin with because this is what I am starting with but am having to explode it to dtext right now to use this. I would also like the modified attribute to be placed on a different layer so I can keep track of which ones have been completed. The routine also puts the text as the Tag name which is not what I need. I have uploaded a sample drawing to show what I'm starting with and the desired results to see if anyone has any ideas. Thanks in advance.


Code: [Select]
;Tip1791:  TXT2ATTDEF.LSP  TEXT TO ATTRIBUTES              (c)2002, Sanjay Kulkarni

(defun C:T2A ()
  (setq PCMDECHO (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq TXT1 (entget (car (entsel "\nSelect Text : "))))
  (setq IFTXT (cdr (assoc 0 TXT1)))
  (while (/= IFTXT "TEXT")
    (setq
      TXT1
       (entget
         (car
           (entsel
             (strcat
               "\nSelection Error !! You selected "
               IFTXT
               "! \nPlease Select Text : "
             ) ;_ end of strcat
           ) ;_ end of entsel
         ) ;_ end of car
       ) ;_ end of entget
    ) ;_ end of setq
    (setq IFTXT (cdr (assoc 0 TXT1)))
  ) ;_ end of while
  (setq TXT1VAL (cdr (assoc 1 TXT1)))
  (setq TXT1IP (cdr (assoc 10 TXT1)))
  (setq TXT1HT (cdr (assoc 40 TXT1)))
  (setq TXT1ROT (cdr (assoc 50 TXT1)))
  (setq APRMPT (getstring T "\nAttribute prompt : "))
  (entdel (cdar TXT1))
  (setq PAFLAGS (getvar "AFLAGS"))
  (setvar "AFLAGS" 0)
  (command
    "attdef"
    ""
    TXT1VAL
    APRMPT
    TXT1VAL
    TXT1IP
    TXT1HT
    (/ (* TXT1ROT 180) (/ 22.0 7.0))
  ) ;_ end of command
  (setvar "AFLAGS" PAFLAGS)
  ;;(alert "\n\t(c) 2000 SanganakSakha \n\tSanganakSakha@ivillage.com")
  (setvar "CMDECHO" PCMDECHO)
  (princ)
)
;defun txt2attdef
;;(alert
;;  "\t\t* AutoCAD 14 & AutoCAD 2000/2000i/2002 *\n\n\nThis routine converts the selected string to an attribute definition. \n\nTag and Default value of the new attribute are the same as the string being converted. \n\nThe new Attribute definition by default will be with ICVP value 'NNNN'. \n\nYou can change any/all attributes of this attdef subsequently using 'ddmodify' command. \n\n\nType 'txt2attdef' to execute.\n\n"
;;) ;_ end of alert
;;End Of Routine

ELOQUINTET

  • Guest
Re: Putting selected text string as Default Value for selected attribute
« Reply #2 on: April 15, 2008, 05:34:05 PM »
You know guys after doing a little more searching on the net I found a routine which does exactly what I need and wanted to share it with you. I though I recall there being a terrycadd here but not sure. Anyway Terry Miller wherever you are thank you veeeeeerrrry much

Code: [Select]
;-------------------------------------------------------------------------------
; Program Name: TAM.lsp [TAM R2]
; Created By:   Terry Miller (Email: terrycadd@yahoo.com)
;               (URL: http://web2.airmail.net/terrycad)
; Date Created: 9-20-05
; Function:     Matches text, mtext and attribute text with the selected text,
;               mtext or attribute text.
;-------------------------------------------------------------------------------
; Revision History
; Rev  By     Date    Description
;-------------------------------------------------------------------------------
; 1    TM   9-20-05   Initial version. Included TM.lsp, Text Match.
; 2    TM   5-9-07    Added Loop to c:TAM to be able to revise more entities.
;-------------------------------------------------------------------------------
; c:TAM - Text and Attribute Match
;-------------------------------------------------------------------------------
(defun c:TAM (/ EntList@ EntName^ EntPick@ EntType$ Loop Match$ Next$ Text$)
  (princ "\nText and Attribute Match")
  (if (setq EntPick@ (nentsel "\nSelect text or attribute text to match: "))
    (progn
      (setq EntName^ (car EntPick@)
            EntList@ (entget EntName^)
            Match$ (if (assoc 1 EntList@) (cdr (assoc 1 EntList@)))
            Loop (if Match$ t nil)
            Next$ ""
      );setq
      (while Loop
        (if (setq EntPick@ (nentsel (strcat "\nSelect " Next$ "text or attribute text to replace with \"" Match$ "\": ")))
          (setq EntName^ (car EntPick@)
                EntList@ (entget EntName^)
                Text$ (if (assoc 1 EntList@) (cdr (assoc 1 EntList@)))
          );setq
          (setq Text$ nil)
        );if
        (if Text$
          (progn
            (setq EntList@ (entmod (subst (cons 1 Match$) (assoc 1 EntList@) EntList@))
                  EntType$ (cdr (assoc 0 EntList@))
            );setq
            (entupd EntName^)
            (if (or (= EntType$ "MTEXT")(= EntType$ "TEXT"))
              (command "REGEN")
            );if
          );progn
          (progn
            (princ "\nNo text or attribute text selected to replace.")
            (setq Loop nil)
          );progn
        );if
        (setq Next$ (if (= Next$ "") "next " ""))
      );while
    );progn
    (princ "\nNo text or attribute text selected to match.")
  );if
  (princ)
);defun c:TAM
;-------------------------------------------------------------------------------
; c:TM - Text Match
;-------------------------------------------------------------------------------
(defun c:TM (/ Cnt# EntList1@ EntName1^ EntList2@ EntName2^ Match$ SS&)
  (princ "\nText Match")
  (princ "\nSelect text or mtext to match")
  (if (setq EntName1^ (car (entsel)))
    (setq EntList1@ (entget EntName1^))
  );if
  (if (or (= (cdr (assoc 0 EntList1@)) "TEXT")(= (cdr (assoc 0 EntList1@)) "MTEXT"))
    (progn
      (setq Match$ (cdr (assoc 1 EntList1@)))
      (princ (strcat "\nSelect text or mtext to replace with " Match$))
      (if (setq SS& (ssget '((-4 . "<OR")(0 . "MTEXT")(0 . "TEXT")(-4 . "OR>"))))
        (progn
          (command "UNDO" "BEGIN")
          (setq Cnt# 0)
          (repeat (sslength SS&)
            (setq EntName2^ (ssname SS& Cnt#)
                  EntList2@ (entget EntName2^)
            );setq
            (setq EntList2@ (subst (cons 1 Match$) (assoc 1 EntList2@) EntList2@))
            (entmod EntList2@)
            (setq Cnt# (1+ Cnt#))
          );repeat
          (command "UNDO" "END")
        );progn
        (princ "\nNo text or mtext selected.")
      );if
    );progn
    (princ "\nNo text or mtext selected.")
  );if
  (princ)
);defun c:TM
;-------------------------------------------------------------------------------
(princ)

terrycadd

  • Guest
Re: Putting selected text string as Default Value for selected attribute
« Reply #3 on: April 15, 2008, 05:56:24 PM »
Your veeeeeerrrry much welcome!  :wink:

Terry

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Putting selected text string as Default Value for selected attribute
« Reply #4 on: April 15, 2008, 06:35:14 PM »
Hi Dan,
I see you found something that works for you. But since I took the time to come up with this lisp for you I figured I'd post it anyway. Converts Text &/or MText to an attribute having IDEN1_TAG for the Tag and a default value of the selected text/mtext's value. Works with Center or Topleft MText or most any Text.

Hope you can still find it useful.

Jeff
Code: [Select]
(defun c:txt2att (/ algn att ent idx inspt obj space ss sstemp)
  (vl-load-com)
  (setq space (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
  (while (setq ss (ssget '((0 . "TEXT,MTEXT"))))
    (setq idx -1)
    (while (setq ent (ssname ss (setq idx (1+ idx))))
      (setq algn nil)
      (if (eq (cdr (assoc 0 (entget ent))) "MTEXT")
(progn
  ;;this is Mtext, get specific props.
  (setq obj (vlax-ename->vla-object ent))
  (setq inspt (vla-get-insertionpoint obj)
algn (vla-get-attachmentpoint obj)
)
  (setq sstemp (ssadd))
  (ssadd ent sstemp)
  (command "explode" ent)
  (setq ent (entlast))
  (setq sstemp nil)
  )
)
      (setq ent (vlax-ename->vla-object ent))
      (setq att (vla-addattribute space
  (vla-get-height ent)
  acAttributeModeNormal
  "Iden1 Tag"
  (vla-get-insertionpoint ent)
  "IDEN1_TAG"
  (vla-get-textstring ent)
  )
    )
      (vla-put-alignment att (if algn
       (cond ((= algn 5) acAlignmentMiddleCenter)
     (t acAlignmentTopLeft)
     )
       (vla-get-alignment ent)
       )
)
       (if (/= 0 (vla-get-alignment att))
      (vla-put-TextAlignmentPoint att (if algn
inspt
(vla-get-TextAlignmentPoint ent)
)
)
)
      (vla-put-layer att "0")
      (vla-delete ent)
      )
    )
  (princ)
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Putting selected text string as Default Value for selected attribute
« Reply #5 on: April 15, 2008, 08:45:20 PM »
FYI, this works with just about anything with a string in it.
http://www.theswamp.org/index.php?topic=6874.msg261785#msg261785
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Putting selected text string as Default Value for selected attribute
« Reply #6 on: April 16, 2008, 08:49:44 AM »
O wow thanks guys I will give these a test too. I apologize for getting you to develop something that was already done Jeff but I suppose it's good practice anyhow right. I peaked at yours and I do like how it changes the layer which the other does not. Also thanks CAB for the link I'll try this one too.

ELOQUINTET

  • Guest
Re: Putting selected text string as Default Value for selected attribute
« Reply #7 on: April 16, 2008, 09:04:40 AM »
Oops I forgot to put one thing in my attributes. How hard would it be to set constant to yes in the attribute properties? I'm actually refreshing my memory as far as what the various settings are for right now. I like the way the routine works Jeff. CAB I get this error on yours and I'm assuming it's due to the fact I'm using 2002.

Command: ; error: AutoCAD variable setting rejected: "TABLEINDICATOR" 0

ELOQUINTET

  • Guest
Re: Putting selected text string as Default Value for selected attribute
« Reply #8 on: April 16, 2008, 09:08:35 AM »
Aha my memory serves me well Terry 8-)

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Putting selected text string as Default Value for selected attribute
« Reply #9 on: April 16, 2008, 01:37:24 PM »
Oops I forgot to put one thing in my attributes. How hard would it be to set constant to yes in the attribute properties?
In my code you'd just change this:
acAttributeModeNormal
to this:
acAttributeModeConstant

ELOQUINTET

  • Guest
Re: Putting selected text string as Default Value for selected attribute
« Reply #10 on: April 16, 2008, 01:43:20 PM »
thank you thank you Jeff.  :oops: I could've figured that out if I had a second to look at it.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.