mhmtlgrr Posted June 19, 2017 Posted June 19, 2017 Dear all, I need a lisp routine which basicly performs the action below: I have only room number as mtext objects. What I want to achieve is: I defined a block with attribute inside named ROOM_NO, I want to replace each mtext object with this block while getting the value into the attribute. The issue comes from migrating the drawing from Revit to AutoCad. Revit exports the room tags as mtext objects and I need to covert them to proper blocks with attibute. I have over 3000 rooms which is why a lisp routing comes in handy. Regards, MA Quote
Tharwat Posted June 19, 2017 Posted June 19, 2017 Hi, If you are using AutoCAD LT as shown in your profile so you have no luck to run any Lisp codes with it. Quote
mhmtlgrr Posted June 19, 2017 Author Posted June 19, 2017 Dear Tharwat, I joined this forum in 2012 and totally missed updating my profile in this period. Thanks for warning. I am currently using AutoCad 2015 (not LT) in the office. Quote
Tharwat Posted June 19, 2017 Posted June 19, 2017 No worries. Did you create the Attributed Block? Then what's the name of this Block? Do you have a list of these Room names? Is there any of these Mtexts formatted? Quote
mhmtlgrr Posted June 19, 2017 Author Posted June 19, 2017 Let me explain as per your questions: Did you create the Attributed Block? - Yes. Then what's the name of this Block? -The block is named as ROOMTAG Do you have a list of these Room names? -Room numbers are distributed over the DWG Is there any of these Mtexts formatted? -All room numbers are placed in Mtext objects I shared a file with this post. Please check out the file as working drawing. REPLACE-TEXT-W-BLOCK_TRANSFER-CONTENT.dwg Quote
Tharwat Posted June 19, 2017 Posted June 19, 2017 Give this a try. (defun c:Test (/ sel int ent att spc) ;; 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)))) (and (setq att (vla-insertblock spc (vlax-3d-point (cdr (assoc 10 (entget ent)))) "ROOMTAG" 1.0 1.0 1.0 0. ) ) (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) ) (entdel ent) ) ) ) ) (princ) )(vl-load-com) 3 Quote
mhmtlgrr Posted June 19, 2017 Author Posted June 19, 2017 Dear Tharwat, It works like a charm! I really appreciate! You can't know how much time you saved me! Hopefully I will have the chance to help you back soon. Thank you very much again. Regards, MA Quote
Tharwat Posted June 19, 2017 Posted June 19, 2017 Dear Tharwat, It works like a charm! I really appreciate! You can't know how much time you saved me! Hopefully I will have the chance to help you back soon. Thank you very much again. Regards, MA Great to hear. You are most welcome. Quote
nanjac86 Posted November 30, 2017 Posted November 30, 2017 I was looking for the same routine. Thank you very much. Also i need the block to be inserted in the source layer. Currently its placing in "0" layer. please update this lisp to place in source object layer. Thank you Nanjappa Quote
Tharwat Posted November 30, 2017 Posted November 30, 2017 I was looking for the same routine. Thank you very much. Also i need the block to be inserted in the source layer. Currently its placing in "0" layer. please update this lisp to place in source object layer. Thank you Nanjappa Good to hear that. Please add the following codes. (progn (vla-put-layer att (cdr (assoc 8 (entget ent)))) t) Before the following codes in the routine. (entdel ent) Like this: (progn (vla-put-layer att (cdr (assoc 8 (entget ent)))) t) (entdel ent) 1 Quote
Tharwat Posted December 1, 2017 Posted December 1, 2017 Thank you. works as needed. You are welcome. Quote
hassan2018 Posted January 27, 2018 Posted January 27, 2018 I hope u help me to replaace tendon id and number of strand in two circle as drawing attached with thank u NEW.dwg Quote
CAD_Noob Posted January 29, 2018 Posted January 29, 2018 Bookmarked. This is useful. Thanks Tharwat Quote
tonez Posted May 3, 2018 Posted May 3, 2018 Hi There, I loaded the lisp you created and opened my drawing which contains multiple mtext which are height levels (e.g. 3.580). I created an attributed text with the 'tag' roomtag and then created a block of the attributed text called 'roomtag' when i use the lisp command it inserts the block but the value on the attributed text within the block remains empty. Am i doing something incorrectly? Quote
great_isme Posted June 6, 2018 Posted June 6, 2018 Thank you thank you thank you!!! You saved my life! Can you keep the attribute block angle same as the text before conversion? Before replacing, the text may be having different angle. Thanks a lot. Quote
great_isme Posted June 6, 2018 Posted June 6, 2018 Hi, You have to change the attribute tag name or using the tag name in the lisp. Quote
great_isme Posted June 6, 2018 Posted June 6, 2018 Hi There, I loaded the lisp you created and opened my drawing which contains multiple mtext which are height levels (e.g. 3.580). I created an attributed text with the 'tag' roomtag and then created a block of the attributed text called 'roomtag' when i use the lisp command it inserts the block but the value on the attributed text within the block remains empty. Am i doing something incorrectly? Hi, You have to change the attribute tag name or using the tag name in the lisp. Quote
aridzv Posted January 30, 2022 Posted January 30, 2022 On 1/29/2018 at 4:37 AM, CAD_Noob said: Bookmarked. This is useful. Thanks Tharwat @Tharwat Wow! Definitely Bookmarked! 22 hours ago, Danish said: what is the command to use this lisp? if you didn't change anything so after you load it (use appload command) - type Test in the command line. make shure you have a block named ROOMTAG that contains a visible attribute named ROOMNO inserted in to your drawing first. something like the block I have attached. ROOMTAG.dwg Quote
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.