Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

text edit inside block

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
cadman777
4514 Views, 14 Replies

text edit inside block

Does someone have an autolisp routine that edits all simple text and mtext inside a block without editing the block?

I want to be able to select the block, or window around a block to select all text, and then edit the text width factor.

The reason I need this is b/c the newer versions of autocad revert all text width factor of older autocad text entities to 1, but they were .75 in all my old drg title blocks (about 3 gigs of them).

thanks ... Chris

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
14 REPLIES 14
Message 2 of 15
_Tharwat
in reply to: cadman777

Check this out buddy . Smiley Wink

 

Select the text which is into your  block .

 

(defun c:Test (/ ss e Ent)
  (vl-load-com)
  (if (setq ss (nentsel "\n Select Text in a block :"))
    (progn
      (cond ((eq "TEXT" (cdr (assoc 0 (entget (car ss)))))
             (entupd  (cdr  (assoc -1 (entmod (subst (cons 41 1.)(assoc 41 (setq e (entget (car ss)))) e))))))
            ((eq "MTEXT" (cdr (assoc 0 (entget (car ss)))))
             (entupd  (cdr  (assoc -1 (entmod (subst (cons 41 1.)
                                                     (assoc 41 (setq Ent (entget (tblobjname "STYLE" (cdr (assoc 7 (entget (car ss))))))))Ent)))))))
             
      (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object))
                 acAllViewports
      )
    )
    (princ)
  )
  (princ)
)

Message 3 of 15
cadman777
in reply to: cadman777

thanks for the code

i tried it and it didn't appear to do anything

can you tell me what it's supposed to do?
also, can you show me your code in old-style autolisp?
I can't do v-lisp or v-basic, but can fiddle with autolisp, working from memory when I wrote code for r12-14 acad

thanks ... chris

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 4 of 15
_Tharwat
in reply to: cadman777

As I said before , you should select the text in the block directly .and it would extract the width of the selected text in the

block to be 1 as you required, but if the width of text is already 1 , action won't ake a place.

 

I am also confused with your needs . What is the width of text you want 1 of 0.75 ??

 

Message 5 of 15
pbejse
in reply to: cadman777


@cadman777 wrote:

Does someone have an autolisp routine that edits all simple text and mtext inside a block without editing the block?

I want to be able to select the block, or window around a block to select all text, and then edit the text width factor.

The reason I need this is b/c the newer versions of autocad revert all text width factor of older autocad text entities to 1, but they were .75 in all my old drg title blocks (about 3 gigs of them).

thanks ... Chris


If you want it done globally, your best bet would be redefining your block , (you can use this in conjunction with a script)

 

(defun C:RDEF  (/ blkname cmde)
  ;;		Change this line to reflect the new block		;;
 (setq blkname (findfile "c:\\NewBLockLocation\\YourBlock.dwg"));<---
    (if (tblsearch "block" (cadr (fnsplitl blkname)))
    (progn
      (command
        "._-insert"
        (strcat (cadr (fnsplitl blkname)) "=" blkname)
        (command))
      (princ (strcat "\nBlock " (strcase blkname) " redefined."))))
  (princ))

 

 But if you wnat it done individually (via selection)

 

(defun c:WidthChange (/ ss e tsel opt)
	(while (setq ss (car (nentsel "\nSelect Text:")))
          		(redraw ss 3)
			(if (wcmatch (cdr (assoc 0 (entget ss))) "*TEXT")
          			(setq tsel (cons ss tsel))))
	(if tsel
          	(foreach tx tsel
                  	(setq e (entget tx))
                  	(setq opt
                           	(list (cons 1 (strcat "{\\W1;"(cdr (assoc 1 e)) "}"))'(41 . 1.0)))
                  	(entmod (subst (cons (setq ent (if (assoc 42 e) 1 41))
                                         	 (cdr (assoc ent opt)))
                                          	 (assoc ent e) e))
                  	(entupd tx))
                  )
	(command "_.regen")
  	(princ)
          )

 

I expect you understand the way this code is written, and  there is nowhere on this code you will see VL, 

Hope this helps


Autolisper wrote::
.........
(entupd  (cdr  (assoc -1 (entmod (subst (cons 41 1.)
        (assoc 41 (setq Ent (entget (tblobjname "STYLE"
          (cdr (assoc 7 (entget (car ss))))))))Ent)))))......

 

Take note, by doing it this way, ALL MTEXT using the same textstyle will be affected.

 

 

Message 6 of 15
_Tharwat
in reply to: cadman777

Thanks a lot .

 

You are right , changing textstyle would affect on all texts in dwg.

 

But I still wonder about your way of changing the width by the use of this .

(setq tsel (cons ss tsel))

(strcat "{\\W1;" (cdr (assoc 1 e)) "}")

 

Thanks

Message 7 of 15
pbejse
in reply to: _Tharwat


@Autolisper wrote:

 ......    (setq tsel (cons ss tsel)) ..... 

 

 

its a collection of filtered enames from objects selected, that way theres no need for the overhead of testing each one on  the main code. (somewhat like like ssget  ":S" thingy but using nentsel for nested entities).(multiple selection)

Let me put it this way, "collect valid entities then process" got it?

 

 


@Autolisper wrote:

 (strcat "{\\W1;" (cdr (assoc 1 e)) "}") 


Look into MTEXT formatting, only problem i can see with this approach is, if the MTEXT is already formated, then i need to strip it and rewrite the STRING . its not hard though, but as the OP stated, he knew a thing or two about lisp. i'm sure he can figure it out.

 

Nice to know you're interested on how other people write codes. thats how I learn too.

good habit  and good for you Autolisper

 

Smiley Happy

 

 

 

 

 

Message 8 of 15
cadman777
in reply to: cadman777

Autolisper,

Thanks for helping.

I believe the reason it didn't work is b/c I wanted to change the text width factor from 1 to .75.

In other words, it's 1 now, but it needs to change to .75.

My problem is that I can't remember my autolisp from the old days, and i'm not a good programmer.

Us mechanical guys are good at design, calcs, and all that stuff, so we depend on and appreciate the skills you guys have.

So, what I need to do now is take an hour or so, and try to understand what you did in your code, and change the number to .75 that defines the text width factor.

As you can see, this is a big job for me, since i'm not versed in lisp any more.

Thanks for helping ... Chris

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 9 of 15
cadman777
in reply to: pbejse

pbejse,

Thanks for helping too.

I need to take time to try to read and use your code.

Yesterday I got nearly all my 'coding' done, which took me the better part of a day.

I bet you guys could have done it in an hour!

Anyways, I appreciate all the help you guys are giving me.

... Chris

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 10 of 15
pbejse
in reply to: cadman777


@cadman777 wrote:

........wanted to change the text width factor from 1 to .75.

Thanks for helping ... Chris


in that case. change this.

 

(setq opt
(list (cons 1 (strcat "{\\W1;"(cdr (assoc 1 e)) "}"))'(41 . 1.0)))

to

 

(setq opt
(list (cons 1 (strcat "{\\W0.75;"(cdr (assoc 1 e)) "}"))'(41 . 0.75)))

 

I'm pretty sure everything you knew about lisp will come back to you eventually.

 

Good luck CadMan777

 

 

Message 11 of 15
cadman777
in reply to: pbejse

pbejse,

Thanks for the update.

I took out my old book that taught me lisp and used it as a dictionary of sorts to 'read' your guys code.

"AutoLISP Programming: Principles and Techniques" by Rod Rawls/Mark Hagen.

Now that I can kind-of speak 'broken lisp', it looks like you gave me 2 options in your code:
1. editing text one line at a time, or

2. re-making a block on disk.

Am I right?
What did you have in mind wiht a script file?

I'm not follwing you.

I just wanted to be able to pick a block on screen and have all the text in it update to .75 width factor, not one line at a time.

I fixed Autolisper's code to do the text width factor change to .75, so now i have 2 codes that do only one pick at a time.

This is not global block text editing.

do you know of any code out there that does what I want?

When I get that code, I'll add it to my script that's attached to a tool bar button.

The script already runs 3 lisp files that are apploaded, and i want to add this as a forth lisp file to fix the mess adsk made in their 'upgrade' of autocad.

Thanks ... Chris

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 12 of 15
Kent1Cooper
in reply to: cadman777


@cadman777 wrote:

....

I just wanted to be able to pick a block on screen and have all the text in it update to .75 width factor, not one line at a time.

I fixed Autolisper's code to do the text width factor change to .75, so now i have 2 codes that do only one pick at a time.

This is not global block text editing.

do you know of any code out there that does what I want?

....


Here's one way to do it for all plain Text entities in a selected Block's definition [limited testing]:

 

(defun C:BT75 (/ ent edata); = Block Text to width factor of .75
  (setq ent
    (cdr (assoc -2 ; first sub-entity in Block's content
      (entget (tblobjname "BLOCK"
        (cdr (assoc 2 ; Block name
          (entget (car (entsel "\nSelect Block for Text Width upgrade: ")))
        )); end cdr / assoc 2
      )); end entget / tblobjname
    )); end cdr / assoc -2
  ); end setq
  (while ent
    (setq edata (entget ent))
    (if (= (cdr (assoc 0 edata)) "TEXT")
      (entmod (subst '(41 . 0.75) (assoc 41 edata) edata)); force width
    ); end if
    (setq ent (entnext ent)) ; next sub-entity, if any
  ); end while
  (command "_.regen"); update on-screen
); end defun

It may have changed since my 2004, but I can't affect the width factor of text inside Mtext entities [mentioned in your first post], except through the definition of the text Style, which I would hope isn't affected/afflicted by the same problem.  So if that's something you can do in Mtext in later versions, someone else will have to help you incorporate that.

Kent Cooper, AIA
Message 13 of 15
Kent1Cooper
in reply to: Kent1Cooper


 

Kent1Cooper wrote:

....

....
      (entget (tblobjname "BLOCK"
        (cdr (assoc 2 ; Block name
          (entget (car (entsel "\nSelect Block for Text Width upgrade: ")))
        )); end cdr / assoc 2
      )); end entget / tblobjname
....

It turns out that part can be simplified slightly, replacing (entget (tblobjname...  with just (tblsearch... :

 

....
      (tblsearch "BLOCK"
        (cdr (assoc 2 ; Block name
          (entget (car (entsel "\nSelect Block for Text Width upgrade: ")))
        )); end cdr / assoc 2
      ); end tblsearch
....
Kent Cooper, AIA
Message 14 of 15
cadman777
in reply to: cadman777

Kent,

Thanks for the code!

It works just like I want in my toolbar button script.

This saves my wrists from 'acad death'.

I really appreaciiate your assistance.

It took 3 programs to make my block text width edit routine work:

1. edit attribute width (a Cadalyst pick)

2. edit text with CHTEXT (and ancient original acad command revived and posted on Cadalyst)

3. your plain text inside block width changing code

That's what it took to fix the acad upgrade fiasco.

Thanks again for bring this to completion for me!

... Chris

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 15 of 15
pbejse
in reply to: cadman777


@cadman777 wrote:

pbejse,

Thanks for the update.


1. editing text one line at a time,

correct, (one entity at a time but you can select multiple text on one run),

at first I was thinking more of one BLOCK  at a time. that why i opted for REDEFINE option

2. re-making a block on disk.

I meant re-define a block (inserting the file from a folder that will redefine the exisitng with modified block)

 

But anyhooo. all is good now, if your ran into problems usng Kents code for  MTEXT width , just holler and will try and fix it for you

 

pBe

 

 

Thanks ... Chris

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost