Tharwat Posted November 6, 2012 Share Posted November 6, 2012 Here you have a quick tool to change Text in Block Attributcorrectly 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 . Quote Link to comment Share on other sites More sharing options...
cadplayer Posted November 6, 2012 Share Posted November 6, 2012 Don´t run the code or what are you meaning with lots of mistakeso:) Quote Link to comment Share on other sites More sharing options...
pBe Posted November 6, 2012 Share Posted November 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
bono05 Posted November 6, 2012 Author Share Posted November 6, 2012 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!! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2012 Share Posted November 6, 2012 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) ) Quote Link to comment Share on other sites More sharing options...
cadplayer Posted November 6, 2012 Share Posted November 6, 2012 Great stuff Lee, much easier and takes no time to changeAll:shock: Quote Link to comment Share on other sites More sharing options...
bono05 Posted November 6, 2012 Author Share Posted November 6, 2012 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! Quote Link to comment Share on other sites More sharing options...
pBe Posted November 6, 2012 Share Posted November 6, 2012 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2012 Share Posted November 6, 2012 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 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 Quote Link to comment Share on other sites More sharing options...
cadplayer Posted November 6, 2012 Share Posted November 6, 2012 No problem! But more confusing ??? DATA +06_example.dwg Quote Link to comment Share on other sites More sharing options...
bono05 Posted November 6, 2012 Author Share Posted November 6, 2012 It's a amazing result!!!! :D:D But why doens't working with me?? Need a special config into my autocad 2010? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2012 Share Posted November 6, 2012 It's a amazing result!!!! :D:DBut why doens't working with me?? 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? Quote Link to comment Share on other sites More sharing options...
bono05 Posted November 6, 2012 Author Share Posted November 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2012 Share Posted November 6, 2012 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. 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) ) Quote Link to comment Share on other sites More sharing options...
bono05 Posted November 6, 2012 Author Share Posted November 6, 2012 Ho my god!! I receive this report: No 'Chapelle' attributed blocks found in Modelspace. So i forget to create a attribute by the block!!! By the way it's working now! So once again you've always find a solution to help us!! MANY MANY MANY thanks!!!!!!!!!!!!!!!!!!!!!!!!!! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2012 Share Posted November 6, 2012 Thank you for your appreciation, I'm glad the program is working for you now. Quote Link to comment Share on other sites More sharing options...
bono05 Posted November 6, 2012 Author Share Posted November 6, 2012 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? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2012 Share Posted November 6, 2012 The program simply uses the nearest text object to the insertion point of the block, that is all. Quote Link to comment Share on other sites More sharing options...
bono05 Posted November 6, 2012 Author Share Posted November 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2012 Share Posted November 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.