mtext height change, code error

mtext height change, code error

Anonymous
Not applicable
1,366 Views
6 Replies
Message 1 of 7

mtext height change, code error

Anonymous
Not applicable
; mtext height change
(defun c:chgtxth ()

  (setq n 0 )

  (setq sstxt (ssget "_X" '((0 . "MTEXT")(40 . 500))))

  (repeat (sslength sstxt)
    (setq en (ssname sstxt n))
    (setq endata (entget en))
    (setq entype (cdr (assoc 40 endata)))
    (if (= entype 500)
      (txt_h)
      );end if
    (setq n (1+ n))
    ); end repeat
  (prin1)
  ); defun

  (defun txt_h()
  (setq old_h (assoc 40 endata))
    (setq new_h (cons 40 600))
    (setq endata (subst new_h old_h endata))
    (entmod endata)
        ); sub-defun

  (prompt "change mtext height")
  (prin1)
  
  

Hello, experts,

 

The code I wrote for changing mtext height from 500 to 600 always gave me error message; can anyone help me to identify the mistakes?

thanks,

0 Likes
Accepted solutions (1)
1,367 Views
6 Replies
Replies (6)
Message 2 of 7

dbroad
Mentor
Mentor

What is your error? It seems to work fine here.  It could certainly be improved but works.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 7

Ranjit_Singh
Advisor
Advisor

What error message do you get? It works fine at my end. Although I would recommend localizing the variables and passing endata to the txt_h function

(defun c:chgtxth  (/ en endata entype n sstxt)
  (setq n 0)
  (setq sstxt (ssget "_X" '((0 . "MTEXT") (40 . 500))))
  (repeat (sslength sstxt)
    (setq en (ssname sstxt n))
    (setq endata (entget en))
    (setq entype (cdr (assoc 40 endata)))
    (if (= entype 500)
      (txt_h endata)) ;end if
    (setq n (1+ n))) ; end repeat
  (prin1)) ; defun
(defun txt_h  (endata / new_h old_h)
  (setq old_h (assoc 40 endata))
  (setq new_h (cons 40 600))
  (setq endata (subst new_h old_h endata))
  (entmod endata)) ; sub-defun
(prompt "change mtext height")
(prin1)
Message 4 of 7

pbejse
Mentor
Mentor
Accepted solution

hifrank001 wrote:

 

...The code I wrote for changing mtext height from 500 to 600 always gave me error message; can anyone help me to identify the mistakes?

thanks,


Silly question (coming from me) < don't take it the wrong way > but does the drawing even have an MTEXT with 500 height??

 

If none was found, you will get this because of the way the code is written | from (sslength ssttxt)

 

 

 

; error: bad argument type: lselsetp nil

if so,

 

Add

 

(if (setq sstxt (ssget "_X" '((0 . "MTEXT") (40 . 500))))

and and closing parenthesis.

 

HTH

 

Message 5 of 7

Anonymous
Not applicable

thanks, pBe; it is the error message I got; but the plan does have 500 mtext. see attached.

Thanks, people.

0 Likes
Message 6 of 7

Anonymous
Not applicable

I found the mistake but it is not from the code.

Thanks

0 Likes
Message 7 of 7

pbejse
Mentor
Mentor

@Anonymous wrote:

thanks, pBe; it is the error message I got; but the plan does have 500 mtext. see attached.

Thanks, people.


I see, one more reason for that is when the value for variable n is out of range, but it clearly defined on your code.

 

But then again, if you leave your code as it stands now [ no if statement ] , second time you ran the command it will again produce that error.

 

Sit back and think , what did you do differently when the error pops up again on the command line.

 

EDIT: I see you got it figured out then.

 

MORE EDIT: I would suggest you use VLIDE when debugging your code, easier to spot the errors like the one you had.

 

Cheers