colby82 Posted August 16, 2012 Posted August 16, 2012 Hello, question for ya all out there.. so, in a drawing, i have several text strings, 's', that i would like to change to a known block... is this able to be done? there are over 3000 's' in the drawing, hoping to change them all to the same block. let me know if this can be done. thanks colby Quote
neophoible Posted August 16, 2012 Posted August 16, 2012 Hi, Colby, Yes, this type of replacement is certainly possible, though it will likely have to be via AutoLISP. Somebody has probably already done smth like this. The easiest thing to program would be for inserting the block at each insertion point of the text at a scale factor of 1, rotation 0, erasing the ‘s’ text afterward. Would that be sufficient? If not, tell us what else you would need. Quote
colby82 Posted August 16, 2012 Author Posted August 16, 2012 that is exactly what i need, and i have been scouring the net looking for a lisp routine that would work, or i could edit slgihtly, since i am not a lisp expert there is noway i could make one from scratch. Quote
neophoible Posted August 16, 2012 Posted August 16, 2012 (edited) OK. Just to make sure I know what I’m dealing with before I get started, please enter the LISP code below on the command line (you can simply copy and paste), select an ‘s’, then post the full result here. It will give the AutoLISP entity data list (a bunch of stuff in parentheses) of the selected item regardless of what it is. (setq E (car (entsel)) N E L (entget E)) Edited August 17, 2012 by neophoible added code tags to short code snippets Quote
colby82 Posted August 16, 2012 Author Posted August 16, 2012 here is what i got in return ((-1 . ) (0 . "TEXT") (330 . name: 7ffff7119f0>) (5 . "613E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "Pole") (100 . "AcDbText") (10 638134.0 5.87584e+006 0.0) (40 . 15.7653) (1 . "s") (50 . 4.74066) (41 . 1.0) (51 . 0.0) (7 . "Font10800") (71 . 0) (72 . 1) (11 638142.0 5.87584e+006 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 2)) thanks a lot!! colby Quote
neophoible Posted August 16, 2012 Posted August 16, 2012 OK. This looks good. It may take me a few minutes to sort this out. In the meantime, be sure to do a backup SAVE of your drawing just in case! This is always true, of course. And you will want to test it with just a few instances of ‘s’ in a test drawing first, just to make sure it works. So you can go ahead and set up a TEST dwg if you haven’t already. The 3000 shouldn’t take too long, but long enough. Quote
JPlanera Posted August 16, 2012 Posted August 16, 2012 Wouldnt QSELECT work? Once all the 's' are selected, they can be manipulated anyway you want.. Edit: i take that back... nevermind upon re reading the OP question... Quote
neophoible Posted August 16, 2012 Posted August 16, 2012 Well, I started on it and thought I just about had it, then manged to lock up my machine! If someone else doesn't jump in, I'll plan to tackle this tomorrow. One way or another, I believe help is on its way. Just hang in there. Quote
neophoible Posted August 16, 2012 Posted August 16, 2012 (edited) Well, I decided to keep going since I felt so close. It's kinda down n dirty but does the trick for the specific situation. I tested it with BORDER, so you will need to put your block's name in place of that. TBR was for Text-Block-Replace. (defun C:TBR ( / Text_set ; Set_index ; Insert_pt BlockName New_elist ; ) ; This assumes there is at least one TEXT object with value "s" AND that the ; BLOCk name is already defined in the drawing (prompt "\nSelecting text to replace...") ; If your text is other than "s", then replace the "s" with yours (setq Text_set (ssget "X" '( (-4 . "<AND") (0 . "TEXT") (1 . "s") (-4 . "AND>") ) ) ) (setq Set_index (sslength Text_set)) ; Need to put your block name in the quotes! (setq BlockName "BORDER") (command "Select" Text_set "") (prompt (strcat "\nReplacing " (rtos Set_index 2 0) " occurrence(s) of TEXT:\"s\"" " with BLOCK:\"" BlockName "\"..." ) ) (if (not (>= Set_index 1)) (exit)) (repeat Set_index (setq Set_index (1- Set_index)) (setq New_elist (entget (ssname Text_set Set_index))) (setq Insert_pt (cdr (assoc 11 New_elist))) (command "._INSERT" BlockName "S" "" "R" "" Insert_pt) ) (prompt "\nErasing the text...") (Command "._ERASE" Text_set "") (prompt "Done.") (princ) ) (C:TBR) Edited August 17, 2012 by neophoible accidentally used the insertion 10 code instead of 11 Quote
BIGAL Posted August 17, 2012 Posted August 17, 2012 Ia a check for S & s (0 . "TEXT") (1 . "s") required remember there are 52 characters in the alphabet. Quote
neophoible Posted August 17, 2012 Posted August 17, 2012 Ia a check for S & s (0 . "TEXT") (1 . "s") required remember there are 52 characters in the alphabet. Didn’t quite understand the initial accent there but... Yes, there are 52 a-b chars, but including “S” is actually an assumption. The “s” was specified and the sample specifically yielded “s”. Additionally assuming “S” might actually edit something not originally intended. In any case, “down n dirty” meant just that. If you have more text other than “s”, then edit, reload and rerun--simple as that. There are almost no bells or whistles here. Interestingly, AutoCAD maintains BLOCK names by case (at least in later releases) but ignores case in this case. OOPS--Actually, the way I wrote it, re-loading will re-run it automatically. Quote
dbroada Posted August 17, 2012 Posted August 17, 2012 Interestingly, AutoCAD maintains BLOCK names by case (at least in later releases) but ignores case in this case.AutoCAD has never taken notice of case in block names. You may be able to capitalise your blocks for easier reading but you cannot define different blocks with the same name but diiferent capitalisation. Quote
colby82 Posted August 17, 2012 Author Posted August 17, 2012 Wow! worked amazing neophoible!! thanks so much, the down and dirty is perfect, lets me edit for other uses! thanks alot!! colby Quote
colby82 Posted August 17, 2012 Author Posted August 17, 2012 so , i did work perfectly, but, the block comes in on the bottom of the 's' not on the insertition point of the text string. is there any way to get the blocks insert point to be inserted on the 's' insert point? thanks again! Quote
neophoible Posted August 17, 2012 Posted August 17, 2012 AutoCAD has never taken notice of case in block names. You may be able to capitalise your blocks for easier reading but you cannot define different blocks with the same name but diiferent capitalisation. Yes, that’s correct. AutoCAD does not differentiate, thus you don’t want to try to create a different BLOCK by varying capitalization. You may very well end up overwriting an existing BLOCK definition! But AutoCAD is nice enough to notice and maintain your capitalization preferences as you said. And you can easily change capitalization via REName. I don’t think this has always been possible. (I date back to v2.6--no, that’s not 2006--but my memory doesn’t!) Still, you don’t have to worry about any of this at the command line or in AutoLISP. Quote
neophoible Posted August 17, 2012 Posted August 17, 2012 (edited) so , i did work perfectly, but, the block comes in on the bottom of the 's' not on the insertition point of the text string. is there any way to get the blocks insert point to be inserted on the 's' insert point? thanks again! OOPS! Missed that. Change the 10 to 11 as follows and it should work correctly. That is, change this line (setq Insert_pt (cdr (assoc 10 New_elist))) to (setq Insert_pt (cdr (assoc 11 New_elist))) Hope it works now. I'll go edit the code post to reflect this. Edited August 17, 2012 by neophoible added code tags to short code snippets Quote
SLW210 Posted August 17, 2012 Posted August 17, 2012 Please read the CODE POSTING GUIDELINES and use code tags for your code. Quote
neophoible Posted August 17, 2012 Posted August 17, 2012 Please read the CODE POSTING GUIDELINES and use code tags for your code. Done! Sorry 'bout that. From here, it looked like overkill on the short snippets, but point well taken. Happy to comply. Quote
colby82 Posted August 17, 2012 Author Posted August 17, 2012 wow neophoible! amazing, thanks alot, such a great help! works like a charm. i had another 'routine' question, but i feel like i am taking advantage! lol Quote
neophoible Posted August 17, 2012 Posted August 17, 2012 wow neophoible! amazing, thanks alot, such a great help! works like a charm. i had another 'routine' question, but i feel like i am taking advantage! lol Glad it worked. I don’t know the limit to Qs here, but if it’s closely related to the task at hand, ask away in this thread. If I can’t get to it, perhaps someone else will pick it up. If it’s too involved for a freebie, then someone might offer to do it ‘for a small fee’. Quote
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.