Hi guys
I have this routine ConstructField.lsp from here (http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Extract-Field-Expression/td-p/3364401...). It was made by gjrcmb (He does not put his name into)
This routine do its the job very well, but now I would like to have some improvement.The routine makes a Field between an Attribute and a Mtext. In resume, It takes the « Value » of an Attribute and puts it in a Mtext. So, if I change the Attrribute, the Mtext will follow. Also, I can choose if the Mtext will be placed in the same layout or in another layout. However, I would like to have 2 particular changes:
Exemple: If my source is an Attribute, I will be able to select a Text, Mtext or another Attribute to destination. If my source is a Text,I will be able to select a Mtext, Attibute or another Text to destination and so on…
If my second issue is to hard, I will be glad only with the first one.
By the way, I saw this routine CopyTextV1-3.lsp at Lee-Mac (http://www.lee-mac.com/copytext.html). The CTx command is pretty similar to what I need, but :
Thanks for any help,
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
@msarqui wrote:Hi guys
I have this routine ConstructField.lsp from here (http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Extract-Field-Expression/td-p/3364401...). It was made by @Anonymous (He does not put his name into)
.......
Exemple: If my source is an Attribute, I will be able to select a Text, Mtext or another Attribute to destination. If my source is a Text,I will be able to select a Mtext, Attibute or another Text to destination and so on…
Thanks for any help,
Quick mod
(defun c:ConstructField (/ enam elst objid fldexp enm2) (vl-load-com) (while (null (setq enam (car (nentsel "\nSelect TEXT/MTEXT/ATTRIBUTE: ")))) (princ "Nothing Selected") ) (cond ((and (setq elst (entget enam)) (setq elst (member (cdr (assoc 0 elst)) '("ATTRIB" "TEXT" "MTEXT"))) (setq objid (vla-get-ObjectId (vlax-ename->vla-object enam))) (setq fldexp (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa objid) ">%).TextString>%")) (setvar "cmdecho" 0) (setq glay (Strcase (getstring "\nSpecify Layout Tab to Place MText Object On: "))) (progn (If (and (not (= glay "")) (member glay (mapcar 'strcase (cons "MODEL" (layoutlist))))) (setvar 'Ctab glay)) T) (setq enm2 (car (nentsel "\nSelect String: "))) (setq enam (member (cdr (assoc 0 (entget enm2))) '("ATTRIB" "TEXT" "MTEXT"))) (not (vla-put-textstring (vlax-ename->vla-object enm2) fldexp)) (setvar "cmdecho" 1) (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport) ) ) ) (vl-some '(lambda (j) (if (null (eval (car j))) (princ (cadr j)) )) '((elst "\nSelected Entity is Not valid for Field value.") (enm2 "\nNothing Selected") (enam "\nSelected Entity is Not valid for Field value.")) ) (princ) )
As for this one:
@msarqui wrote:By the way, I saw this routine CopyTextV1-3.lsp at Lee-Mac (http://www.lee-mac.com/copytext.html). The CTx Thanks for any help,
You can leave a message on his weblink msarqui and ask for the additional options
HTH
Hello pbejse
I put the routine from Lee-Mac as an example only.
Analyzing your routine, I had one last idea that seems (to me) impossible with lisp, but still I want to share with you: instead of choosing the layout tab by typing its name on the command line, it would be possible to just click on the layout tab to choose it ?
But do not worry if this is not possible or if is to hard, since the routine you did is exactly what I asked.
I'm starting to run out of compliments for you because once again the routine you made is really good. I am very grateful for your work.
@msarqui wrote:Hello @pbejse
......Iam verygratefulfor your work.
You are welcome msarqui.
@msarqui wrote:
Analyzing your routine, I had one last idea that seems (to me) impossible with lisp, but still I want to share with you: instead of choosing the layout tab by typing its name on the command line, it would be possible to just click on the layout tab to choose it ?
But do not worry if this is not possible or if is to hard, since the routine you did is exactly what I asked.
Not sure if you can do that with newer versions of Autocad.
Look here: --> Navigate Layout Tab
We can modify the code using the routine from that thread.
[Attached file: ConstructField2.lsp]
HTH
Cheers
I was going to open a new post, but it is Perfect¡¡¡¡
I I have been searching and trying to apply this rutine to a ssget selection,but i cant do it
(defun C:test (/ rfont rent rfx rht rob ent i blks objid fldexp pt) (setq blks (ssget '((0 . "INSERT")))) (if blks (progn (setq len (sslength blks) i 0 ) (setq ent (entget (ssname blks i))) (if (assoc 66 ent) (progn (/= "SEQEND" (cdr (assoc 0 ent))) (setq ent (entget (entnext (cdr (assoc -1 ent))))) (if (= "ATTRIB" (cdr (assoc 0 ent))) (progn ;;;;;;;;;;;;;;;;;;;;;;;; (setq objid (vla-get-ObjectId (vlax-ename->vla-object ent))) (setq fldexp (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa objid) ">%).TextString>%")) (setvar "cmdecho" 0) (command "._LAYOUT" "S" "A00") (setq pt (getpoint "\nSpecify First Corner of MText Object: ")) (command "._MTEXT" pt pause fldexp "") (setvar "cmdecho" 1) ;;;;;;;;;;;;;;;;;;;;;;;;;; );end prong );end if (setq i (1+ i)) );end prong );end if );end prong );end if (princ) )
some help?
Only I need a small push.... i do it.........but only when an attribute exists.....
(vl-load-com) (defun C:test (/ rfont rent rfx rht rob ent i blks objid fldexp pt) (setq lst '() i 0 *ms* (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ) (setq blks (ssget '((0 . "INSERT")))) (if blks (progn (repeat (setq len (sslength blks)) (setq a (entnext(ssname blks i))) (setq b (entnext(entnext(ssname blks i)))) (setq a1 (entget a)) (setq b1 (entget b)) (setq tlst (list a1 b1)) (setq lst (cons tlst lst)) (setq i (1+ i)) );end repeat (foreach item lst (if (and (= "ATTRIB" (cdr (assoc 0 a1))) (= "DEPENDENCIA" (cdr (assoc 2 a1))) );end and (if (and (= "ATTRIB" (cdr (assoc 0 b1))) (= "SUP_UTIL" (cdr (assoc 2 b1))) );end and (progn (setq objid (vla-get-ObjectId (vlax-ename->vla-object a))) (setq objid1 (vla-get-ObjectId (vlax-ename->vla-object b))) (setq fldexp (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa objid) ">%).TextString>%" "%<\\AcObjProp Object(%<\\_ObjId1 " (itoa objid1) ">%).TextString>%" )) (setvar "cmdecho" 0) (command "._LAYOUT" "S" "A00") (setq pt (getpoint "\nSpecify First Corner of MText Object: ")) (setq pt2 (polar pt (/ (* 270 pi) 180) 10)) (command "._MTEXT" pt pt2 fldexp "") (setvar "cmdecho" 1) );end prong );end if );end if );end prong );end if ;);end prong ;);end if );end foreach item lst (princ) )
the field of the second attibute It appears "######"
i sure that it is a bilge, but i need help.
oh my good... unvelievable....
"%<\\AcObjProp Object(%<\\_ObjId1 " (itoa objid1) ">%).TextString>%" ))
"%<\\AcObjProp Object(%<\\_ObjId " (itoa objid1) ">%).TextString>%" ))
Is there anyway to then filter out the MText formating characters? Such as the width specifications and other formatting like \W0.8500{\L....} is there anyway that in the code that defines the field that those characters or information can be filtered out?
@ajnowar_4449 wrote:
Is there anyway to then filter out the MText formating characters? Such as the width specifications and other formatting like \W0.8500{\L....} is there anyway that in the code that defines the field that those characters or information can be filtered out?
Are you wanting to leave the formatting from the source TEXT/MTEXT entity but filter them out on the field value? Not sure it can be done , I tried to do it manually but no joy. As long as you can show me it can be done manually then i will give it a try.
But if you're willing to forego the character formating on the source then sure it can be done that way.
@pbejse wrote:
@ajnowar_4449 wrote:Is there anyway to then filter out the MText formatting characters? Such as the width specifications and other formatting like \W0.8500{\L....} is there anyway that in the code that defines the field that those characters or information can be filtered out?
Are you wanting to leave the formatting from the source TEXT/MTEXT entity but filter them out on the field value? Not sure it can be done , I tried to do it manually but no joy. As long as you can show me it can be done manually then I will give it a try.
But if you're willing to forego the character formatting on the source then sure it can be done that way.
You got it.
It's a band-aid for a bigger issue at our office involving standards but, I was trying to see if I could link a multiline mtext attribute drawing title to the title block sheet title or vice versa and either I lose the underline formatting our standards dictate for the drawing title when linking the sheet name to the drawing title; and when done the other way, I gain all the MTEXT formatting from the multiline attribute which has no way (that we know of) to filter out the formatting characters to just display the text. This scenario is only viable when there is only one drawing per sheet and wouldn't help on say a detail page.
I guess what I am trying to do is see if its possible to have attributes be dynamic (in regards to their content) when linked to one another but, I guess the only way to do that would be to pass it to a database and then link both blocks with the desired attributes back to said database?
PBEJSE, your lisp I that I am searching for a long time ,but I need a little change in it , I need to choose multiple attribute in model space , and link them to a Text , If is possible to be a comma " , "between the attributes
Thanks in advance !!!!
Is is NOT mine
;| The UnFormat function below was written by John Uhden. I have made some small modifications to John's original code to optimize it for running inside StripMtext. Thanks to you John! SD |; ;; UnFormat by John Uhden ;; Primary function to perform the format stripping: ;; Arguments: ;; Mtext - the text string to be Unformatted ;; Formats - a string containing some or all of ;; the following characters: ;; ;; A - Alignment ;; C - Color ;; F - Font ;; H - Height ;; L - Underscore ;; O - Overscore ;; P - Linefeed (Paragraph) ;; Q - Obliquing ;; S - Spacing (Stacking) ;; T - Tracking ;; W - Width ;; ~ - Non-breaking Space ;; Optional Formats - ;; * - All formats ;; Returns: ;; nil - if not a valid Mtext object ;; Text - the Mtext textstring with none, some, or all ;; of the formatting removed, depending on what ;; formats were present and what formats were ;; specified for removal. ;; (DEFUN UNFORMAT (MTEXT FORMATS / ALL FORMAT1 FORMAT2 FORMAT3 TEXT STR) (AND MTEXT FORMATS (= (TYPE MTEXT) 'STR) (= (TYPE FORMATS) 'STR) (SETQ FORMATS (STRCASE FORMATS)) (SETQ TEXT "") (SETQ ALL T) (IF (= FORMATS "*") (SETQ FORMATS "S" FORMAT1 "\\[LO`~]" FORMAT2 "\\[ACFHQTW]" FORMAT3 "\\P" ) (PROGN (SETQ FORMAT1 "" FORMAT2 "" FORMAT3 "") (FOREACH ITEM '("L" "O" "~") (IF (VL-STRING-SEARCH ITEM FORMATS) (SETQ FORMAT1 (STRCAT FORMAT1 "`" ITEM)) (SETQ ALL NIL) ) ) (IF (= FORMAT1 "") (SETQ FORMAT1 NIL) (SETQ FORMAT1 (STRCAT "\\[" FORMAT1 "]")) ) (FOREACH ITEM '("A" "C" "F" "H" "Q" "T" "W") (IF (VL-STRING-SEARCH ITEM FORMATS) (SETQ FORMAT2 (STRCAT FORMAT2 ITEM)) (SETQ ALL NIL) ) ) (IF (= FORMAT2 "") (SETQ FORMAT2 NIL) (SETQ FORMAT2 (STRCAT "\\[" FORMAT2 "]")) ) (IF (VL-STRING-SEARCH "P" FORMATS) (SETQ FORMAT3 "\\P") (SETQ FORMAT3 NIL ALL NIL) ) T ) ) (WHILE (/= MTEXT "") (COND ((WCMATCH (STRCASE (SETQ STR (SUBSTR MTEXT 1 2))) "\\[\\{}]") (SETQ MTEXT (SUBSTR MTEXT 3) TEXT (STRCAT TEXT STR) ) ) ((AND ALL (WCMATCH (SUBSTR MTEXT 1 1) "[{}]")) (SETQ MTEXT (SUBSTR MTEXT 2)) ) ((AND FORMAT1 (WCMATCH (STRCASE (SUBSTR MTEXT 1 2)) FORMAT1)) (SETQ MTEXT (SUBSTR MTEXT 3)) ) ((AND FORMAT2 (WCMATCH (STRCASE (SUBSTR MTEXT 1 2)) FORMAT2)) (SETQ MTEXT (SUBSTR MTEXT (+ 2 (VL-STRING-SEARCH ";" MTEXT)))) ) ((AND FORMAT3 (WCMATCH (STRCASE (SUBSTR MTEXT 1 2)) FORMAT3)) (IF (OR (EQ "" TEXT) ;_ added JB 1/15/2007 (= " " (SUBSTR TEXT (STRLEN TEXT))) (= " " (SUBSTR MTEXT 3 1)) ) (SETQ MTEXT (SUBSTR MTEXT 3)) (SETQ MTEXT (SUBSTR MTEXT 3) TEXT (STRCAT TEXT " ")) ) ) ((AND (VL-STRING-SEARCH "S" FORMATS) (WCMATCH (STRCASE (SUBSTR MTEXT 1 2)) "\\S")) (SETQ STR (SUBSTR MTEXT 3 (- (VL-STRING-SEARCH ";" MTEXT) 2)) TEXT (STRCAT TEXT (VL-STRING-TRANSLATE "#^\\" "/^\\" STR)) MTEXT (SUBSTR MTEXT (+ 4 (STRLEN STR))) ) ) (1 (SETQ TEXT (STRCAT TEXT (SUBSTR MTEXT 1 1)) MTEXT (SUBSTR MTEXT 2) ) ) ) ) ) TEXT ) ;;;(princ "\nStripMtext v3.08 by John Uhden & Steve Doman\nStart by typing \"STRIPMTEXT\" ") ;;;(princ)
One more time for : PBEJSE, your lisp ( ConstructField2.lsp ) is that I am searching for a long time ,but I need a little change in it , I need to choose multiple attribute in model space , and link them to a Text , If is possible to be a comma " , "between the attributes
Thanks in advance !!!! Forgot to mention before lisp names
@sergiu_ciuhnenco wrote:
One more time for : PBEJSE, your lisp ( ConstructField2.lsp ) is that I am searching for a long time ,but I need a little change in it , I need to choose multiple attribute in model space , and link them to a Text , If is possible to be a comma " , "between the attributes
Thanks in advance !!!! Forgot to mention before lisp names
I hope you do not mind my friend!
pBe's code, revised to allow multiple strings selection, and paste all fields separated by commas in a single text line...
Hope this helps,
Henrique
Thanks Crazy lisp!!! I'm wondering if we can select multiple text in a rectangular select box like txt2mtxt in autocad?
This is amazing...Hoping you can find some time to make it work in Multileaders and possible from external reference dwg file.
Thanks,
Richard