TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Fabricio28 on July 28, 2017, 07:39:48 AM

Title: Lisp to align Text from objects-help
Post by: Fabricio28 on July 28, 2017, 07:39:48 AM
Hello guys!
I'm using that excellent code to align a text from line or curve.

But sometimes when I try to align a text from a line shows that alert bellow.

Alert!
Code: [Select]
Select object: ; error: bad argument type: numberp: nil
Anybody could help me please?

I think Lee Mac's is the author for this code.

Thank in advance
Fabricio

Code: [Select]
(defun c:rtr ( / a e i p s )
    (if (setq s (LM:ssget "\nSelect Text: " '("_:L" ((0 . "*TEXT")))))
        (progn
            (while
                (progn (setvar 'errno 0) (setq e (entsel))
                    (cond
                        (   (= 7 (getvar 'errno))
                            (princ "\nMissed, try again.")
                        )
                        (   (= 'ename (type (car e)))
                            (if
                                (vl-catch-all-error-p
                                    (setq p
                                        (vl-catch-all-apply 'vlax-curve-getclosestpointto
                                            (list (car e) (trans (cadr e) 1 0))
                                        )
                                    )
                                )
                                (princ "\nInvalid object selected.")
                            )
                        )
                    )
                )
            )
            (if (= 'ename (type (setq e (car e))))
                (progn
                    (setq a (angle '(0.0 0.0) (vlax-curve-getfirstderiv e (vlax-curve-getparamatpoint e p))))
                    (if (and (< (* 0.5 pi) a) (<= a (* 1.5 pi)))
                        (setq a (+ pi a))
                    )
                    (repeat (setq i (sslength s))
                        (setq e (entget (ssname s (setq i (1- i)))))
                        (entmod (subst (cons 50 a) (assoc 50 e) e))
                    )
                )
            )
        )
    )
    (princ)
)

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;;
;; Arguments:
;; msg    - selection prompt
;; params - list of ssget arguments

(defun LM:ssget ( msg params / sel )
    (princ msg)
    (setvar 'nomutt 1)
    (setq sel (vl-catch-all-apply 'ssget params))
    (setvar 'nomutt 0)
    (if (not (vl-catch-all-error-p sel)) sel)
)
(vl-load-com)
(princ)



Title: Re: Lisp to align Text from objects-help
Post by: Lee Mac on July 28, 2017, 08:01:16 AM
After a cursory review of the program, I don't see any issue with the code - therefore, could you please follow the first section of this tutorial (http://lee-mac.com/debugvlide.html#where) and post the expression which is highlighted when the program errors?
Title: Re: Lisp to align Text from objects-help
Post by: Fabricio28 on July 28, 2017, 08:51:38 AM
After a cursory review of the program, I don't see any issue with the code - therefore, could you please follow the first section of this tutorial (http://lee-mac.com/debugvlide.html#where) and post the expression which is highlighted when the program errors?

Hi Lee
How are you?

I've made the workflow about "Where did the Code Fail?".
After that step Debug » Last Break Source (Ctrl+F9). Showed this message.

Title: Re: Lisp to align Text from objects-help
Post by: ronjonp on July 28, 2017, 10:22:38 AM
Maybe try something like this:

Code - Auto/Visual Lisp: [Select]
  1. (defun _angleatpoint (ename pt / p2 param)
  2.            (setq p2 (vlax-curve-getclosestpointto ename pt))
  3.            (setq param (vlax-curve-getparamatpoint ename p2))
  4.       )
  5.     (angle '(0 0) (vlax-curve-getfirstderiv ename param))
  6.   )
  7. )
  8. ;; Usage in routine
  9. (if (and (= 'ename (type (setq e (car e)))) (setq a (_angleatpoint e p)))
  10.   (progn (if (and (< (* 0.5 pi) a) (<= a (* 1.5 pi)))
  11.            (setq a (+ pi a))
  12.          )
  13.          (repeat (setq i (sslength s))
  14.            (setq e (entget (ssname s (setq i (1- i)))))
  15.            (entmod (subst (cons 50 a) (assoc 50 e) e))
  16.          )
  17.   )
  18. )
Title: Re: Lisp to align Text from objects-help
Post by: Fabricio28 on July 28, 2017, 11:12:37 AM
Maybe try something like this:

Code - Auto/Visual Lisp: [Select]
  1. (defun _angleatpoint (ename pt / p2 param)
  2.            (setq p2 (vlax-curve-getclosestpointto ename pt))
  3.            (setq param (vlax-curve-getparamatpoint ename p2))
  4.       )
  5.     (angle '(0 0) (vlax-curve-getfirstderiv ename param))
  6.   )
  7. )
  8. ;; Usage in routine
  9. (if (and (= 'ename (type (setq e (car e)))) (setq a (_angleatpoint e p)))
  10.   (progn (if (and (< (* 0.5 pi) a) (<= a (* 1.5 pi)))
  11.            (setq a (+ pi a))
  12.          )
  13.          (repeat (setq i (sslength s))
  14.            (setq e (entget (ssname s (setq i (1- i)))))
  15.            (entmod (subst (cons 50 a) (assoc 50 e) e))
  16.          )
  17.   )
  18. )

Perfect ronjonp!
Thank you very much.

I've made some test and worked perfect now.

I really appreciate the help. :)

Fabricio
Title: Re: Lisp to align Text from objects-help
Post by: ronjonp on July 28, 2017, 12:10:26 PM
Glad to help :)
Title: Re: Lisp to align Text from objects-help
Post by: ahsattarian on September 18, 2021, 01:01:22 PM
Hello everyone

I had sometimes the same problem in sharp-bending splines.

After checking everything, I found out that the problem  :

Original Program  :

(setq pt (vlax-curve-getclosestpointto s po nil))
(setq di (vlax-curve-getdistatpoint obj pt))


Modified Program  :

(setq pt (vlax-curve-getclosestpointto s po nil))
(setq pt (vlax-curve-getclosestpointto s pt nil))
(setq di (vlax-curve-getdistatpoint obj pt))


The middle line doesn't seem to be necessary,  BUT It's Necessary !!

It is not logical, but it works  !!!