andy_06 Posted October 13, 2016 Share Posted October 13, 2016 I am looking for a LISP routine that can display a list of MText contents. The reason is to help me when checking drawings with different pipe sizes. The list of different MTexts are: 63mm PE 90mm PE 125mm PE 180mm PE 250mm PE 315mm PE It would be great if I could run a routine that tells me how many times these appear in the drawing instead of using QSelect for each individual MText. Thanks Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 13, 2016 Share Posted October 13, 2016 Untested: (defun C:test ( / SSX txt ) (foreach x '(63 90 125 180 250 315) (if (setq SSX (ssget "_X" (list (cons 0 "MTEXT")(cons 1 (setq txt (strcat (itoa x) "mm PE")))(if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (princ (strcat "\nThere are " (itoa (sslength SSX)) " MTEXT objects with content \"" txt "\" on the current tab.")) (princ (strcat "\nThere arent any MTEXT objects with content \"" txt "\" on this tab!")) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 14, 2016 Share Posted October 14, 2016 Find "63mm PE" Replace "xx" Find All then undo. Will find all occurances in text, blocks, mtext etc but if you know where the 63mm PE is normally its probably ok a quick and dirty way. This would work in LT as well. Also set up a FILTER using *63mm* as search, mtext will appear as Text in the filter options but works. Quote Link to comment Share on other sites More sharing options...
andy_06 Posted October 14, 2016 Author Share Posted October 14, 2016 Untested: (defun C:test ( / SSX txt ) (foreach x '(63 90 125 180 250 315) (if (setq SSX (ssget "_X" (list (cons 0 "MTEXT")(cons 1 (setq txt (strcat (itoa x) "mm PE")))(if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (princ (strcat "\nThere are " (itoa (sslength SSX)) " MTEXT objects with content \"" txt "\" on the current tab.")) (princ (strcat "\nThere arent any MTEXT objects with content \"" txt "\" on this tab!")) ) ) (princ) ) That works fine, thanks! Now that I know this works I just have a couple of other variables. Sometimes the label won't include the 'mm' (i.e. 63 PE) and there could also be a lower case e (i.e. 63mm Pe/63 Pe). So if it is possible it would be great if the search wasn't case sensitive and could also look for labels without 'mm'. Thanks again. Quote Link to comment Share on other sites More sharing options...
andy_06 Posted October 14, 2016 Author Share Posted October 14, 2016 Find "63mm PE" Replace "xx" Find All then undo. Will find all occurances in text, blocks, mtext etc but if you know where the 63mm PE is normally its probably ok a quick and dirty way. This would work in LT as well. Also set up a FILTER using *63mm* as search, mtext will appear as Text in the filter options but works. Thanks! The FILTER option looks good so I will look into this. Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 14, 2016 Share Posted October 14, 2016 Maybe this could help: (defun C:test ( / StrLst SSX txt lst ) (defun StrLst ( l ) (vl-string-right-trim ")" (vl-string-left-trim "(" (vl-princ-to-string l)))) (setq lst (list (strcat "Found on \"" (getvar 'ctab) "\" tab:"))) (foreach size (mapcar 'itoa '(63 90 125 180 250 315)) (foreach type '("mm PE" "mm Pe" " PE" " Pe") (if (setq SSX (ssget "_X" (list (cons 0 "ATTRIB,*TEXT")(cons 1 (setq txt (strcat "*" size type "*")))(if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (setq lst (cons (strcat "\n" (itoa (sslength SSX)) " occurence(s) with content \"" txt "\"") lst)) ) ) ) (if lst (alert (StrLst (reverse lst)))) (princ) ) Quote Link to comment Share on other sites More sharing options...
andy_06 Posted October 17, 2016 Author Share Posted October 17, 2016 (edited) Maybe this could help: (defun C:test ( / StrLst SSX txt lst ) (defun StrLst ( l ) (vl-string-right-trim ")" (vl-string-left-trim "(" (vl-princ-to-string l)))) (setq lst (list (strcat "Found on \"" (getvar 'ctab) "\" tab:"))) (foreach size (mapcar 'itoa '(63 90 125 180 250 315)) (foreach type '("mm PE" "mm Pe" " PE" " Pe") (if (setq SSX (ssget "_X" (list (cons 0 "ATTRIB,*TEXT")(cons 1 (setq txt (strcat "*" size type "*")))(if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (setq lst (cons (strcat "\n" (itoa (sslength SSX)) " occurence(s) with content \"" txt "\"") lst)) ) ) ) (if lst (alert (StrLst (reverse lst)))) (princ) ) Hi again, This code was almost exactly what I was looking for but the only problem is it picks up every occurrence of the MTEXT types and these appear in other areas of the drawing (within paragraphs on notes on the drawing). The other code you did for me only picked up exact occurrences of each MTEXT. If it could be set to look at just MTEXT on the '0gas' layer then it would be great. (I have also just posted below regarding adding Polyline lengths which could be added to this instead if it is possible). Thanks again. Edited November 5, 2016 by andy_06 Quote Link to comment Share on other sites More sharing options...
andy_06 Posted November 5, 2016 Author Share Posted November 5, 2016 Untested: (defun C:test ( / SSX txt ) (foreach x '(63 90 125 180 250 315) (if (setq SSX (ssget "_X" (list (cons 0 "MTEXT")(cons 1 (setq txt (strcat (itoa x) "mm PE")))(if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))) (princ (strcat "\nThere are " (itoa (sslength SSX)) " MTEXT objects with content \"" txt "\" on the current tab.")) (princ (strcat "\nThere arent any MTEXT objects with content \"" txt "\" on this tab!")) ) ) (princ) ) Hi, I have been using this code for the last couple of weeks and it works great. Since I have been using it I thought of something else that would be a real help if it could be added. Each MTEXT is offset from a Polyline (each MTEXT labels the size of each section of pipe). I was wondering if it is possible to list the total length of Polyline for each type of MTEXT by looking at the nearest Polyline to each MTEXT on the '0gas' layer. Therefore when you run the command it would say something like: (There are 48 MTEXT objects with content "63mm PE" on the current tab and the length is 110.5m). (There are 20 MTEXT objects with content "90mm PE" on the current tab and the length is 90.2m) This is way too advanced for me but could be a good challenge for someone! 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.