aridzv Posted January 30, 2022 Share Posted January 30, 2022 (edited) On 6/6/2018 at 9:55 AM, great_isme said: .... Can you keep the attribute block angle same as the text before conversion? Before replacing, the text may be having different angle. .... @great_isme try this: (defun c:MtxtToBlk1 (/ sel int ent att spc ang) ;; Tharwat - Date: 19.Jun.2017 ;; (if (and (or (tblsearch "BLOCK" "ROOMTAG") (alert "Attributed Block <ROOMTAG> is not found in drawing <!>") ) (princ "\nSelect Mtexts to be replaced with Attributed Block <ROOMTAG> :") (setq sel (ssget "_:L" '((0 . "MTEXT")))) ) (progn (defun unformatmtext (string / text str) ;; ASMI - sub-function ;; ;; Get string from Formatted Mtext string ;; (setq text "") (while (/= string "") (cond ((wcmatch (strcase (setq str (substr string 1 2))) "\\[\\{}`~]" ) (setq string (substr string 3) text (strcat text str) ) ) ((wcmatch (substr string 1 1) "[{}]") (setq string (substr string 2)) ) ((and (wcmatch (strcase (substr string 1 2)) "\\P") (/= (substr string 3 1) " ") ) (setq string (substr string 3) text (strcat text " ") ) ) ((wcmatch (strcase (substr string 1 2)) "\\[LOP]") (setq string (substr string 3)) ) ((wcmatch (strcase (substr string 1 2)) "\\[ACFHQTW]") (setq string (substr string (+ 2 (vl-string-search ";" string)) ) ) ) ((wcmatch (strcase (substr string 1 2)) "\\S") (setq str (substr string 3 (- (vl-string-search ";" string) 2)) text (strcat text (vl-string-translate "#^\\" " " str)) string (substr string (+ 4 (strlen str))) ) (print str) ) (t (setq text (strcat text (substr string 1 1)) string (substr string 2) ) ) ) ) text ) (setq spc (vlax-get (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)) ) 'block ) ) (repeat (setq int (sslength sel)) (setq ent (ssname sel (setq int (1- int)))) (setq ang (cdr (assoc 50 (entget ent)))) ;; get the Mtext Angle (in radians) and set it to the variable ang (and (setq att (vla-insertblock spc (vlax-3d-point (cdr (assoc 10 (entget ent)))) "ROOMTAG" 1.0 1.0 1.0 ang ;; the block rotation from the Mtext rotation ) ) (vl-some '(lambda (x) (if (eq (strcase (vla-get-tagstring x)) "ROOMNO") (progn (vla-put-textstring x (unformatmtext (cdr (assoc 1 (entget ent)))) ) t ) ) ) (vlax-invoke att 'getattributes) ) (progn (vla-put-layer att (cdr (assoc 8 (entget ent)))) t) (entdel ent) ) ) ) ) (princ) )(vl-load-com) Edited January 30, 2022 by aridzv Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.