ashfaq Posted January 23, 2013 Posted January 23, 2013 (edited) Hello everyone!! I am a rookie in autolisp. I need help in figuring this out.. I wish to find Mtext "J" of a particular style (say ROMANS) in the drawing and retrieve its position (x,y coordinates). I am trying to replace all the occurrences of the text with a block (say "star") at their respective locations. I found lisp programs to find text, but i cant seem to figure out how to use its attributes to proceed further. eagerly awaiting responses... Edited January 23, 2013 by ashfaq Quote
Tharwat Posted January 23, 2013 Posted January 23, 2013 Welcome to the forum . You can not use Lisp with Autocad LT . Quote
ashfaq Posted January 23, 2013 Author Posted January 23, 2013 Well, I must say, You seem to be a keen observer, . I am actually using Autocad 2011. I didn't think my profile would make a difference to the replies . Quote
Tharwat Posted January 23, 2013 Posted January 23, 2013 Okay , What do you mean by Mtext "J" ? And you would replace all the texts and Mtexts objects with respect to the text styles with a normal block ( not attributed or dynamic block ) ? Quote
ashfaq Posted January 23, 2013 Author Posted January 23, 2013 I am trying to transfer drawings from PDMS software into autocad. The angle symbol in PDMS is being represented as J in autocad. and I found out that the font style that is being used is called "FOP11901". This is in actual a PDMS symbol library that is not compatible with autocad. so i thought of developing an autolisp file which will : 1. find all occurrences of mtext "J" having fontstyle "FOP11901" 2. retrieve its position coordinates. 3. Delete the text. 4. insert block "starang" (available in the drawing) at the same position. Hope this clears out what i need Quote
Tharwat Posted January 23, 2013 Posted January 23, 2013 1. find all occurrences of mtext "J" having fontstyle "FOP11901" So you need to select mtexts according to their font style and not to their Text Styles as you have entitled the thread ? I am still not sure about what you mean by mtext "j" ? ( maybe this is the only string that you need to replace with a block if its font style according the above said one ) ? Quote
ashfaq Posted January 23, 2013 Author Posted January 23, 2013 So you need to select mtexts according to their font style and not to their Text Styles as you have entitled the thread ? Ive attached a screen shot of the same: I believe its the Text Style and not font style. I am still not sure about what you mean by mtext "j" ? ( maybe this is the only string that you need to replace with a block if its font style according the above said one ) ? What I mean is that I have a multi-line text that has only one string entry and that is the alphabet 'J'. this multi-line text needs to be replaced by a block. Quote
Tharwat Posted January 23, 2013 Posted January 23, 2013 (edited) okay , Try this draft at the moment and tell me back if it suits your needs or not . (defun c:Test (/ b ss) (if (and (/= (setq b (getstring t "\n Enter name of Block :")) "") (if (not (tblsearch "BLOCK" B)) (progn (princ "\n name of Block is not existed ") nil ) t ) (progn (prompt " Select texts ") (setq ss (ssget "_:L" '((0 . "*TEXT") (1 . "j") (7 . "FOP11901"))) )) ) ((lambda (i / sn e) (while (setq sn (ssname ss (setq i (1+ i)))) (if (entmakex (list '(0 . "INSERT") (cons 2 b) (assoc 10 (entget sn)) (assoc 50 (entget sn)) '(41 . 1.) '(42 . 1.) '(43 . 1.) ) ) (entdel sn) ) ) ) -1 ) ) (princ) ) Edited January 23, 2013 by Tharwat New codes added according to OP needs Quote
ashfaq Posted January 23, 2013 Author Posted January 23, 2013 Thank you Tharwat , the the draft code works!!! :D. Quote
Tharwat Posted January 23, 2013 Posted January 23, 2013 thank you Tharwat , the the draft code works!!! :D Very happy to hear that . Good luck . Quote
ashfaq Posted January 23, 2013 Author Posted January 23, 2013 Now i again need your help with an improvement: if the Text is placed at an angle, (say 45 Degree), I want the block to be placed at the same angle as well. how can that be done?? Quote
Tharwat Posted January 23, 2013 Posted January 23, 2013 Now i again need your help with an improvement:if the Text is placed at an angle, (say 45 Degree), I want the block to be placed at the same angle as well. how can that be done?? The routine is updated without testing it , please try it and hope it goes well as needed . Quote
ashfaq Posted January 23, 2013 Author Posted January 23, 2013 Thanks Tharwat. It works and caters to what i wanted . Great Job!!! PS: I removed an extra bracket and removed the second step of selecting the texts in your revised code. (defun c:Test (/ b ss) (if (and (/= (setq b (getstring t "\n Enter name of Block :")) "") (if (not (tblsearch "BLOCK" b)) (progn (princ "\n name of Block is not existed ") nil ) t ) (setq ss (ssget "_X" '((0 . "*TEXT") (1 . "j") (7 . "FOP11901")))) ) ((lambda (i / sn e) (while (setq sn (ssname ss (setq i (1+ i)))) (if (entmakex (list '(0 . "INSERT") (cons 2 b) (assoc 10 (entget sn)) (assoc 50 (entget sn)) '(41 . 1.) '(42 . 1.) '(43 . 1.) ) ) (entdel sn) ) ) ) -1 ) ) (princ) ) Quote
Tharwat Posted January 23, 2013 Posted January 23, 2013 Thanks Tharwat. It works and caters to what i wanted . Great Job!!! You're welcome . PS: I removed an extra bracket and removed the second step of selecting the texts in your revised code. Be careful to have all your layers unlocked to avoid any error may occur due to the changes you did to the code. Quote
ashfaq Posted June 4, 2013 Author Posted June 4, 2013 Hello, I require modification in the previous code. The earlier code was to replace all text elements with "J" as entry and "FOP11901" as style with a block. The block is placed at the same location and the orientation as the text. Now I want the code to do the following: 1. find all text elements having their first character as "h" followed by "ISA" or a number 2. Insert a Block at the same location and orientation as the text. 3. Replace the character "h" with " "(Blank). Ive attached an image of the original and revised text for clarity, do let me know if you need more information. thank you in advance!! 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.