Change text content of Mtext

Change text content of Mtext

diogo-braz
Explorer Explorer
1,058 Views
5 Replies
Message 1 of 6

Change text content of Mtext

diogo-braz
Explorer
Explorer

I'm trying to split the string below into two chunks to be able to implement in to a mtext:

 

"\\pxsm1;Trapezoidal profile sheet of the "loop" type, thermo-lacquered in RAL 9010 (white) color, resting on a metallic structure\\P\\PGutter and roof trims with 3mm thick bent steel sheet esp.\\P\\P\\ps*,ql;Covering of the Prefabricated Concrete Platform, (see construction details)\\P\\PSteel downpipes, galvanized and painted with enamel paint in RAL 1013"

 

I did this code for separating into chunks of 255 characters:

 

(while (> (strlen texto-temp) 0)
   (if (<= (strlen texto-temp) 200)
      (setq numb 1)
      (setq numb 3)
   )
   (if (= c-atr 304)
      (setq numb 304)
   )
   (setq bloquinho (cons numb (substr texto-temp 1 255)))
   (setq blocos-250 (cons bloquinho blocos-250))
   (setq texto-temp (substr texto-temp 256 (strlen texto-temp)))
)

 

it results in this list:

(
   (1 . " construction details)\\P\\PSteel downpipes, galvanized and painted with enamel paint in RAL 1013")
   (3 . "\\pxsm1;Trapezoidal profile sheet of the \"loop\" type, thermo-lacquered in RAL 9010 (white) color, resting on a metallic structure\\P\\PGutter and roof trims with 3mm thick bent steel sheet esp.\\P\\P\\ps*,ql;Covering of the Prefabricated Concrete Platform, (see")

)

 

But I want to the element 3. to have just 255 characters, not 263 as this website says (https://mothereff.in/byte-counter). Because of that, the Mtext elements disappear on the drawing paper and I cannot see it anymore.

 

What am I doing wrong?

0 Likes
Accepted solutions (2)
1,059 Views
5 Replies
Replies (5)
Message 2 of 6

ronjonp
Mentor
Mentor
Accepted solution

@diogo-braz 

IMO this would be much easier using VLA-GET\PUT-TEXTSTRING.

0 Likes
Message 3 of 6

Sea-Haven
Mentor
Mentor

Have you thought about reading a text file as the mtext source ? Not sure why your mtext is not working this is my old  "NOTES" saved as a dwg.

SeaHaven_0-1684368137668.png

 

0 Likes
Message 4 of 6

john.uhden
Mentor
Mentor
Accepted solution

@diogo-braz ,

I have to agree with @ronjonp ...

By the old-fashioned dxf method, you have to strcat all the dxf 3s with the dxf 1 to get the whole texstring.

But (vlax-get object 'texstring) returns the entire string.

Not that the dxf method is bad, just that many things are easier with ActiveX methods.

John F. Uhden

0 Likes
Message 5 of 6

ronjonp
Mentor
Mentor

@diogo-braz I'm not exactly sure what you're doing with these strings but here's a simple example how to modify the text without using VLA.

 

(defun c:foo (/ s)
  ;; RJP » 2023-05-18
  ;; Example to replace spaces with underscores without using VLA
  (if (setq s (ssget "_:L" '((0 . "*TEXT"))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (entmod (mapcar '(lambda (x)
			 (if (member (car x) '(1 3))
			   (cons (car x) (vl-string-translate " " "_" (cdr x)))
			   x
			 )
		       )
		      (entget e)
	      )
      )
    )
  )
  (princ)
)

2023-05-18_06-48-43.gif

 

0 Likes
Message 6 of 6

diogo-braz
Explorer
Explorer

Thank you for all the answers. I corrected the code using DFX objects, it's way easier than the way that I was codding

 

0 Likes