Jump to content

Recommended Posts

Posted

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

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • neophoible

    11

  • colby82

    7

  • BIGAL

    1

  • JPlanera

    1

Top Posters In This Topic

Posted

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.

Posted

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.

Posted (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 by neophoible
added code tags to short code snippets
Posted

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

Posted

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.

Posted

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

Posted

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.

Posted (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 by neophoible
accidentally used the insertion 10 code instead of 11
Posted

Ia a check for S & s (0 . "TEXT") (1 . "s") required remember there are 52 characters in the alphabet.

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

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

Wow! worked amazing neophoible!! thanks so much, the down and dirty is perfect, lets me edit for other uses! thanks alot!!

 

colby

Posted

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!

Posted

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.

Posted (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 by neophoible
added code tags to short code snippets
Posted

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.

Posted

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

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

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