Jump to content

Replacing text with a block?


GWelch

Recommended Posts

Greetings all,

 

I have inherited a drawing where certain objects are represented by text. Sounds odd, but the text is the "Dingbats" sort of font, where individual letters represent symbols. So, the letter "T" represents a tree (plan view), but I would like to convert these letters to editable blocks of trees, which seems infinitely more preferable to me. Is this possible - can a "find and replace" function change text to a defined block? There are hundreds of these, so you can imagine my frustration.

 

ACAD 2004 drawing, but I have 2007 and Land Desktop if those are necessary.

 

Thanks in advance,

 

GWelch

Link to comment
Share on other sites

  • 2 weeks later...

Post this in the lisp/customization forum and a few super lispers will take care of you with an elegant routine.

 

The following Q&D lisp might get you started (untested);

 

(defun c:T2Block ()
  (setq TreeStylename "Dingbats");;edit this to match actual style
  (setq TreeSymSet (ssget "x" '((0 . "TEXT")(1 . "T"))))
  (setq NumSet (sslength TreeSymSet))
  (setq Count 0)
  (repeat NumSet
      (setq Ename (ssname TreeSymSet Count))
      (setq InsPt (cdr (assoc 10 (entget Ename))))
      (entdel Ename)
      (command "insert" "YourBlockname" InsPt 1 1 0);;edit block name
      (setq Count (1+ Count))
 )
 (princ)
)

Link to comment
Share on other sites

  • 5 years later...

I'm a newbie onto writing LISP. I have pretty similar problem on how to replace a text with a dynamic block?

 

This is what I want to do: I want to replace all text or mtext in a specific layer which are basically the House Number layer of my drawing and all of these text objects in autocad are (alphanumeric). The existing value should be transferred to specific block tag which is VISIBLE attribute into my block and I aim to put them into a block tag with "HOUSE_NO". After that, all of the replaced text will be deleted since the new values are already into my new blocks.

 

Imagine working on a map with at least 5,000 house numbers to replace them into a blocks.

Link to comment
Share on other sites

I'm a newbie onto writing LISP. I have pretty similar problem on how to replace a text with a dynamic block?

 

This is what I want to do: I want to replace all text or mtext in a specific layer which are basically the House Number layer of my drawing and all of these text objects in autocad are (alphanumeric). The existing value should be transferred to specific block tag which is VISIBLE attribute into my block and I aim to put them into a block tag with "HOUSE_NO". After that, all of the replaced text will be deleted since the new values are already into my new blocks.

 

Imagine working on a map with at least 5,000 house numbers to replace them into a blocks.

 

Welcome to CADTutor. :)

This sounds like an onerous task, but I would guess that if you visited Lee Mac's excellent site

there may well be some tools there to help you.

 

http://www.lee-mac.com/programs.html#general

 

Not sure which to suggest, but give them a look.

Thanks Lee! :beer:

Link to comment
Share on other sites

This is a simple, quick revision of the routine to achieve what you want:

(defun c:T2B (/ Ename InsPt Count TreeSymSet NumSet TextValue Elist)
;   (setq TreeStylename "Dingbats");;edit this to match actual style
  (setq TreeSymSet (ssget "X" '((0 . "TEXT")(8 . "HouseNumber"))))
  (setq NumSet (sslength TreeSymSet)) ; Edit LayName
;   (princ NumSet)
  (setq Count 0)
  (repeat NumSet
      (setq Ename (ssname TreeSymSet Count)
            Elist (entget Ename)
            InsPt (cdr (assoc 11 Elist))
            TextValue (cdr (assoc 1 Elist))
      )
;       (princ Count)
;       (entdel Ename)
      (command "_.INSERT" "APD" InsPt 1 0 TextValue)
      (setq Count (1+ Count));              ;edit block name
 )
 (command "ERASE" TreeSymSet "")
 (princ)
)

You'll need to either name your Block and Layer the same or change them in the program. It assumes the TEXT has the proper justification to match. A couple of lines have been commented out, as they do not apply for your situation. I also localized the variables. If you have problems with incorrect insertion points, try turning OSNAP OFF before running.

Edited by neophoible
commented out princs--can use if problem changed names to match below
Link to comment
Share on other sites

Thanks to both of you Dadgad and Neo,:)

 

I have edited and try the code above, but it doesn't replace all the text into block in my drawing.

 

You might need this info;

my Text layer is "HouseNumber"

my blockname is "APD" it is also in "HouseNumber" Layer

Text justify: "Middle Center".

 

Thanks!

Link to comment
Share on other sites

You're welcome, dennis03. Hope this now works. I edited the code above to match the layer name and block name you listed. Middle Center should work great for this.

Link to comment
Share on other sites

  • 2 weeks later...

I have tried to run the edited code above, but it doesn't replace the text into Block nor insert a block.

 

I'm trying to understand the code and I have a few questions. What does setq TreeStylename "Dingbats" mean in the code?

Also the (command "_.INSERT" "APD" InsPt 1 0 TextValue) seems, not doing the job done. So I try to experiment and replace it from the original code. And it does insert blocks in my drawing, I say most of it 60%, but not all text. The justification are all the same, that puzzled me why it doesn't replace them all.

 

In case you have overlooked; I also want to moved or retain the existing TEXT value into my BLOCKS with defined Tag attributes "HOUSE_NO".

 

Thanks Neo for the reply.

Link to comment
Share on other sites

I have tried to run the edited code above, but it doesn't replace the text into Block nor insert a block.

I'm trying to understand the code and I have a few questions. What does

(setq TreeStylename "Dingbats")

mean in the code?

I added code tags. This line is actually commented out using a semicolon. It was not active and is incomplete, but must have been intended to help set the Text Style long ago.

 

Also the
(command "_.INSERT" "APD" InsPt 1 0 TextValue)

seems, not doing the job done. So I try to experiment and replace it from the original code. And it does insert blocks in my drawing, I say most of it 60%, but not all text. The justification are all the same, that puzzled me why it doesn't replace them all.

In case you have overlooked; I also want to moved or retain the existing TEXT value into my BLOCKS with defined Tag attributes "HOUSE_NO".

Thanks Neo for the reply.

You're welcome for the reply. Sorry it's not working as needed. I tell you what, post a sample DWG with about 10 or 12 of these blocks, including some that did not work. Also, show what you want it to look like when finished. Then I or someone else can take a closer look and try to solve your problem. Again, that's two parts to your DWG: Part 1 is what you start with, and Part 2 is what you want to end with.
Link to comment
Share on other sites

  • 2 years later...
What happened to the "convert text to block" code?

 

Looks like someone forgot to come back like they said they would.

Link to comment
Share on other sites

Hi ReMark,

I need exactly the same lisp routine requested initially in this thread, i.e. convert a text or Mtext to a pre-defined block with two attributes where one of them includes the original text. The block should be in the same layer as the original text and this lisp should be able to convert in one shot the entire selected texts in a given drawing.

 

thanks,

 

Nasr

Link to comment
Share on other sites

Would you like it to order a pizza too?

 

Your description of what you need the lisp routine to do is a little bit more involved than that stated in the first post of this thread which by the way I did find a solution to. Problem is, it is not nearly the solution you require. Sorry.

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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