Jump to content
ashfaq

Finding text based on style and replacing it with a block at the same position

Recommended Posts

ashfaq

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 by ashfaq

Share this post


Link to post
Share on other sites
Tharwat

Welcome to the forum .:)

 

You can not use Lisp with Autocad LT .

Share this post


Link to post
Share on other sites
ashfaq

Well, I must say, You seem to be a keen observer, o:). I am actually using Autocad 2011. I didn't think my profile would make a difference to the replies :).

Share this post


Link to post
Share on other sites
Tharwat

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 ) ?

Share this post


Link to post
Share on other sites
ashfaq

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

Share this post


Link to post
Share on other sites
Tharwat

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 ) ?

Share this post


Link to post
Share on other sites
ashfaq
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:

 

image.png

 

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.

Share this post


Link to post
Share on other sites
Tharwat

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 by Tharwat
New codes added according to OP needs

Share this post


Link to post
Share on other sites
ashfaq

Thank you Tharwat , the the draft code works!!! :D :D.

Share this post


Link to post
Share on other sites
Tharwat
thank you Tharwat , the the draft code works!!! :D :D

 

Very happy to hear that . :D

 

Good luck .

Share this post


Link to post
Share on other sites
ashfaq

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??

Share this post


Link to post
Share on other sites
Tharwat
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 . 8)

Share this post


Link to post
Share on other sites
ashfaq

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)
)

Share this post


Link to post
Share on other sites
Tharwat
Thanks Tharwat. It works and caters to what i wanted :). Great Job!!!

 

You're welcome . :D

 

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. ;)

Share this post


Link to post
Share on other sites
ashfaq

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.

 

view.php?pic=i5b029&s=5

 

thank you in advance!!

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...