Author Topic: witdh of mtext  (Read 1638 times)

0 Members and 1 Guest are viewing this topic.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
witdh of mtext
« on: April 20, 2016, 01:51:04 PM »
Hello such lisp have this (I think this lisp public Leemac) amending witdh of mtext, the problem is that every time I return to select the same mtext to change the width this does not change again.

Code: [Select]
(defun c:test5 (/ i ss ent eLst joindatosxp)
(setq *datosxp* (cond ((getstring (strcat "\nSpecify width of mtext <" (setq *datosxp* (cond ( *datosxp* ) ( 0.75 ))) ">: "))) ( *datosxp* )))
(setq joindatosxp (strcat "{\\W" *datosxp* ";"))
(if (setq i -1 ss (ssget "_:L" '((0 . "MTEXT"))))
(while (setq ent (ssname ss (setq i (1+ i))))
(entmod
(subst (cons 1 (strcat joindatosxp (cdr (assoc 1 (setq eLst (entget ent)))) "}")) (assoc 1 eLst) eLst))))
(princ))
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

ChrisCarlson

  • Guest
Re: witdh of mtext
« Reply #1 on: April 21, 2016, 08:02:20 AM »
I'm not going to troubleshoot that but

Code - Auto/Visual Lisp: [Select]
  1. (defun c:WD (/ ss wd)
  2.   ;; Change width of selected MText and MultiLeader objects
  3.   ;; Alan J. Thompson, 11.05.09
  4.   (if (and (setq ss (ssget "_:L" '((0 . "MTEXT,MULTILEADER"))))
  5.            (setq wd (initget 4)
  6.                  wd (cond ((getdist "\nWidth <0.0>: "))
  7.                           (0.)
  8.                     )
  9.            )
  10.       )
  11.     (progn
  12.                              (cond (*AcadDoc*)
  13.                                    ((setq *AcadDoc* (vla-get-activedocument
  14.                                                       (vlax-get-acad-object)
  15.                                                     )
  16.                                     )
  17.                                    )
  18.                              )
  19.                            )
  20.                   )
  21.         (vl-catch-all-apply
  22.           (function vlax-put-property)
  23.           (list x
  24.                 (cond ((eq (vla-get-objectname x) "AcDbMText") 'Width)
  25.                       ((eq (vla-get-objectname x) "AcDbMLeader") 'TextWidth)
  26.                 )
  27.                 wd
  28.           )
  29.         )
  30.       )
  31.       (vla-delete ss)
  32.     )
  33.   )
  34.   (princ)
  35. )

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: witdh of mtext
« Reply #2 on: April 21, 2016, 12:35:55 PM »
=/
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

ChrisCarlson

  • Guest
Re: witdh of mtext
« Reply #3 on: April 21, 2016, 01:08:48 PM »
As-is, the program does not run

Code: [Select]
Command: TEST5
Error: bad argument type: stringp 0.75

Based on this, the routine is wanting a string but you are passing something else.
http://www.lee-mac.com/errormessages.html

Looking at your code you are prompting the user to enter a width. You specify a string (getstring) but are entering a real (0.75).

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: witdh of mtext
« Reply #4 on: April 21, 2016, 01:26:56 PM »
Code: [Select]
  (defun c:test5 (/ i ss ent eLst joindatosxp)
  (setq *datosxp* (cond ((getreal (strcat "\nSpecify width of mtext <" (rtos (setq *datosxp* (cond ( *datosxp* ) ( 0.75 ))) 2 2) ">: "))) ( *datosxp* )))
  (setq joindatosxp (strcat "{\\W" (rtos *datosxp* 2 2) ";"))
  (if (setq i -1 ss (ssget "_:L" '((0 . "MTEXT"))))
  (while (setq ent (ssname ss (setq i (1+ i))))
  (entmod
  (subst (cons 1 (strcat joindatosxp (cdr (assoc 1 (setq eLst (entget ent)))) "}")) (assoc 1 eLst) eLst))))
  (princ))
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

ronjonp

  • Needs a day job
  • Posts: 7529
Re: witdh of mtext
« Reply #5 on: April 21, 2016, 01:33:50 PM »
Code: [Select]
  (defun c:test5 (/ i ss ent eLst joindatosxp)
  (setq *datosxp* (cond ((getreal (strcat "\nSpecify width of mtext <" (rtos (setq *datosxp* (cond ( *datosxp* ) ( 0.75 ))) 2 2) ">: "))) ( *datosxp* )))
  (setq joindatosxp (strcat "{\\W" (rtos *datosxp* 2 2) ";"))
  (if (setq i -1 ss (ssget "_:L" '((0 . "MTEXT"))))
  (while (setq ent (ssname ss (setq i (1+ i))))
  (entmod
  (subst (cons 1 (strcat joindatosxp (cdr (assoc 1 (setq eLst (entget ent)))) "}")) (assoc 1 eLst) eLst))))
  (princ))
This works for me .. but you may want to check if width has already been applied or you'll end up with a mess like this:
"{\\W6.00;{\\W3.00;{\\W2.00;{\\W0.75;TEST}}}}"


Maybe something like this will help ( although I think hard coded properties in mtext is  >:D  )
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test5 (/ elst ent i joindatosxp ss str)
  2.   (setq *datosxp* (cond ((getreal (strcat "\nSpecify width of mtext <"
  3.                                           (rtos (setq *datosxp* (cond (*datosxp*)
  4.                                                                       (0.75)
  5.                                                                 )
  6.                                                 )
  7.                                                 2
  8.                                                 2
  9.                                           )
  10.                                           ">: "
  11.                                   )
  12.                          )
  13.                         )
  14.                         (*datosxp*)
  15.                   )
  16.   )
  17.   (setq joindatosxp (strcat "{\\W" (rtos *datosxp* 2 2) ";"))
  18.   (if (setq i  -1
  19.             ss (ssget "_:L" '((0 . "MTEXT")))
  20.       )
  21.     (while (setq ent (ssname ss (setq i (1+ i))))
  22.       (setq str (cdr (assoc 1 (setq elst (entget ent)))))
  23.       (while (wcmatch str "{\\W*")
  24.         (setq str (vl-string-right-trim "}" (substr str (+ 2 (vl-string-search ";" str)))))
  25.       )
  26.       (entmod (subst (cons 1 (strcat joindatosxp str "}")) (assoc 1 elst) elst))
  27.     )
  28.   )
  29.   (princ)
  30. )
« Last Edit: April 21, 2016, 01:46:17 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: witdh of mtext
« Reply #6 on: April 21, 2016, 01:51:11 PM »
Thank your code fix my problem thank you very much, good afternoon.
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

ronjonp

  • Needs a day job
  • Posts: 7529
Re: witdh of mtext
« Reply #7 on: April 21, 2016, 02:05:21 PM »
Glad to help :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC