Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link between Text, Mtext and Attribute with Field

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
msarqui
7539 Views, 20 Replies

Link between Text, Mtext and Attribute with Field

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:

 

  1. Instead of select a point and click to create a new Mtext, it is possible to click on a existing Text, Mtext or Attribute to simply replace it?
  2. Instead to make a Field only from an Attribute to a Mtext, I would like that the source could be also a Text or a Mtext and the destination could be another Text, Mtext or Attribute. I mean, no matter what kind of source I take, and no matter what kind of destination I put it. The routine will acept all of them (Text, Mtext & Attribute).

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 :

  1. Don’t need to have the leader option.
  2. Instead to just copy the text bettween the source and the destination, I would like to have this with Fields to keep it linked.
  3. With the possibility to choose the layout tab to put the destination.

Thanks for any help,

20 REPLIES 20
Message 2 of 21
pbejse
in reply to: msarqui


@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 @gjrcmb (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

 

Message 3 of 21
msarqui
in reply to: pbejse

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.

Message 4 of 21
pbejse
in reply to: msarqui


@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 

Message 5 of 21
msarqui
in reply to: pbejse

Perfect!!!!!!!!

 

The ListBoxDia "thing" is perfect for easily switching layouts.

 

Thanks and best regards!

 

Message 6 of 21
pbejse
in reply to: msarqui


@msarqui wrote:

...

Thanks and best regards!

 


Anytime msarqui.

 

I'm happy to help. 

 

Cheers

Message 7 of 21
andresep82
in reply to: pbejse

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 Smiley Sad

 

(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?

 

 

Message 8 of 21
andresep82
in reply to: andresep82

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.

 

 

Message 9 of 21
andresep82
in reply to: andresep82

oh my good... unvelievable....

 

"%<\\AcObjProp Object(%<\\_ObjId1 " (itoa objid1) 
							">%).TextString>%" )) 


 "%<\\AcObjProp Object(%<\\_ObjId " (itoa objid1) 
							">%).TextString>%" )) 
Message 10 of 21
ajnowar_4449
in reply to: andresep82

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?

Message 11 of 21
pbejse
in reply to: ajnowar_4449


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

 

 

Message 12 of 21
ajnowar_4449
in reply to: pbejse


@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?

Message 13 of 21
sergiu_ciuhnenco
in reply to: pbejse

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

Message 14 of 21
devitg
in reply to: ajnowar_4449

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)
Message 15 of 21
sergiu_ciuhnenco
in reply to: pbejse

 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

Message 16 of 21
hmsilva
in reply to: sergiu_ciuhnenco


@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


@pbejse

I hope you do not mind my friend!

 

@sergiu_ciuhnenco

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

EESignature

Message 17 of 21
sergiu_ciuhnenco
in reply to: hmsilva

Many Thanks  Hmsilva !!!

Message 18 of 21
hmsilva
in reply to: sergiu_ciuhnenco


@sergiu_ciuhnenco wrote:

Many Thanks  Hmsilva !!!


You're welcome, Sergiu!
Glad I could help

Henrique

EESignature

Message 19 of 21
tung.bui2003
in reply to: hmsilva

Thanks Crazy lisp!!! I'm wondering if we can select multiple text in a rectangular select box like txt2mtxt in autocad?

Message 20 of 21
RichardSF35V
in reply to: pbejse

This is amazing...Hoping you can find some time to make it work in Multileaders and possible from external reference dwg file.

 

Thanks,

Richard

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost