Mleader text content match

Mleader text content match

Anonymous
Not applicable
2,440 Views
5 Replies
Message 1 of 6

Mleader text content match

Anonymous
Not applicable

I have a lisp routine that matches text from one location to another. However, this command does not work with Mleaders. Does anyone have a fix for this?

 

This is the current lisp I have.

 

(DEFUN C:TMA (/ a b c)
 (SETVAR "CMDECHO" 0)
 (SETQ a (ENTGET (CAR (NENTSEL "\nSelect needed text!"))))
 (redraw (cdr (assoc -1 a)) 3)
 (SETQ c (CDR (ASSOC 1 a)))
 (while (SETQ b (NENTSEL "\nSelect text to changed!"))
 (setq b (ENTGET (CAR b)))
 (SETQ b (SUBST (ASSOC 1 a) (ASSOC 1 b) b)) (ENTMOD b) (entupd (cdr (assoc -1 b)))
 )
 (redraw (cdr (assoc -1 a)) 4)
 (SETVAR "CMDECHO" 1)
 (princ)
 )

0 Likes
2,441 Views
5 Replies
Replies (5)
Message 2 of 6

Ajilal.Vijayan
Advisor
Advisor

Hi,

Try with this code.

I guess you want to select a Dtext/Mtext and apply that text value to Mleader.

This code will not work if your source object is Mleader.

Spoiler
(DEFUN C:TMA (/ a b c)
 (SETVAR "CMDECHO" 0)
 (SETQ a (ENTGET (CAR (NENTSEL "\nSelect needed text!"))))
 (redraw (cdr (assoc -1 a)) 3)
 (SETQ c (CDR (ASSOC 1 a)))
 (while (SETQ b (NENTSEL "\nSelect text to changed!"))
 (setq b (ENTGET (CAR b)))
 (if( = (cdr(assoc 0 b)) "MULTILEADER")
 (SETQ b (SUBST (cons 304 (cdr(ASSOC 1 a))) (ASSOC 304 b) b))
 (SETQ b (SUBST (ASSOC 1 a) (ASSOC 1 b) b))
 );if
 (ENTMOD b) (entupd (cdr (assoc -1 b)))
 )
 (redraw (cdr (assoc -1 a)) 4)
 (SETVAR "CMDECHO" 1)
 (princ)
 )

 

0 Likes
Message 3 of 6

redtransitconsultants
Collaborator
Collaborator

Try this code out below - I left your command name "TMA" the same but replaced most of your command. This allows for matching from a source object (Dtext, Mtext, or MLeader) to a destination object (Dtext, Mtext, or MLeader) and will maintain text widths where applicable.

 

;;Match Text - Dtext, Mtext, MLeader
;;
;;By Steve Hill with Red Transit Consultants, LLC on 11/16/2015
;;
;;

(defun c:TMA ( / oobj nobj nstrg nwidth)
(prompt "\nThis command uses the current multileader style in conversion process. Variations in command depend on multileader style. Current style is '")
(prompt (getvar "cmlstyle"))
(prompt "'... \n")

(vl-load-com)
;;Select match source object
(setq oobj (vlax-ename->vla-object (car (nentsel "\nSelect source mtext, dtext, or mleader: "))))
(if (= (vlax-get-property oobj 'ObjectName) "AcDbMText")
(progn
(setq nstrg (vlax-get-property oobj 'TextString))
(setq nwidth (vlax-get-property oobj 'Width))
);progn
)

(if (= (vlax-get-property oobj 'ObjectName) "AcDbText")
(progn
(setq nstrg (vlax-get-property oobj 'TextString))
(setq nwidth 0)
);progn
)

(if (= (vlax-get-property oobj 'ObjectName) "AcDbMLeader")
(progn
(setq nstrg (vlax-get-property oobj 'TextString))
(setq nwidth (vlax-get-property oobj 'TextWidth))
);progn
)

;;Select match desitnation object
(setq nobj (vlax-ename->vla-object (car (nentsel "\nSelect destination mtext, dtext, or mleader: "))))

(if (= (vlax-get-property nobj 'ObjectName) "AcDbMText")
(progn
(vlax-put-property nobj 'TextString nstrg)
(vlax-put-property nobj 'Width nwidth)
);progn
)

(if (= (vlax-get-property nobj 'ObjectName) "AcDbText")
(progn
(vlax-put-property nobj 'TextString nstrg)
);progn
)

(if (= (vlax-get-property nobj 'ObjectName) "AcDbMLeader")
(progn
(vlax-put-property nobj 'TextString nstrg)
(vlax-put-property nobj 'TextWidth nwidth)
);progn
)
(princ)
);defun

Steve Hill,Civil Designer / .NET Developer / AutoCAD and AutoCAD Civil 3D Certified Professional
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

http://redtransitconsultants.com/
Autodesk Exchange Store
Twitter | LinkedIn | YouTube

Message 4 of 6

Anthony.Lopez
Community Visitor
Community Visitor

hi! I really like your lisp, I wander if you can modify only to change the text style and the width, what I mean everything you have except match the sentences, I do use to match font style and Hight and the width, but I don't need to match the sentences or the words in the call out of one leader to another,

please let me know, I will appreciate it.. thanks again

 

Anthony Lopez

ant7lop@gmail.com 

0 Likes
Message 5 of 6

calderg1000
Mentor
Mentor

Regards @Anthony.Lopez 

Add the four lines that contain comments in their corresponding locations.

(progn
 (setq nstrg (vlax-get-property oobj 'TextString))
 (setq nwidth (vlax-get-property oobj 'TextWidth))
 (setq nst (vlax-get-property oobj 'textstylename));get the text style
 (setq nht (vlax-get-property oobj 'Textheight));get the text height
 );progn

 

(progn
 (vlax-put-property nobj 'TextString nstrg)
 (vlax-put-property nobj 'TextWidth nwidth)
 (vlax-put-property nobj 'textstylename nst);change the text style
 (vlax-put-property nobj 'Textheight nht);change the text height
 );progn

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 6 of 6

redtransitconsultants
Collaborator
Collaborator

@Anthony.Lopez... following up on @calderg1000 post, here's the full code adding Text Style and Text Height, while also commenting out the Text String match ability. I changed the command name to TMA2 to differentiate. Note - I did not run this and test, but it should work.

 

;;Match Text - Dtext, Mtext, MLeader
;;
;;By Steve Hill with Red Transit Consultants, LLC on 11/16/2015
;;Revised by Carlos Calderon G and Steve Hill
;;
;;Rev: Commented out Text String matching, added ability to match text style and height
;;

(defun c:TMA2 ( / oobj nobj nstrg nwidth)
 (prompt "\nThis command uses the current multileader style in conversion process. Variations in command depend on multileader style. Current style is '")
 (prompt (getvar "cmlstyle"))
 (prompt "'... \n")

 (vl-load-com)
;;Select match source object
 (setq oobj (vlax-ename->vla-object (car (nentsel "\nSelect source mtext, dtext, or mleader: "))))
 (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText")
 (progn
 ;(setq nstrg (vlax-get-property oobj 'TextString))
 (setq nwidth (vlax-get-property oobj 'Width))
 (setq nst (vlax-get-property oobj 'textstylename));get the text style
 (setq nht (vlax-get-property oobj 'Textheight));get the text height
 );progn
 )

 (if (= (vlax-get-property oobj 'ObjectName) "AcDbText")
 (progn
 ;(setq nstrg (vlax-get-property oobj 'TextString))
 (setq nwidth 0)
 (setq nst (vlax-get-property oobj 'textstylename));get the text style
 (setq nht (vlax-get-property oobj 'Textheight));get the text height
 );progn
 )

 (if (= (vlax-get-property oobj 'ObjectName) "AcDbMLeader")
 (progn
 ;(setq nstrg (vlax-get-property oobj 'TextString))
 (setq nwidth (vlax-get-property oobj 'TextWidth))
 (setq nst (vlax-get-property oobj 'textstylename));get the text style
 (setq nht (vlax-get-property oobj 'Textheight));get the text height
 );progn
 )

;;Select match desitnation object
 (setq nobj (vlax-ename->vla-object (car (nentsel "\nSelect destination mtext, dtext, or mleader: "))))

 (if (= (vlax-get-property nobj 'ObjectName) "AcDbMText")
 (progn
 ;(vlax-put-property nobj 'TextString nstrg)
 (vlax-put-property nobj 'Width nwidth)
 (vlax-put-property nobj 'textstylename nst);change the text style
 (vlax-put-property nobj 'Textheight nht);change the text height
 );progn
 )

 (if (= (vlax-get-property nobj 'ObjectName) "AcDbText")
 (progn
 ;(vlax-put-property nobj 'TextString nstrg)
 (vlax-put-property nobj 'textstylename nst);change the text style
 (vlax-put-property nobj 'Textheight nht);change the text height
 );progn
 )

 (if (= (vlax-get-property nobj 'ObjectName) "AcDbMLeader")
 (progn
 ;(vlax-put-property nobj 'TextString nstrg)
 (vlax-put-property nobj 'TextWidth nwidth)
 (vlax-put-property nobj 'textstylename nst);change the text style
 (vlax-put-property nobj 'Textheight nht);change the text height
 );progn
 )
 (princ)
);defun

 

Steve Hill,Civil Designer / .NET Developer / AutoCAD and AutoCAD Civil 3D Certified Professional
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

http://redtransitconsultants.com/
Autodesk Exchange Store
Twitter | LinkedIn | YouTube

0 Likes