runner214 Posted February 8, 2015 Posted February 8, 2015 (edited) I currently do a cut and paste from results when labeling a pipe run. I compiled a simple program from bits and pieces and multiple website references. I am now at a point where I need help with placing my text results from lisp to offset above midpoint of selected line. Any help is appreciated ;; label_run.lsp ;; lisp commands used referenced at: cadtutor.com, jefferypsanders.com, afralisp.net, ronleigh.com, lee-mac.com ;; Credits - Noted Assistance: hanhphuc, ymg ;; Objective: ;; User To Pick By Line Or Two Points From Screen To Retrieve Distance(d) With Length Rounded Off And Compute Slope Percentage Of Selection ;; To Be Used For: ;; 1) As An Inquiry - For Display Only ;; 2) With Option To Paste Results Above Selected Line As Label ;; Wish List Add Ons ;; 1) Possible Pipe Size And Material Add To String ;; 2) Use Leader If Text Exceeds line ;; ;;**************************************************************************************;; (defun C:label_run ( / *error* a1 a2 el e2 x1 y1 z1 x2 y2 z2 d tx pt txsize rot kw); Defined Functions Used - (setq oldlayer (getvar "clayer")) (setq oldsnap (getvar "osmode")) ;; User Option: Select Two Points Or Line - To Retrieve Distance Between And (z) Elevation At Each Selected Point (initget 0 "Line") (setq a1 (getpoint "\nPoint or [Line] ")) (if (= a1 nil); If nil then select line (setq a1 "Line") ) ;; If line option selected then: (if (= a1 "Line") ; true (progn (setq el (ut-get-object "LINE" "\nSelect Line:")) (setq a1 (cdr (assoc 10 el))) (setq a2 (cdr (assoc 11 el))) ) ;; If point - pick point (progn (setq a2 (getpoint a1 "\nSelect second point: ")) ) ) (if (= a2 nil) (exit)); line option selected ;get z value of points (setq x1 (car a1) y1 (cadr a1) z1 (caddr a1) x2 (car a2) y2 (cadr a2) z2 (caddr a2) ) ;; Determine slope percentage - (if (> (abs (- z1 z2)) 0.1) (setq s1 "%" a1 (subst 0.0 z1 a1) a2 (subst 0.0 z2 a2) d (distance a1 a2); Get Distance / Length Of Line slp (/ (- z2 z1) d); Formula For Slope: Z Value Point(1) Minus Z Value Point(2) (can Be Opposite 2-1) Divided By Length Of Line ) (setq s1 "%"; Determine Percent d (distance a1 a2) slp (/ (- y2 y1) d) ) ) (setq slp (* slp 1.000)) ;; Make Angle Readable ;credit to ymg (defun MakeReadable (a) (setq a (rem (+ a pi pi) (+ pi pi))) (rem (if (< (* pi 0.5) a (* pi 1.5)) (+ a pi) a ) ;_ end of if (+ pi pi) ) ;_ end of rem ) ;_ end of defun ;; Results Displayed On Screen (terpri) (princ (setq tx ( strcat (rtos d 2 0)" LF @ " (rtos slp 2 2) s1 " Slope"))) ;; Option To Paste Results In Drawing offset Midpoint Above Line From Display (initget "Yes No") (setq kw (getkword "\nPlace Above Line? [Yes/No] :")) (if (= kw "Yes") (progn (setq txsize (getvar 'textsize) pt (polar (apply 'mapcar (cons ''((a b) (* 0.5 (+ a b))) (list a1 a2))) (+ rot (/ pi 2.)) (* txsize 3.0) ) ;_ end of polar ) ;_ end of setq (entmake (list '(0 . "TEXT") '(72 . 1) ; justify (cons 1 tx) (cons 10 pt) (cons 11 pt) ; justify (cons 40 txsize) (cons 50 (MakeReadable (apply 'angle lst))) ) ; list ) ;entmake ) ;_ end of progn ) ;_ end of if ;;;; NOTED ERROR AT THIS POINT ;;;; ; error: bad argument type: numberp: nil ;; ERROR RESEARCH: A function requiring an integer argument has been passed an argument of incorrect data type with the value noted in the error message. (princ) ) (princ) ;; To Reset Original Varibles - End (setq olderr *error*) (setvar "osmode" 11) (princ) Edited February 8, 2015 by runner214 Corrected Suggestions Quote
hanhphuc Posted February 8, 2015 Posted February 8, 2015 (edited) I am now at a point where I need help with placing my text results from lisp to offset above midpoint of selected line. Any help is appreciated hi runner214 try this old thread does it help? suggestion: ;; label_run.lsp ;; lisp commands used referenced at: cadtutor.com, jefferypsanders.com, afralisp.net, ronleigh.com, lee-mac.com ;; Credits - Noted Assistance: hanhphuc, ymg ;; Objective: ;; User To Pick By Line Or Two Points From Screen To Retrieve Distance(d) With Length Rounded Off And Compute Slope Percentage Of Selection ;; To Be Used For: ;; 1) As An Inquiry - For Display Only ;; 2) With Option To Paste Results Above Selected Line As Label ;; Wish List Add Ons ;; 1) Possible Pipe Size And Material Add To String ;; 2) Use Leader If Text Exceeds line ;; ;;**************************************************************************************;; ;; Make Angle Readable ;credit to ymg (defun MakeReadable (a) (setq a (rem (+ a pi pi) (+ pi pi))) (rem (if (< (* pi 0.5) a (* pi 1.5)) (+ a pi) a ) ;_ end of if (+ pi pi) ) ;_ end of rem ) ;_ end of defun (defun C:label_run ( / *error* a1 a2 el e2 x1 y1 z1 x2 y2 z2 d tx pt txsize rot kw [color="red"]lst[/color] ); Defined Functions Used - (setq oldlayer (getvar "clayer")) (setq oldsnap (getvar "osmode")) ;; User Option: Select Two Points Or Line - To Retrieve Distance Between And (z) Elevation At Each Selected Point (initget 0 "Line") (setq a1 (getpoint "\nPoint or [Line] ")) (if (= a1 nil); If nil then select line (setq a1 "Line") ) ;; If line option selected then: (if (= a1 "Line") ; true (progn (setq el (ut-get-object "LINE" "\nSelect Line:")) (setq a1 (cdr (assoc 10 el))) (setq a2 (cdr (assoc 11 el))) ) ;; If point - pick point (progn (setq a2 (getpoint a1 "\nSelect second point: ")) ) ) (if (= a2 nil) (exit)); line option selected ;get z value of points (setq x1 (car a1) y1 (cadr a1) z1 (caddr a1) x2 (car a2) y2 (cadr a2) z2 (caddr a2) ) ;; Determine slope percentage - (if (> (abs (- z1 z2)) 0.1) (setq s1 "%" a1 (subst 0.0 z1 a1) a2 (subst 0.0 z2 a2) d (distance a1 a2); Get Distance / Length Of Line slp (/ (- z2 z1) d); Formula For Slope: Z Value Point(1) Minus Z Value Point(2) (can Be Opposite 2-1) Divided By Length Of Line ) (setq s1 "%"; Determine Percent d (distance a1 a2) slp (/ (- y2 y1) d) ) ) (setq slp (* slp 1.000)) ;; Results Displayed On Screen (terpri) (princ (setq tx ( strcat (rtos d 2 0)" LF @ " (rtos slp 2 2) s1 " Slope"))) ;; Option To Paste Results In Drawing offset Midpoint Above Line From Display (initget "Yes No") (setq kw (getkword "\nPlace Above Line? [Yes/No] :")) (if (= kw "Yes") (progn (setq txsize (getvar 'textsize) [color="red"]lst (list a1 a2) rot (MakeReadable (apply 'angle lst))[/color] pt (polar (apply 'mapcar (cons ''((a b) (* 0.5 (+ a b)))[color="red"] lst[/color])) (+ rot (/ pi 2.)) (* txsize 3.0) ) ;_ end of polar ) ;_ end of setq (entmake (list '(0 . "TEXT") '(72 . 1) ; justify (cons 1 tx) (cons 10 pt) (cons 11 pt) ; justify (cons 40 txsize) (cons 50 [color="red"]rot[/color]) ) ; list ) ;entmake ) ;_ end of progn ) ;_ end of if (princ) ) (princ) ;; To Reset Original Varibles - End (setq olderr *error*) (setvar "osmode" 11) (princ) HTH Edited February 9, 2015 by hanhphuc suggested code updated. rot value not setq Quote
runner214 Posted February 8, 2015 Author Posted February 8, 2015 (edited) Thanks hanhphuc, will check it out in the morning I am satisfied with the results from my lisp results. - ie: 27 LF @ .02% SLOPE -. I am just unsure how to take the results and place them offsetting the midpoint of my selected line. I am trying to use the lisp as both a tool for inquiry (display) as well as having a Y or N option to place the text results over the line if i wish to label it.. Edited February 8, 2015 by runner214 added to reply Quote
runner214 Posted February 8, 2015 Author Posted February 8, 2015 hanhphuc Inserted your suggested changes. Incurred an error on the YES response and received an error. The NO option closes without any error. I then ran the Visual Lips editor program as per Lee Mac's tutorial with the following result concerning the error: LOG Watch ............... *LAST-VALUE* = (+ ROT (/ PI 2.0)) = (SETQ DEC 2) = 2 12 = 12 ............... Updated Code: ;; label_run.lsp ;; lisp commands used referenced at: cadtutor.com, jefferypsanders.com, afralisp.net, ronleigh.com, lee-mac.com ;; Credits - Noted Assistance: hanhphuc, ymg ;; Debugging ;; Current - 020815 ;; Objective: ;; User To Pick By Line Or Two Points From Screen To Retrieve Distance(d) With Length Rounded Off And Compute Slope Percentage Of Selection ;; To Be Used For: ;; 1) As An Inquiry - For Display Only ;; 2) With Option To Paste Results Above Selected Line As Label ;; Wish List Add Ons ;; 1) Possible Pipe Size And Material Add To String ;; 2) Use Leader If Text Exceeds line ;; ;;**************************************************************************************;; (defun C:label_run ( / *error* a1 a2 el e2 x1 y1 z1 x2 y2 z2 d tx pt txsize rot kw); Defined Functions Used - (setq oldlayer (getvar "clayer")) (setq oldsnap (getvar "osmode")) ;; User Option: Select Two Points Or Line - To Retrieve Distance Between And (z) Elevation At Each Selected Point (initget 0 "Line") (setq a1 (getpoint "\nPoint or [Line] ")) (if (= a1 nil); If nil then select line (setq a1 "Line") ) ;; If line option selected then: (if (= a1 "Line") ; true (progn (setq el (ut-get-object "LINE" "\nSelect Line:")) (setq a1 (cdr (assoc 10 el))) (setq a2 (cdr (assoc 11 el))) ) ;; If point - pick point (progn (setq a2 (getpoint a1 "\nSelect second point: ")) ) ) (if (= a2 nil) (exit)); line option selected ;get z value of points (setq x1 (car a1) y1 (cadr a1) z1 (caddr a1) x2 (car a2) y2 (cadr a2) z2 (caddr a2) ) ;; Determine slope percentage - (if (> (abs (- z1 z2)) 0.1) (setq s1 "%" a1 (subst 0.0 z1 a1) a2 (subst 0.0 z2 a2) d (distance a1 a2); Get Distance / Length Of Line slp (/ (- z2 z1) d); Formula For Slope: Z Value Point(1) Minus Z Value Point(2) (can Be Opposite 2-1) Divided By Length Of Line ) (setq s1 "%"; Determine Percent d (distance a1 a2) slp (/ (- y2 y1) d) ) ) (setq slp (* slp 1.000)) ;; Make Angle Readable ;credit to ymg (defun MakeReadable (a) (setq a (rem (+ a pi pi) (+ pi pi))) (rem (if (< (* pi 0.5) a (* pi 1.5)) (+ a pi) a ) ;_ end of if (+ pi pi) ) ;_ end of rem ) ;_ end of defun ;; Results Displayed On Screen (terpri) (princ (setq tx ( strcat (rtos d 2 0)" LF @ " (rtos slp 2 2) s1 " Slope"))) ;; Option To Paste Results In Drawing offset Midpoint Above Line From Display (initget "Yes No") (setq kw (getkword "\nPlace Above Line? [Yes/No] :")) (if (= kw "Yes") (progn (setq txsize (getvar 'textsize) pt (polar (apply 'mapcar (cons ''((a b) (* 0.5 (+ a b))) (list a1 a2))) (+ rot (/ pi 2.)) (* txsize 3.0) ) ;_ end of polar ) ;_ end of setq (entmake (list '(0 . "TEXT") '(72 . 1) ; justify (cons 1 tx) (cons 10 pt) (cons 11 pt) ; justify (cons 40 txsize) (cons 50 (MakeReadable (apply 'angle lst))) ) ; list ) ;entmake ) ;_ end of progn ) ;_ end of if ;;;; NOTED ERROR AT THIS POINT ;;;; ; error: bad argument type: numberp: nil ;; ERROR RESEARCH: A function requiring an integer argument has been passed an argument of incorrect data type with the value noted in the error message. (princ) ) (princ) ;; To Reset Original Varibles - End (setq olderr *error*) (setvar "osmode" 11) (princ) Any ideas on how to approach? Quote
hanhphuc Posted February 9, 2015 Posted February 9, 2015 ;;; NOTED ERROR AT THIS POINT ;;;; ; error: bad argument type: numberp: nil my apology, It was due to rot value not setq, lst (list a1 a2) [color="red"]rot[/color] (MakeReadable (apply 'angle lst)) code updated post#2 Quote
runner214 Posted February 9, 2015 Author Posted February 9, 2015 hanhphuc That did it! Thank you for your help. Have been reading all day with no success. Appreciate your time. Quote
hanhphuc Posted February 9, 2015 Posted February 9, 2015 hanhphuc That did it! Thank you for your help. Have been reading all day with no success. Appreciate your time. You are welcome runner214. Keep it up that's your afford Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.