• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    Valued Contributor
    msarqui
    Posts: 87
    Registered: ‎09-14-2010
    Accepted Solution

    Link between Text, Mtext and Attribute with Field

    286 Views, 5 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,

    Please use plain text.
    *Expert Elite*
    Posts: 2,066
    Registered: ‎11-24-2009

    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

     

    Please use plain text.
    Valued Contributor
    msarqui
    Posts: 87
    Registered: ‎09-14-2010

    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.

    Please use plain text.
    *Expert Elite*
    Posts: 2,066
    Registered: ‎11-24-2009

    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 

    Please use plain text.
    Valued Contributor
    msarqui
    Posts: 87
    Registered: ‎09-14-2010

    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!

     

    Please use plain text.
    *Expert Elite*
    Posts: 2,066
    Registered: ‎11-24-2009

    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

    Please use plain text.