Jump to content

Convert block+text -----> block + attribute


bono05

Recommended Posts

Here you have a quick tool to change Text in Block Attribut

correctly better so...

(defun c:cha (/ txt blk)
 (if (= (cdr (assoc 0 (entget (setq txt (car (entsel "\nSelect text value ")))))) "TEXT")
   (progn
     (if (and (= (cdr (assoc 0 (entget (setq blk (car (entsel "\nSelect Chapelle block ")))))) "INSERT")
              (= (cdr (assoc 2 (entget blk))) (cdr (assoc 2 (tblsearch "BLOCK" "Chapelle"))))
              )
       (progn
         (entmod (subst (assoc 1 (entget txt)) (assoc 1 (entget (entnext blk))) (entget (entnext blk))))
          (entdel txt)
         )
       )
     )
   (princ "\nSelect a Text ")
   )
 (princ)
 )
       

 

Lots of mistakes and errors would take a place when the routine runs .

 

Read this post here and check your codes before posting .

Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

  • bono05

    24

  • pBe

    12

  • Lee Mac

    8

  • cadplayer

    7

Top Posters In This Topic

Posted Images

Cadplayer,

 

I've tried this lisp....but after selection of block my text is gone and there is no attribute at the chapelle block?

 

A response like this is what we're trying to avoid bono05, lay your cards on the table and let us see what we're dealing with.

Link to comment
Share on other sites

I've doing something wrong?

I don't understand everything....but actually the best way for me is your cst lisp.

 

But thanks to all to help me!!

Link to comment
Share on other sites

Try this:

(defun c:txt2blk ( / blk di1 di2 ent inc ins itm lst txt )
   (if
       (and
           (setq txt (ssget "_X" '((0 . "TEXT") (8 . "data txt") (410 . "Model"))))
           (setq blk (ssget "_X" '((0 . "INSERT") (2 . "Chapelle") (66 . 1) (410 . "Model"))))
       )
       (progn
           (repeat (setq inc (sslength txt))
               (setq ent (entget (ssname txt (setq inc (1- inc))))
                     lst (cons (list (cdr (assoc 10 ent)) (assoc 1 ent) (cdr (assoc -1 ent))) lst)
               )
           )
           (setq inc -1)
           (while (and lst (setq ent (ssname blk (setq inc (1+ inc)))))
               (setq ins (cdr (assoc 10 (entget ent)))
                     ent (entget (entnext ent))
                     di1 (distance (caar lst) ins)
                     itm (car lst)
               )
               (foreach x (cdr lst)
                   (if (< (setq di2 (distance (car x) ins)) di1)
                       (setq di1 di2 itm x)
                   )
               )
               (if (entmod (subst (cadr itm) (assoc 1 ent) ent))
                   (entupd (cdr (assoc -1 ent)))
               )
               (entdel (caddr itm))
               (setq lst (vl-remove itm lst))
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

Hi lee,

 

Are you test it with my plan?

If wel would please put this result in attachment?

 

I'm try it but doesn't nothing on my plan?!

 

thanks!

Link to comment
Share on other sites

I've doing something wrong?

I don't understand everything....but actually the best way for me is your cst lisp.

 

But thanks to all to help me!!

 

Not at all, we're just wanting to serve what you ordered. :) besides Lee appears to be on top of it.

 

@Lee

 

chapelle? I guess you were able to open the OPs' link then.

 

Good stuff LM :thumbsup:

Link to comment
Share on other sites

Great stuff Lee, much easier and takes no time to changeAll:shock:

 

Cheers!

 

I'm try it but doesn't nothing on my plan?!

 

I gave it a brief test on the drawing attached to this post and it appeared to perform as expected.

 

@Lee

 

chapelle? I guess you were able to open the OPs' link then.

 

Good stuff LM :thumbsup:

 

I based my code on the drawing attached to this post, but judging by the response from the OP, perhaps I viewed the wrong drawing :(

Thanks anyway Patrick :)

Link to comment
Share on other sites

It's a amazing result!!!! :D:D:D

But why doens't working with me?? :cry:

 

Need a special config into my autocad 2010?

 

The code should not be affected by any settings in AutoCAD, and should also work in all versions after AutoCAD 2000.

 

Can you attach your drawing in which the code is not working?

Link to comment
Share on other sites

Plan is attached on post#16 (thanks to cadplayer!)... and he send back the same plan convert with your lisp.

So no problem with the plan....but doens't working with me. :cry:

Link to comment
Share on other sites

Plan is attached on post#16 (thanks to cadplayer!)... and he send back the same plan convert with your lisp.

So no problem with the plan....but doens't working with me. :cry:

 

Given that you report that 'nothing happens', try this more verbose code:

(defun c:txt2blk ( / blk di1 di2 ent inc ins itm lst txt )
   (if (setq txt (ssget "_X" '((0 . "TEXT") (8 . "data txt") (410 . "Model"))))
       (if (setq blk (ssget "_X" '((0 . "INSERT") (2 . "Chapelle") (66 . 1) (410 . "Model"))))
           (progn
               (repeat (setq inc (sslength txt))
                   (setq ent (entget (ssname txt (setq inc (1- inc))))
                         lst (cons (list (cdr (assoc 10 ent)) (assoc 1 ent) (cdr (assoc -1 ent))) lst)
                   )
               )
               (setq inc -1)
               (while (and lst (setq ent (ssname blk (setq inc (1+ inc)))))
                   (setq ins (cdr (assoc 10 (entget ent)))
                         ent (entget (entnext ent))
                         di1 (distance (caar lst) ins)
                         itm (car lst)
                   )
                   (foreach x (cdr lst)
                       (if (< (setq di2 (distance (car x) ins)) di1)
                           (setq di1 di2 itm x)
                       )
                   )
                   (if (entmod (subst (cadr itm) (assoc 1 ent) ent))
                       (entupd (cdr (assoc -1 ent)))
                   )
                   (entdel (caddr itm))
                   (setq lst (vl-remove itm lst))
               )
           )
           (princ "\nNo 'Chapelle' attributed blocks found in Modelspace.")
       )
       (princ "\nNo Text objects found on 'data txt' layer in Modelspace.")
   )
   (princ)
)

Link to comment
Share on other sites

Ho my god!! I receive this report:

No 'Chapelle' attributed blocks found in Modelspace.

 

So i forget to create a attribute by the block!!!:oops:

 

By the way it's working now!

 

So once again you've always find a solution to help us!! MANY MANY MANY thanks!!!!!!!!!!!!!!!!!!!!!!!!!! :D

Link to comment
Share on other sites

I'm sorry Lee but is a serious problem:

 

You can see on the first drawing all text begin with 07A...

After the lisp there are text with 07A, 07B, 07C,...

And all the numbers are foul.

 

I think make a mix of the text that he find in the drawing?!

So he don't take the right text to the right box.

 

Any idea?

 

 

02.jpg

01.jpg

Link to comment
Share on other sites

Lee,

 

If you check the original plan on post#16...insertion point are always on the block and he don't take the nearest text.

I'm just comment the result of the test to try to go forward ...and certainly not to find any problems.

 

By the way it's not the first time that you help me with success.

 

If it's to complicated for Autocad, i'll anderstand.

Link to comment
Share on other sites

If you check the original plan on post#16...insertion point are always on the block and he don't take the nearest text.

 

The program measures the distance from the block insertion point to the text insertion point (lower-left corner), and uses the text with the minimum of these distances.

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