bono05 Posted April 28, 2015 Share Posted April 28, 2015 Hello, I have a block "Detector" with already an attribute "DI" + mtext (wich is adress of detector) ---- See dwg sample in attachment I would like to convert that mtext to a attribute in the block? Idea is that i can manually select 1 block and his mtext...to convert it. I hope there is a solution for this. Thanks! block and mtext.dwg Quote Link to comment Share on other sites More sharing options...
ttray33y Posted April 28, 2015 Share Posted April 28, 2015 I would suggest, modify your block with specific attribute tag > attsync > redefine/ re-insert the block to your drawings > attsync > update you attribute value. Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 Manually one by one...a lots of work isn't? This is a sample with ony 3 blocks, but the fact is that i have more than 100 by plan. Quote Link to comment Share on other sites More sharing options...
ttray33y Posted April 28, 2015 Share Posted April 28, 2015 Manually one by one...a lots of work isn't?This is a sample with ony 3 blocks, but the fact is that i have more than 100 by plan. yes i understand, however your block share the same name, and adding an attrbiute in there will make every block the same as the other when syncing the attribute inserted. Or we can wait Lee, Thar & Pbe advice. Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 I'm not sure to understand!? How can i make from my text a attribute? Quote Link to comment Share on other sites More sharing options...
ttray33y Posted April 28, 2015 Share Posted April 28, 2015 I'm not sure to understand!? How can i make from my text a attribute? I have a lisp that converts text/mtext to attribute + insert them to an existing block. i already test it with your drawing. Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 I have a lisp that converts text/mtext to attribute + insert them to an existing block. i already test it with your drawing. Great...but can you post it here please? Quote Link to comment Share on other sites More sharing options...
ttray33y Posted April 28, 2015 Share Posted April 28, 2015 Great...but can you post it here please? Detecteur incendie mc.dwg Alternative workaround. Updated your block see (Detecteur incendie mc.dwg), test file (block and mtext.dwg), test LISP (txt2att.lsp). open the test file attached, appload txt2att.lsp and invoke test1. hint: it will convert the nearest text. txt2att.lsp block and mtext.dwg Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 Waow!!!! congratulations!!! Now because i have 3 of 4 differents blocks into my drawing can i just add an attribute COOR to another blocks. Or it's working only with block " Detecteur incendie mc". ANd just to understand ...why tag name "COOR"? I don't see any link into the lisp. OR can i add some blocknames here: (setq blk (ssget "_X" '((0 . "INSERT") (2 . "Detecteur incendie mc") (66 . 1) (410 . "Model")))) Quote Link to comment Share on other sites More sharing options...
ttray33y Posted April 28, 2015 Share Posted April 28, 2015 Waow!!!! congratulations!!! Now because i have 3 of 4 differents blocks into my drawing can i just add an attribute COOR to another blocks. Or it's working only with block " Detecteur incendie mc". ANd just to understand ...why tag name "COOR"? I don't see any link into the lisp. OR can i add some blocknames here: (setq blk (ssget "_X" '((0 . "INSERT") (2 . "Detecteur incendie mc") (66 . 1) (410 . "Model")))) exactly, it will only convert text nearest to the block Detecteur incendie mc. and will insert the text value to the first attribute it detect within your block which is COOR, of course you can add any attribute definition in your other block as long as that Attdef is at the top. Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 It's possible to put more than one block into the script, not only "Detecteur incendie mc"?? So i can make all the plan at once. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 28, 2015 Share Posted April 28, 2015 Add a new attribute object to every attributed block that you want to add the nearest mtext string to it then it would take less codes to write a routine to replace the nearest mtext string to the new added attribute object as text string . NOTE: if you want to add the mtext as a multiple lined text string , so that should be considered while adding the new attribute object in its mode . Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 Add a new attribute object to every attributed block that you want to add the nearest mtext string to it It's done then it would take less codes to write a routine to replace the nearest mtext string to the new added attribute object as text string Need to change something in this code? NOTE: if you want to add the mtext as a multiple lined text string , so that should be considered while adding the new attribute object in its mode . One line is ok for me. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 28, 2015 Share Posted April 28, 2015 Since that it is done , what is the new tag name that you added to each block ? Upload a real drawing to avoid guessing and modifying the codes for several times . Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 So i add a new attribute on each block (COOR) Those are the different blockname: Detecteur incendie mc Detecteur incendie mc sol (this one have now 3 attributes) efp02 EL001 EL003 Sirene incendie P_R1.dwg Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 28, 2015 Share Posted April 28, 2015 Would you like to delete the Mtext object that would take a place of the attribute ? Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 Yes please. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 28, 2015 Share Posted April 28, 2015 All right , this should do the trick in one shot (defun c:Test (/ il ml s i sn en v d lst) ;;------------------------------------;; ;; Tharwat 28.4.2015 ;; ;;------------------------------------;; (princ "\nSelect Attributed Blocks with Mtexts:") (if (setq s (ssget "_:L" '((-4 . "<OR") (-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>") (0 . "MTEXT") (-4 . "OR>") ) ) ) (progn (repeat (setq i (sslength s)) (setq sn (ssname s (setq i (1- i))) en (entget sn) ) (if (eq (cdr (assoc 0 en)) "INSERT") (setq il (cons (list (cdr (assoc 10 en)) sn) il)) (setq ml (cons (list (cdr (assoc 10 en)) sn) ml)) ) ) (mapcar '(lambda (u) (mapcar '(lambda (p) (setq lst (cons (list (distance (car u) (car p)) (cadr p)) lst ) ) ) ml ) (setq v (vl-sort lst '(lambda (j k) (< (car j) (car k))))) (mapcar '(lambda (o) (if (eq (strcase (vla-get-tagstring o)) "COOR") (progn (vla-put-textstring o (vl-string-subst "" "\\P" (cdr (assoc 1 (entget (cadar v)))) ) ) (setq d (cons (cadar v) d)) ) ) ) (vlax-invoke (vlax-ename->vla-object (cadr u)) 'getattributes ) ) (setq v nil lst nil ) ) il ) (mapcar 'entdel d) ) ) (princ) )(vl-load-com) Quote Link to comment Share on other sites More sharing options...
bono05 Posted April 28, 2015 Author Share Posted April 28, 2015 Exactly!!! BIG thanks to you and ttray33y. If i want to use this code for the future on another plan it's possible? Or the blockname present in this plan are important? And attribute name need always to be "COOR" Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 28, 2015 Share Posted April 28, 2015 Exactly!!! BIG thanks to you and ttray33y. Great , If i want to use this code for the future on another plan it's possible? Or the blockname present in this plan are important? And attribute name need always to be "COOR" You can use it with any attributed block name and the most important thing is that the tag name that should be included in the selected blocks. Good luck . Tharwat 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.