Author Topic: Replace text with existing block with attribute  (Read 4178 times)

0 Members and 1 Guest are viewing this topic.

luisternou

  • Newt
  • Posts: 32
Replace text with existing block with attribute
« on: March 22, 2017, 03:45:55 PM »
Hello everyone!
I have several bridge-numbers in my drawing(2000+). I want to replace the text numbers with an existing block with an attribute in it who's value becomes de replaced text.
Is there someone who can help me to write a lisp?
Thanks in advance,
Kind regards, Luis

ChrisCarlson

  • Guest
Re: Replace text with existing block with attribute
« Reply #1 on: March 22, 2017, 03:59:36 PM »
This isn't too bad if you're willing to learn. You need to break it down into steps first. This is how I would break it down

1) Select text entities and filter on entities with the string you want to replace
    1a) Create a txtstr variable
    1b) Create a variable for insertion point based on the text entity
2) Insert the block
4) Input the string into the attribute of the block entity
5) Delete the text entity

luisternou

  • Newt
  • Posts: 32
Re: Replace text with existing block with attribute
« Reply #2 on: March 22, 2017, 05:07:19 PM »
  :idea:  eeeeh oké, thanks, that looks very simple! But to be honest. I tried in the past to write lisp but I don't have the talent and/or brains to get it right.  :idiot2: I hope you or someone else can help me. Anyhow, thanks for replying!

ChrisCarlson

  • Guest
Re: Replace text with existing block with attribute
« Reply #3 on: March 23, 2017, 08:13:45 AM »
Research and examine the following;

Code - Auto/Visual Lisp: [Select]

luisternou

  • Newt
  • Posts: 32
Re: Replace text with existing block with attribute
« Reply #4 on: March 23, 2017, 01:13:59 PM »
Sorry Master_Shake but I am in a hurry! So what I did is: I did the command Tcircle and selected all the text. Then with an old lisp I have I converted all the 2014 circles to a circle block. Then in Express-tools I replaced all the circle blocks with the one I want with the attribute. With another lisp I copy the text to the attribute value one by one...  :embarrassed2:

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Replace text with existing block with attribute
« Reply #5 on: March 23, 2017, 01:32:33 PM »
If you still have text near the blocks, THIS could be modified to copy text value into the attribute.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

luisternou

  • Newt
  • Posts: 32
Re: Replace text with existing block with attribute
« Reply #6 on: March 23, 2017, 01:59:27 PM »
Thanks ronjonp! That looks promising. I will look in to that first thing in the morning!

luisternou

  • Newt
  • Posts: 32
Re: Replace text with existing block with attribute
« Reply #7 on: March 24, 2017, 07:27:23 AM »
Hi Ronjonp! I tried the lisp but it not working in my drawing. I attached a small part of it. Maybe you can take a look?
Thanks in advance!

Kind regards,
Luis

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Replace text with existing block with attribute
« Reply #8 on: March 24, 2017, 09:03:09 AM »
Hi Ronjonp! I tried the lisp but it not working in my drawing. I attached a small part of it. Maybe you can take a look?
Thanks in advance!

Kind regards,
Luis
Here you go:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ blocks el fuzz p text txt x)
  2.   (setq fuzz 0.001)
  3.   (if (and (setq text (ssget "_x" '((0 . "text") (8 . "!Kunstwerken_Watervaknummer"))))
  4.            (setq blocks (ssget "_x" '((0 . "insert") (66 . 1) (2 . "Symbool_Kunstwerk"))))
  5.            (setq blocks (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex blocks))))
  6.            (setq
  7.              text (mapcar
  8.                     '(lambda (x) (setq el (entget x)) (list (cdr (assoc 11 el)) (cdr (assoc 1 el)) x))
  9.                     (mapcar 'cadr (ssnamex text))
  10.                   )
  11.            )
  12.       )
  13.     (foreach block blocks
  14.       (setq p (vlax-get block 'insertionpoint))
  15.       (if (setq txt (vl-some '(lambda (x)
  16.                                 (if (equal p (car x) fuzz)
  17.                                   x
  18.                                 )
  19.                               )
  20.                              text
  21.                     )
  22.           )
  23.         (progn (mapcar '(lambda (x) (vla-put-textstring x (cadr txt)))
  24.                        (vlax-invoke block 'getattributes)
  25.                )
  26.                (entdel (last txt))
  27.         )
  28.       )
  29.     )
  30.   )
  31.   (princ)
  32. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

luisternou

  • Newt
  • Posts: 32
Re: Replace text with existing block with attribute
« Reply #9 on: March 24, 2017, 10:22:49 AM »
Hello again Ronjonp!
For you it is maybe nothing but for me this is amazing  :yay!: :yay!: :yay!: Thank you very much!! :-D

In the meantime I was also examining this routine. It did something but not as smooth and fast as your routine. Maybe it is interesting for you to study.
http://cadtips.cadalyst.com/attributed-blocks/automatically-convert-text-or-mtext-attributes (credits to Ricky Medley).

Anyway, thangs again! I am glad I get my deadline in time!  :-D

luisternou

  • Newt
  • Posts: 32
Re: Replace text with existing block with attribute
« Reply #10 on: March 24, 2017, 10:23:25 AM »
 :yay!: :yay!: :yay!:

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Replace text with existing block with attribute
« Reply #11 on: March 24, 2017, 10:31:35 AM »
Hello again Ronjonp!
For you it is maybe nothing but for me this is amazing  :yay!: :yay!: :yay!: Thank you very much!! ;D

In the meantime I was also examining this routine. It did something but not as smooth and fast as your routine. Maybe it is interesting for you to study.
http://cadtips.cadalyst.com/attributed-blocks/automatically-convert-text-or-mtext-attributes (credits to Ricky Medley).

Anyway, thangs again! I am glad I get my deadline in time!  ;D
Glad to help :) .. now you can go home early today!  ;)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

luisternou

  • Newt
  • Posts: 32
Re: Replace text with existing block with attribute
« Reply #12 on: March 24, 2017, 11:31:04 AM »
 :-D Exacly, I go now, have a nice weekend Ronjonp!

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Replace text with existing block with attribute
« Reply #13 on: March 24, 2017, 11:40:34 AM »
;D Exacly, I go now, have a nice weekend Ronjonp!
You too  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

symoin

  • Mosquito
  • Posts: 5
Re: Replace text with existing block with attribute
« Reply #14 on: January 03, 2024, 11:56:06 AM »
Dear RonJonp,

How to modfiy or is there any way for converting the Normal block without attribute to a block with attribute and attach the nearest text on the same layer as its value.
dOESN'T MATTER IF THE BLOCK IS REPLACE WITH A NEW BLOCK.