Lisp - Change Part of Mtext to smaller textsize

Lisp - Change Part of Mtext to smaller textsize

stijn.dedeckerM4Q3S
Participant Participant
1,015 Views
14 Replies
Message 1 of 15

Lisp - Change Part of Mtext to smaller textsize

stijn.dedeckerM4Q3S
Participant
Participant

Hi, 

 

I have in my dwg files for each room a mtext block - firstline - roomnumber, secondline spacetype, example "00.01\PBuiten_trap" now i want for all spacetypes that the the size will be changed to 0.10, the roomnumber must stay  the same (0.25)

 

This is the list of spacetypes : niet ingerichte ruimte,technische ruimte,verharde zone,parkeerruimte buiten,helling binnen,helling,Buiten_trap

0 Likes
1,016 Views
14 Replies
Replies (14)
Message 2 of 15

wispoxy
Advisor
Advisor
Most architects use TAGS and ATTDEF blocks, then you can preset that text. Makes it easier to work with for anyone.
0 Likes
Message 3 of 15

pendean
Community Legend
Community Legend

@wispoxy wrote:
Most architects use TAGS and ATTDEF blocks, then you can preset that text. Makes it easier to work with for anyone.

I think they are trying to fix a pre-existing condition in many DWG files... .

0 Likes
Message 4 of 15

stijn.dedeckerM4Q3S
Participant
Participant
We import the dwgs in a facility program
0 Likes
Message 5 of 15

wispoxy
Advisor
Advisor
Ugh, not easy to deal with that as a pre-existing condition. Would be nice to have an AutoCAD feature to detect that and rebuild them as blocks.
0 Likes
Message 6 of 15

Sea-Haven
Mentor
Mentor

Are they mtext and always in a pattern like change 3rd line size then yes could be done.

 

If they are groups of say 4 lines then yes a nightmare to fix, can be done but must select 4 lines repeatedly as a simple answer, smarter people than me have some answers for this 4 lines of text problem.

0 Likes
Message 7 of 15

stijn.dedeckerM4Q3S
Participant
Participant

its always the data after \P 

voorbeeld 2.PNG

voorbeeld 1.PNG

  

0 Likes
Message 8 of 15

Sea-Haven
Mentor
Mentor

Try this.

 

; Changes second line in a mtext

(defun c:wow ( / obj txtht str pos txt1 txt2 txt3)

(while (setq ent (car (entsel "\nSelect a MText object Enter to exit ")))
(setq obj (vlax-ename->vla-object ent))

; (setq txtht (/ newht (vlax-get obj 'height)))
; (setq newht (getreal "\nEnter new height "))
; (setq txtht (/ newht txtht))

(setq txtht (/ 0.1 0.25))
(setq str (vlax-get obj 'textstring))
(setq pos (setq pos (vl-string-position 92 str)))
(setq txt1 (substr str 1 (+ pos 2)))
(setq txt2 (strcat "\\H" (rtos txtht 2 3) "x;"))
(setq txt3 (substr str (+ pos 1)))

(vlax-put obj 'Textstring (strcat txt1 txt2 txt3))
)
(princ)
)

 

0 Likes
Message 9 of 15

stijn.dedeckerM4Q3S
Participant
Participant
I get error
command ; error malformed list on input
0 Likes
Message 10 of 15

Kent1Cooper
Consultant
Consultant

@stijn.dedeckerM4Q3S wrote:

its always the data after \P 


If it's also always all the data after \P [with none later on that you do not want changed in height], try this:

 

(defun C:MT2HR ; = MText 2nd line Height Reduction
  (/ mt mtdata str)
  (setq
    mt (car (entsel "\nSelect Mtext: "))
    mtdata (entget mt)
    str (cdr (assoc 1 mtdata))
  ); setq
  (entmod
    (subst
      (cons 1
        (strcat
          (vl-string-subst "\\P{\\H0.4x;" "\\P" str)
          "}"
        ); strcat
      ); cons
      (assoc 1 mtdata)
      mtdata
    ); subst
  ); entmod
  (prin1)
)

 

That's for selection of one Mtext object, but can be adjusted easily to do it to all of a selection of multiple Mtexts.  It could limit selection to only those that go to a second line in \P fashion.

 

Also, that's specific to your heights of 0.25 and 0.1 [which is where the 0.4x height multiplier comes from -- height adjustment formatting is a ratio, not an explicit height].  It could need to be a different multiplier for other sizes, if needed, or it could ask for the height you want the content after the first line changed to, and calculate the multiplier based on the initial height.

Kent Cooper, AIA
0 Likes
Message 11 of 15

stijn.dedeckerM4Q3S
Participant
Participant

This don't work, 

The CadImportModule on the facility Software gives error on that

0 Likes
Message 12 of 15

Kent1Cooper
Consultant
Consultant

@stijn.dedeckerM4Q3S wrote:

This don't work, 

The CadImportModule on the facility Software gives error on that


It works on 2-line Mtext with \P causing the second line, for me.  Time for you to post a small sample drawing, or to look into a Forum for the facility software, whatever that is.

 

EDIT:  Now tested at two locations, on Acad2020 and Acad2024.

And on general principles, something like "gives error" is never enough information, if you don't describe what the error is.  [Not that more detail would necessarily help solve it, if it's a limitation in the other software.]

Kent Cooper, AIA
0 Likes
Message 13 of 15

pendean
Community Legend
Community Legend

@stijn.dedeckerM4Q3S wrote:

This don't work, 

The CadImportModule on the facility Software gives error on that


Your Facilities software most likely does not recognize or support /P entries: many do not, some do not work with MTEXT, they can only use TEXT objects. Many do not like Attributes either.

 

The LISP above work great in AutoCAD here too.

0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

@pendean wrote:
.... Your Facilities software most likely does not recognize or support /P entries: many do not, ....

... which raises the question:  Does the facilities software work with Mtext objects containing \P for new lines, but without the height change for the second line?  If \P entries are the problem, then those original Mtexts would give the same error.

Kent Cooper, AIA
0 Likes
Message 15 of 15

Sea-Haven
Mentor
Mentor

Sorry dropped a Close bracket somewhere along the way code corrected above.

0 Likes