Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
msarqui
Posts: 139
Registered: ‎09-14-2010
Message 1 of 12 (1,755 Views)
Accepted Solution

Link between Text, Mtext and Attribute with Field

1755 Views, 11 Replies
01-15-2013 08:27 AM

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,


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 

*Expert Elite*
pbejse
Posts: 2,511
Registered: ‎11-24-2009
Message 2 of 12 (1,727 Views)

Re: Link between Text, Mtext and Attribute with Field

01-15-2013 08:25 PM 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

 

Distinguished Contributor
msarqui
Posts: 139
Registered: ‎09-14-2010
Message 3 of 12 (1,705 Views)

Re: Link between Text, Mtext and Attribute with Field

01-16-2013 05:44 AM 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.

*Expert Elite*
pbejse
Posts: 2,511
Registered: ‎11-24-2009
Message 4 of 12 (1,681 Views)

Re: Link between Text, Mtext and Attribute with Field

01-16-2013 09:48 PM 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 

Distinguished Contributor
msarqui
Posts: 139
Registered: ‎09-14-2010
Message 5 of 12 (1,663 Views)

Re: Link between Text, Mtext and Attribute with Field

01-17-2013 05:38 AM in reply to: pbejse

Perfect!!!!!!!!

 

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

 

Thanks and best regards!

 

*Expert Elite*
pbejse
Posts: 2,511
Registered: ‎11-24-2009
Message 6 of 12 (1,655 Views)

Re: Link between Text, Mtext and Attribute with Field

01-17-2013 06:25 AM in reply to: msarqui

msarqui wrote:

...

Thanks and best regards!

 


Anytime msarqui.

 

I'm happy to help. 

 

Cheers

Valued Contributor
andresep82
Posts: 53
Registered: ‎04-18-2013
Message 7 of 12 (1,425 Views)

Re: Link between Text, Mtext and Attribute with Field

06-20-2013 12:52 AM 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 :smileysad:

 

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

 

 

Valued Contributor
andresep82
Posts: 53
Registered: ‎04-18-2013
Message 8 of 12 (1,390 Views)

Re: Link between Text, Mtext and Attribute with Field

06-20-2013 10:35 AM 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.

 

 

Valued Contributor
andresep82
Posts: 53
Registered: ‎04-18-2013
Message 9 of 12 (1,347 Views)

Re: Link between Text, Mtext and Attribute with Field

06-24-2013 01:00 AM in reply to: andresep82

oh my good... unvelievable....

 

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


 "%<\\AcObjProp Object(%<\\_ObjId " (itoa objid1) 
							">%).TextString>%" )) 
New Member
AJRight
Posts: 2
Registered: ‎11-14-2013
Message 10 of 12 (1,066 Views)

Re: Link between Text, Mtext and Attribute with Field

11-14-2013 04:42 PM 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?

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.