Modify mtext in block

Modify mtext in block

Anonymous
Not applicable
3,227 Views
17 Replies
Message 1 of 18

Modify mtext in block

Anonymous
Not applicable

Hello,

 

I want to edit texte in block by picking the text and use mtedit.

 

I create this for text but i don't know how use mtedit in block.

 

(defun c:test (/ txt)
(setq txt (cdr(assoc 0 (entget(car (nentsel "\nSelect:"))))))
(command "_.mtedit" txt)
)

 

Can you help me

0 Likes
Accepted solutions (1)
3,228 Views
17 Replies
Replies (17)
Message 2 of 18

ВeekeeCZ
Consultant
Consultant

After little trials, this looks like may work.

 

(defun c:test (/ pnt)
  (if (setq pnt (cadr (entsel "\nSelect MText within block: ")))
    (progn
      (command "_.-refedit" pnt "_o" "_a" "_y")
      (command-s "_.mtedit" pnt)
      (command "_.refclose")
      (while (> (getvar 'CMDACTIVE) 0)
        (command "_save"))))
  (princ)
)
0 Likes
Message 3 of 18

Anonymous
Not applicable

Thank you

0 Likes
Message 4 of 18

Anonymous
Not applicable

Sorry 

 

The solution don't work with dynamic block.

 

 

An idea?

0 Likes
Message 5 of 18

john.uhden
Mentor
Mentor

The only way my ancient mind can figure is to (nentsel) the mtext within the block, then create a duplicate in the current space, then run MTEDIT on the clone, and then put the textstring back into the original, obviously deleting the clone.

John F. Uhden

0 Likes
Message 6 of 18

CodeDing
Advisor
Advisor

Taaz,

 

I am not as experienced as these other posters, but if you post the block I'd be willing to try to learn it to for you.

 

Best,

~DD

0 Likes
Message 7 of 18

john.uhden
Mentor
Mentor

Aren't you a friend of Pat Pend?

John F. Uhden

0 Likes
Message 8 of 18

daron.rogers
Explorer
Explorer

Wouldn't using entmod and entupd and possibly getstring, if you need user input, do the job?

0 Likes
Message 9 of 18

Anonymous
Not applicable
Ni I'm not
0 Likes
Message 10 of 18

Anonymous
Not applicable
How you clone and keep the dynamic property
0 Likes
Message 11 of 18

john.uhden
Mentor
Mentor
Accepted solution

@Anonymous wrote, "How you clone and keep the dynamic property?"

 

I didn't mean to clone the block, just the mtext probably using entget and entmake.

What I don't know is whether you can entmod an object within a dynamic block.  And I can't test because I am still running only ACAD2002.

 

Whatever.  See if this works for you.  It doesn't have any error or undo controls but we can add them easily enough.

 

(defun c:EDTest ( / e ent etype clone new)
  (and
    (setq e (car (nentsel "\nSelect text within block to edit: ")))
    (setq ent (entget e))
    (setq etype (cdr (assoc 0 ent)))
    (setq clone (entmakex ent))
    (cond
      ((= etype "TEXT")(vl-cmdf "_.DDEDIT" clone ""))
      ((= etype "MTEXT")(vl-cmdf "_.MTEDIT" clone))
      (prompt "\nEntity selected is not text.")
    )
    (setq new (assoc 1 (entget clone)))
    (entmod (subst new (assoc 1 ent) ent))
    (entdel clone)
    (vl-cmdf "_.regen")
  )
  (princ)
)

John F. Uhden

0 Likes
Message 12 of 18

R0m3r014
Contributor
Contributor

Hi, how are you?
maybe you want to use this routine that allows you to edit multiple text strings, both in blocks, as in dynamic blocks and non-nested strings.

to work correctly you need to have the .lisp file and the .dcl file in an autocad support path.

I hope it works for you, luck

 

Here the .lsp code

 

;Edita multiples cadenas de texto: text; Mtext; Attributo; Dimension
;Edita aun dentro de bloques.
;Necesita EMT.DCL

(defun c:emt ()
  (setq flg 1)
  (done_dialog)


(setq dcl_id (load_dialog "EMT.DCL"))
(while
  (setq bltxt (nentsel "\nTEXTO EN EL BLOQUE A MODIFICAR: \n<ESC> PARA TERMINAR"))
  (setq entdata (entget (car bltxt)) btxt (cdr (assoc 1 entdata)) ostr btxt)
  (setq flg 0)
  (if (not (new_dialog "EMT" dcl_id)) (exit))
  (set_tile "btxt" btxt)
  (mode_tile "btxt" 2)
  (action_tile "btxt" "(setq btxt $value)")
  (action_tile "accept" "(done_dialog)")
  (action_tile "cancel" "(reset)")
  (start_dialog)
  (if (/= flg 1)
    (progn
      (entmod (subst (cons 1 btxt)(assoc 1 entdata) entdata))
      (if (setq bltxt (car (reverse (cadddr bltxt)))) (entupd bltxt))
    )
  )
)

(unload_dialog dcl_id)
(setq bltxt nil entdata nil btxt nil flg nil dcl_id nil)
(princ)
);end defun

Here the .dcl code

 

EMT : dialog {
   label = "MODIFICAR ATTRIBUTOS Y TEXTO" ;
   spacer_1 ;
   : text {
      label = "EDITAR CADENA DE TEXTO EN EL BLOQUE:" ;
   }
   : edit_box {
      fixed_width = true ;
      key = "btxt" ;
      width = 40 ;
   }
   spacer_1 ;
   ok_cancel ;
}
0 Likes
Message 13 of 18

Anonymous
Not applicable

Thank you that work

0 Likes
Message 14 of 18

ВeekeeCZ
Consultant
Consultant

Ok, here little mod for dynamic blocks.

 

(defun c:Test (/ pnt)
  (if (setq pnt (cadr (entsel "\nSelect MText within block: ")))
    (progn
      (command "_.-refedit" pnt "_o")
      (if (wcmatch (getvar 'LASTPROMPT) "*contains custom block properties*,*your french version*") ;; Dynamic block
        (command "_o"))
      (command "_a" "_y")
      (command-s "_.mtedit" pnt)
      (command "_.refclose")
      (while (> (getvar 'CMDACTIVE) 0)
        (command "_save"))))
  (princ)
)

But, if you have different language version, you need add the exact (or a part of) phrase and replace the blue text in to code. Run the previous version and hit F2 to see the command-line window: Take to french translation of bold line.

 

Select MText within block: _.-refedit
Select reference:
Select nesting level [Ok/Next] <Next>: _o
The block reference contains custom block properties. Editing the block in-place will break the link to the original definition and create a new block definition [Ok/Cancel] <Ok>:_a
Invalid option keyword.
Function cancelled

 

 

PS If you like John's solution, you should at least add this line to the end. 

(command "_.zoom" "_P")

 

 

@john.uhden Surprised that I see no coods transformation. It moves you/the OP to the hell (and not back). But congrats to the solution!

 

 

0 Likes
Message 15 of 18

Anonymous
Not applicable

Thank you 

 

I appreciate your enthusiasm 

0 Likes
Message 16 of 18

john.uhden
Mentor
Mentor
@ВeekeeCZ wrote, " @john.uhden
Surprised
that I see no coods transformation. It moves you/the OP to the hell (and
not back). But congrats to the solution! "

I did my minimal testing on a very plain drawing with no UCS thingy turned
on. Considering there my be an annoying blink for some reason, I was going
to entmake the clone with visibility turned off, but skipped that part when
it appeared to work okay. I figured that someone would report any strange
behavior. After all, the method was to modify only the textstring property
within the block, not anything else.

John F. Uhden

0 Likes
Message 17 of 18

ВeekeeCZ
Consultant
Consultant

@john.uhden wrote:
@ВeekeeCZ wrote, " @john.uhden
Surprised
that I see no coods transformation. It moves you/the OP to the hell (and
not back). But congrats to the solution! "

I did my minimal testing on a very plain drawing with no UCS thingy turned
on. Considering there my be an annoying blink for some reason, I was going
to entmake the clone with visibility turned off, but skipped that part when
it appeared to work okay. I figured that someone would report any strange
behavior. After all, the method was to modify only the textstring property
within the block, not anything else.

Well, I see. I presumed that ENTMAKEing MTEXT with its coords related to block's '(0 0 0) OCS would be in WCS drawing issue. Which really is, but (surprisingly ONLY) in the current MTEXT editor. I didn't realize, that the old mtext editor behaves much different and this is not an issue there. 

 

For your information, see HERE the screencast of behaviour 1) your routine with the old editor, 2) your routine with new editor, 3) my dirty-dirty routine.

0 Likes
Message 18 of 18

john.uhden
Mentor
Mentor

I couldn't watch it with the sun shining through the windows onto my laptop screen (it's almost cocktail time here).  I will try again later.

BTW, I tried making the clone invisible, but when I did the editor would not respond, so nothing happened.  Maybe another method would be to change the clone to a frozen layer, but that seems like just a bunch of silly overhead.

John F. Uhden

0 Likes