Replace Text With Block

Replace Text With Block

waynekay24
Explorer Explorer
5,776 Views
12 Replies
Message 1 of 13

Replace Text With Block

waynekay24
Explorer
Explorer

Hi All

 

I have a few thousand text entities that I need to replace with a block, at the same rotation and insertion as the text. 

 

I do not have Lisp experience, but use the routines quite a bit when I can find them. 

 

I do not need to extract any data yet - I just need the block to replace the text.

 

Does anyone have any routine that would do this?

 

Thanks.

0 Likes
Accepted solutions (4)
5,777 Views
12 Replies
Replies (12)
Message 2 of 13

braudpat
Mentor
Mentor
Accepted solution

Hello

 

I think the right solution (Lisp routine of course) is to insert a Block (named for exemple "Block_Text") without graphic

and with ONE Attribute (named for example "Attr_Text") which is in fact the TEXT !?

 

And the Block will inserted at each Text insertion point ...

 

THE HEALTH, Regards, Patrice

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 3 of 13

waynekay24
Explorer
Explorer

Hi - thank you for the reply.

The current need is only for the CAD block (graphic) without any attribute data necessary. Really a visual presentation at the moment where some manipulation of the block may be required later.

To shed some light, the text entities are Erf numbers. I want to substitute those for a block - which is a house drawing template. The rotation of the block would align with the text, as the text is aligned with the erf boundaries. The position of the block (house) would be at the centre of each erf - which is where the text has been positioned by the town planners.

Any help would be appreciated. 

0 Likes
Message 4 of 13

Moshe-A
Mentor
Mentor

@waynekay24  hi,

 

check this:

you can add more properties to (ssget) to filter out texts objects of no interest. 

 

; select all texts in specific layers

(setq ss (ssget '((0 . "text") (8 . "layer1,layer2,layer3")))))

 

; the same with specific height of 10

(setq ss (ssget '((0 . "text") (8 . "layer1,layer2,layer3") (40 . 10.0))))

 

enjoy

Moshe

 

(defun c:xxx (/ ss l elist p0 rot)
 (if (setq ss (ssget '((0 . "text"))))
  (repeat (setq l (sslength ss))
   (setq ename (ssname ss (setq l (1- l)))) 
   (setq elist (entget ename))
   (setq p0 (cdr (assoc '10 elist)))
   (setq rot (cdr (assoc '50 elist)))

   (command "._insert" "YourBlockName" p0 1 1 (angtos rot))
   (entdel ename) 
  ); repeat  

  (princ)  
 )
  

 

 

Message 5 of 13

3wood
Advisor
Advisor

delete

0 Likes
Message 6 of 13

3wood
Advisor
Advisor
Accepted solution

You can try ALTEXT.

You can use a simple formula in ALTEXT.

Steps as below:

Step 1. Original drawing, the justification of texts are set to "MC":

ALTEXT1.JPG

 

Step 2. Pick up "Use formula" in ALTEXT.

ALTEXT2.JPG

 

Step 3. Select a formula. (Save the code below as a *.lsp file)

ALTEXT3.JPG

 

Step 4. Result.

ALTEXT4.JPG

 

Save code below as a lsp file, such as "ALTEXT Formula 15.lsp".

;;; This is an example formula for ALTEXT.vlx
(defun ALTEXT_FORMULA (/ old-osnap)
  (setq old-osnap (getvar "OSMODE"))
  (setvar "OSMODE" 0)
  (vl-cmdf "._insert" "HOUSE" ;Change the block name "HOUSE" to suit your need.
	   (cdr (assoc 11 ALTEXT_BLK_ENT))
	   1.0
	   (atof (angtos (cdr (assoc 50 ALTEXT_BLK_ENT)) 1 3))
	   )
      (setvar "OSMODE" old-osnap)
  nil
  )
Message 7 of 13

vladimir_michl
Advisor
Advisor

With the Txt2Ref utility (freeware) you can replace the texts not only with a single block type but also with blocks of the same name as the original text. See:

https://www.cadforum.cz/cadforum_en/replace-texts-with-blocks-of-the-same-name-txt2ref-tip12760

 

Vladimir Michl, www.cadstudio.cz - www.cadforum.cz

 

Message 8 of 13

john.uhden
Mentor
Mentor
Accepted solution

It could be really easy if you don't mind anonymous blocks.  Each piece of text would be converted to an anonymous block that contained one (1) entity... the text.  If you want to use a standard named block, it would have to have an attribute to hold the text.

Either way can be done in a relatively short amount of time.  Not my time, but there are plenty of apparently financially independent wizards around here that like to work at the drive-thru window.

One neat thing about anonymous blocks is that if you explode them, they are self-purging.

Then again, I don't see the need for converting the text to blocks.  If the purpose is data extraction, AutoLisp can pull all the data from texts as well as blocks.  Of course it would be better if your texts were on specific layers so that the data could be organized.

John F. Uhden

Message 9 of 13

stepo.prochy
Participant
Participant

I have a similar issue. 

 

@braudpat can you please elaborate? I have very little experience with lisp functions.

0 Likes
Message 10 of 13

devitg
Advisor
Advisor

@stepo.prochy @waynekay24 

For better understanding, and maybe get further help, please upload such sample.dwg and CSV file 

0 Likes
Message 11 of 13

stepo.prochy
Participant
Participant
Accepted solution

Hello. 

I have since found a workaround. In my case, I didn't need the specific rotation angle, only the insertion point. I created a surface using text as a definition. Then exported acad points from the surface and converted them to COGO points which you then convert to a block definition matching the block that I needed. Not a very elegant solution but it helped me achieve what I needed.

Message 12 of 13

waynekay24
Explorer
Explorer

Many thanks - an interesting discussion. Solutions and an exciting endpoint regarding surfaces. Have utilised a similar process across CAD-friendly software; to manipulate surface data between programs. 

 

0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

"exported acad points from the surface and converted them to COGO points"

 

If you export the points as a csv then read those points in a simple lisp making blocks, if using Civ3D then can add a code to the csv file so have more than 1 house shape appear to give a varied look, also can add these points to a point group so easy turn off or on. 

0 Likes