jason_a Posted December 19, 2016 Posted December 19, 2016 Hello, I'm trying to create a lisp routine that will create top and side view rectangles based on the front view. I've attached an image for reference. I'd like to click two opposite corners of the white panel, and then the two green rectangles will be created with a thickness of 25.4. Is this possible? Thanks Quote
Grrr Posted December 19, 2016 Posted December 19, 2016 Hi, try this: [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / *error* p1 p2 right top lr lt main [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]defun *error* nil [b][color=NAVY]([/color][/b]redraw[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq p1 [b][color=GREEN]([/color][/b]getpoint [color=#2f4f4f]"\nSpecify bottom left corner <exit>: "[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq p2 [b][color=GREEN]([/color][/b]getcorner p1 [color=#2f4f4f]"\nSpecify top right corner <exit>: "[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq p1 [b][color=GREEN]([/color][/b]trans p1 1 0[b][color=GREEN])[/color][/b] p2 [b][color=GREEN]([/color][/b]trans p2 1 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq right [b][color=GREEN]([/color][/b]lambda [b][color=BLUE]([/color][/b]x[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]polar x 0. 25.4[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq top [b][color=GREEN]([/color][/b]lambda [b][color=BLUE]([/color][/b]x[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]polar x [b][color=RED]([/color][/b]/ PI 2[b][color=RED])[/color][/b] 25.4[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq lr [b][color=GREEN]([/color][/b]mapcar 'right [b][color=BLUE]([/color][/b]list p2 [b][color=RED]([/color][/b]list [b][color=PURPLE]([/color][/b]car p2[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cadr p1[b][color=PURPLE])[/color][/b] 0.[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq lt [b][color=GREEN]([/color][/b]mapcar 'top [b][color=BLUE]([/color][/b]list p2 [b][color=RED]([/color][/b]list [b][color=PURPLE]([/color][/b]car p1[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cadr p2[b][color=PURPLE])[/color][/b] 0.[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq lr [b][color=GREEN]([/color][/b]append [b][color=BLUE]([/color][/b]reverse [b][color=RED]([/color][/b]mapcar 'right lr[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] lr[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq lt [b][color=GREEN]([/color][/b]append [b][color=BLUE]([/color][/b]reverse [b][color=RED]([/color][/b]mapcar 'top lt[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] lt[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq main [b][color=GREEN]([/color][/b]list p1 [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]car p1[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cadr p2[b][color=RED])[/color][/b] 0.[b][color=BLUE])[/color][/b] p2 [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]car p2[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cadr p1[b][color=RED])[/color][/b] 0.[b][color=BLUE])[/color][/b] [b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]redraw[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]grvecs [b][color=BLUE]([/color][/b]cons -1 [b][color=RED]([/color][/b]apply 'append [b][color=PURPLE]([/color][/b]mapcar 'list main [b][color=TEAL]([/color][/b]cons [b][color=OLIVE]([/color][/b]last main [b][color=OLIVE])[/color][/b] main[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]LWPoly lr 1[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]LWPoly lt 1[b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]redraw[b][color=FUCHSIA])[/color][/b][b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] [color=#8b4513]; Lee Mac[/color] [b][color=BLACK]([/color][/b]defun LWPoly [b][color=FUCHSIA]([/color][/b]lst cls[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]entmakex [b][color=NAVY]([/color][/b]append [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"LWPOLYLINE"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 100 [color=#2f4f4f]"AcDbEntity"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 100 [color=#2f4f4f]"AcDbPolyline"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 90 [b][color=BLUE]([/color][/b]length lst[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 70 cls[b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]mapcar [b][color=GREEN]([/color][/b]function [b][color=BLUE]([/color][/b]lambda [b][color=RED]([/color][/b]p[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cons 10 p[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] lst[b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] Quote
jason_a Posted December 19, 2016 Author Posted December 19, 2016 Works perfectly, thank you very much! This is a big help, I appreciate it. Quote
BIGAL Posted December 20, 2016 Posted December 20, 2016 jason_a why would you not draw the rectang as part of this function ? 1 pt, L & W all done. Quote
jason_a Posted December 20, 2016 Author Posted December 20, 2016 I draft many orthographic views in my line of work on a daily basis and unfortunately, entering values would slow me down. Thanks for the suggestion though, it could come in handy elsewhere in my work flow. Quote
ReMark Posted December 20, 2016 Posted December 20, 2016 Maybe you should be working in 3D and generating your 2D views from the model. Quote
jason_a Posted December 20, 2016 Author Posted December 20, 2016 Hi, try this: [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / *error* p1 p2 right top lr lt main [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]defun *error* nil [b][color=NAVY]([/color][/b]redraw[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq p1 [b][color=GREEN]([/color][/b]getpoint [color=#2f4f4f]"\nSpecify bottom left corner <exit>: "[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq p2 [b][color=GREEN]([/color][/b]getcorner p1 [color=#2f4f4f]"\nSpecify top right corner <exit>: "[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]setq p1 [b][color=GREEN]([/color][/b]trans p1 1 0[b][color=GREEN])[/color][/b] p2 [b][color=GREEN]([/color][/b]trans p2 1 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq right [b][color=GREEN]([/color][/b]lambda [b][color=BLUE]([/color][/b]x[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]polar x 0. 25.4[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq top [b][color=GREEN]([/color][/b]lambda [b][color=BLUE]([/color][/b]x[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]polar x [b][color=RED]([/color][/b]/ PI 2[b][color=RED])[/color][/b] 25.4[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq lr [b][color=GREEN]([/color][/b]mapcar 'right [b][color=BLUE]([/color][/b]list p2 [b][color=RED]([/color][/b]list [b][color=PURPLE]([/color][/b]car p2[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cadr p1[b][color=PURPLE])[/color][/b] 0.[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq lt [b][color=GREEN]([/color][/b]mapcar 'top [b][color=BLUE]([/color][/b]list p2 [b][color=RED]([/color][/b]list [b][color=PURPLE]([/color][/b]car p1[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cadr p2[b][color=PURPLE])[/color][/b] 0.[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq lr [b][color=GREEN]([/color][/b]append [b][color=BLUE]([/color][/b]reverse [b][color=RED]([/color][/b]mapcar 'right lr[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] lr[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq lt [b][color=GREEN]([/color][/b]append [b][color=BLUE]([/color][/b]reverse [b][color=RED]([/color][/b]mapcar 'top lt[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] lt[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq main [b][color=GREEN]([/color][/b]list p1 [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]car p1[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cadr p2[b][color=RED])[/color][/b] 0.[b][color=BLUE])[/color][/b] p2 [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]car p2[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cadr p1[b][color=RED])[/color][/b] 0.[b][color=BLUE])[/color][/b] [b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]redraw[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]grvecs [b][color=BLUE]([/color][/b]cons -1 [b][color=RED]([/color][/b]apply 'append [b][color=PURPLE]([/color][/b]mapcar 'list main [b][color=TEAL]([/color][/b]cons [b][color=OLIVE]([/color][/b]last main [b][color=OLIVE])[/color][/b] main[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]LWPoly lr 1[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]LWPoly lt 1[b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]redraw[b][color=FUCHSIA])[/color][/b][b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] [color=#8b4513]; Lee Mac[/color] [b][color=BLACK]([/color][/b]defun LWPoly [b][color=FUCHSIA]([/color][/b]lst cls[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]entmakex [b][color=NAVY]([/color][/b]append [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"LWPOLYLINE"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 100 [color=#2f4f4f]"AcDbEntity"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 100 [color=#2f4f4f]"AcDbPolyline"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 90 [b][color=BLUE]([/color][/b]length lst[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]cons 70 cls[b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]mapcar [b][color=GREEN]([/color][/b]function [b][color=BLUE]([/color][/b]lambda [b][color=RED]([/color][/b]p[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]cons 10 p[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] lst[b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] Lastly, can the lisp routine be modified so as to allow the user to enter the thickness of the panel? It currently has a default value of 25.4 which i've applied to a button and is applicable for most of my work flow. But in the odd cases I need a different value, a second button which allows for user defined input would help as well. Quote
Grrr Posted December 20, 2016 Posted December 20, 2016 Lastly, can the lisp routine be modified so as to allow the user to enter the thickness of the panel? It currently has a default value of 25.4 which i've applied to a button and is applicable for most of my work flow. But in the odd cases I need a different value, a second button which allows for user defined input would help as well. Yup: (defun C:test ( / *error* p1 p2 n right top lr lt main ) (defun *error* nil (redraw) (princ)) (while (and (setq p1 (getpoint "\nSpecify bottom left corner <exit>: ")) (setq p2 (getcorner p1 "\nSpecify top right corner <exit>: ")) (not (initget (+ 2 4))) (or (setq n (getreal "\nSpecify thickness value <25.4>: ")) (setq n 25.4)) ) (and (setq p1 (trans p1 1 0) p2 (trans p2 1 0)) (setq right (lambda (x) (polar x 0. n))) (setq top (lambda (x) (polar x (/ PI 2) n))) (setq lr (mapcar 'right (list p2 (list (car p2) (cadr p1) 0.)))) (setq lt (mapcar 'top (list p2 (list (car p1) (cadr p2) 0.)))) (setq lr (append (reverse (mapcar 'right lr)) lr)) (setq lt (append (reverse (mapcar 'top lt)) lt)) (setq main (list p1 (list (car p1) (cadr p2) 0.) p2 (list (car p2) (cadr p1) 0.) )) (not (redraw)) (not (grvecs (cons -1 (apply 'append (mapcar 'list main (cons (last main ) main)))))) (mapcar '(lambda (x) (LWPoly x 1)) (list lr lt)) ) ) (redraw)(princ) ) Quote
Lee Mac Posted December 20, 2016 Posted December 20, 2016 (defun C:test ( / *error* p1 p2 n right top lr lt main ) (defun *error* nil (redraw) (princ)) (while (and (setq p1 (getpoint "\nSpecify bottom left corner <exit>: ")) (setq p2 (getcorner p1 "\nSpecify top right corner <exit>: ")) (not (initget (+ 2 4))) (or (setq n (getreal "\nSpecify thickness value <25.4>: ")) (setq n 25.4)) ) (and (setq p1 (trans p1 1 0) p2 (trans p2 1 0)) (setq right (lambda (x) (polar x 0. n))) (setq top (lambda (x) (polar x (/ PI 2) n))) (setq lr (mapcar 'right (list p2 (list (car p2) (cadr p1) 0.)))) (setq lt (mapcar 'top (list p2 (list (car p1) (cadr p2) 0.)))) (setq lr (append (reverse (mapcar 'right lr)) lr)) (setq lt (append (reverse (mapcar 'top lt)) lt)) (setq main (list p1 (list (car p1) (cadr p2) 0.) p2 (list (car p2) (cadr p1) 0.) )) (not (redraw)) (not (grvecs (cons -1 (apply 'append (mapcar 'list main (cons (last main ) main)))))) (mapcar '(lambda (x) (LWPoly x 1)) (list lr lt)) ) ) (redraw)(princ) ) I like your use of the 'right' & 'top' functions - I see that you have a good understanding of mapcar now However, note that the *error* function requires a single-argument - the following will return a 'too many arguments' error if an error is encountered: (defun *error* nil (redraw) (princ)) Quote
Lee Mac Posted December 20, 2016 Posted December 20, 2016 FWIW, here is another version which will allow the user to pick the rectangle corners in any order, and will account for any UCS (assuming the UCS axes are parallel to the rectangle): ([color=BLUE]defun[/color] c:rprof ( [color=BLUE]/[/color] fn1 fn2 pt1 pt2 rgt thk tmp top ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] pt1 ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify first corner: "[/color])) ([color=BLUE]setq[/color] pt2 (([color=BLUE]if[/color] ([color=BLUE]zerop[/color] ([color=BLUE]getvar[/color] 'worlducs)) [color=BLUE]getpoint[/color] [color=BLUE]getcorner[/color]) pt1 [color=MAROON]"\nSpecify opposite corner: "[/color])) ) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] thk ([color=BLUE]cond[/color] (([color=BLUE]getdist[/color] [color=MAROON]"\nSpecify thickness <25.4>: "[/color])) (25.4)) fn1 ([color=BLUE]lambda[/color] ( x ) ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] x ([color=BLUE]list[/color] 0 thk 0))) fn2 ([color=BLUE]lambda[/color] ( x ) ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] x ([color=BLUE]list[/color] thk 0 0))) tmp ([color=BLUE]mapcar[/color] '[color=BLUE]max[/color] pt1 pt2) pt1 ([color=BLUE]mapcar[/color] '[color=BLUE]min[/color] pt1 pt2) pt2 tmp top ([color=BLUE]mapcar[/color] 'fn1 ([color=BLUE]list[/color] ([color=BLUE]cons[/color] ([color=BLUE]car[/color] pt1) ([color=BLUE]cdr[/color] pt2)) pt2)) rgt ([color=BLUE]mapcar[/color] 'fn2 ([color=BLUE]list[/color] ([color=BLUE]cons[/color] ([color=BLUE]car[/color] pt2) ([color=BLUE]cdr[/color] pt1)) pt2)) ) (myrectangle ([color=BLUE]append[/color] top ([color=BLUE]reverse[/color] ([color=BLUE]mapcar[/color] 'fn1 top)))) (myrectangle ([color=BLUE]append[/color] rgt ([color=BLUE]reverse[/color] ([color=BLUE]mapcar[/color] 'fn2 rgt)))) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] myrectangle ( lst ) ( ([color=BLUE]lambda[/color] ( ocs ) ([color=BLUE]entmake[/color] ([color=BLUE]append[/color] '( (000 . [color=MAROON]"LWPOLYLINE"[/color]) (100 . [color=MAROON]"AcDbEntity"[/color]) (100 . [color=MAROON]"AcDbPolyline"[/color]) (090 . 4) (070 . 1) ) ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 038 ([color=BLUE]caddr[/color] ([color=BLUE]trans[/color] ([color=BLUE]car[/color] lst) 1 ocs)))) ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]cons[/color] 10 ([color=BLUE]trans[/color] x 1 ocs))) lst) ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 210 ocs)) ) ) ) ([color=BLUE]trans[/color] '(0 0 1) 1 0 [color=BLUE]t[/color]) ) ) ([color=BLUE]princ[/color]) Quote
Grrr Posted December 20, 2016 Posted December 20, 2016 I like your use of the 'right' & 'top' functions - I see that you have a good understanding of mapcar now However, note that the *error* function requires a single-argument - the following will return a 'too many arguments' error if an error is encountered: (defun *error* nil (redraw) (princ)) Thanks Lee! I actually tested the performance, via pasting the code into the console, haven't recieved this error, actually no error nor prompt/break by VLIDE at all, when I used: *error* nil But when I provided an argument: *error* (m) the console did break with error (and my 'break on error' option is always checked). About mapcar.. well I started often to practice with list manipulating. (The only drawback is that most of us that write codes, aren't matematicians - which could reveal more potential to the geometrical tasks (obviously doesn't applies to you!)). FWIW, here is another version which will allow the user to pick the rectangle corners in any order, and will account for any UCS (assuming the UCS axes are parallel to the rectangle): This is way better, and its a good thing that you stay in shape by practicing! Offtopic: I had some (interesting for me) question here, hope you don't mind answering (if/when you have free time). Quote
Lee Mac Posted December 20, 2016 Posted December 20, 2016 I actually tested the performance, via pasting the code into the console, haven't recieved this error, actually no error nor prompt/break by VLIDE at all, when I used: *error* nil But when I provided an argument: *error* (m) the console did break with error (and my 'break on error' option is always checked). If you are evaluating the expressions exactly as shown in your post, then indeed, you will not receive an error for the first expression, as this will merely return a pointer to the function definition for the *error* symbol, and nil. Whereas the second expression will return the pointer and then attempt to evaluate the symbol 'm' as a function (which will obviously error if 'm' is not defined). However, neither of these tests are evaluating the *error* function - observe the following: Command: (defun foo ( / *error* ) (defun *error* nil (princ)) (/ 1 0)) FOO Command: (foo) too many arguments Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ m) (princ)) (/ 1 0)) FOO Command: (foo) divide by zero This is way better, and its a good thing that you stay in shape by practicing! Thanks - I wish I could contribute to the forum and equally, update my site more often, but unfortunately I don't have as much spare time to participate. Quote
Grrr Posted December 21, 2016 Posted December 21, 2016 However, neither of these tests are evaluating the *error* function - observe the following: Command: (defun foo ( / *error* ) (defun *error* nil (princ)) (/ 1 0)) FOO Command: (foo) too many arguments Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ m) (princ)) (/ 1 0)) FOO Command: (foo) divide by zero Lee, actually in the second code the *error* did evaluate (it printed the m symbol), see by adding custom prompting message: Command: (defun foo ( / *error* ) (defun *error* nil (princ "\nError is evaluated.")(princ)) (/ 1 0)) FOO Command: (foo) too many arguments Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ "\nError is evaluated.")(princ m) (princ)) (/ 1 0)) FOO Command: (foo) Error is evaluated.divide by zero Forcing *error* to evaluate (like you do, when you use dialogs on-the-fly): Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ "\nError is evaluated.")(princ m) (princ)) (/ 1 1) (*error* nil)) FOO Command: (foo) Error is evaluated.nil No error(s), no *error* evaluations: Command: (defun foo ( / *error* ) (defun *error* ( m ) (princ "\nError is evaluated.")(princ m) (princ)) (/ 1 1)) FOO Command: (foo) 1 Thanks - I wish I could contribute to the forum and equally, update my site more often, but unfortunately I don't have as much spare time to participate. Its noticeable when you are not around, but having some work is a good thing, right? Quote
Lee Mac Posted December 21, 2016 Posted December 21, 2016 Lee, actually in the second code the *error* did evaluate (it printed the m symbol), see by adding custom prompting message From your post, I understood that you were typing the expressions: *error* nil *error* (m) directly at the VLIDE console - hence my earlier clarification. But for completeness: the *error* function definition always requires a single string-valued argument (the error message), which is supplied automatically by the interpreter when an error is encountered. Quote
Grrr Posted December 21, 2016 Posted December 21, 2016 From your post, I understood that you were typing the expressions:*error* nil *error* (m) directly at the VLIDE console - hence my earlier clarification. No no, I actualy ment that when no argument is provided (m) the *error* is not being evaluated and perhaps VLIDE stays silent when an error occurs, sorry for the misunderstanding. I.e.: _$ (defun foo ( / *error* ) (defun *error* nil (princ "\nError is evaluated.")(princ)) (/ 1 0)) FOO _$ (foo) _$ (foo) _$ (foo) _$ (defun foo ( / *error* ) (defun *error* (m) (princ "\nError is evaluated.")(princ)) (/ 1 0)) FOO _$ (foo) Error is evaluated. _1$ (foo) _$ (foo) Error is evaluated. _1$ Quote
Lee Mac Posted December 21, 2016 Posted December 21, 2016 No no, I actualy ment that when no argument is provided (m) the *error* is not being evaluated and perhaps VLIDE stays silent when an error occurs, sorry for the misunderstanding. I think there is some confusion - By defining the *error* function as: (defun *error* nil (princ "\nError is evaluated.")(princ)) It is not that you are not supplying the function with an argument during evaluation, but rather that the function cannot be evaluated with an argument. You will not receive an error in the Visual LISP IDE, as no error handler can be evaluated: you have redefined the in-built error handler by defining a local *error* function, but this local *error* function cannot be evaluated and so the error has nowhere to go. I'm actually surprised that the command-line history even reports 'too many arguments', but this is coming from somewhere other than the in-built error handler as the message is not prefixed by the typical "; error:". Quote
Grrr Posted December 21, 2016 Posted December 21, 2016 You will not receive an error in the Visual LISP IDE, as no error handler can be evaluated: you have redefined the in-built error handler by defining a local *error* function, but this local *error* function cannot be evaluated and so the error has nowhere to go. Sounds interesting, about discovering something like a vl-catch-all-apply behaviour. I'm actually surprised that the command-line history even reports 'too many arguments', but this is coming from somewhere other than the in-built error handler as the message is not prefixed by the typical "; error:". There might be a slight difference, whenever this function is runned in VLIDE's console vs the command prompt: _$ (foo) _$ Command: (foo) too many arguments Looks like the command prompt is trying to pass the error message to the *error* function, thats why I'm getting that too many arguments error, Similarly to this: _$ (defun something nil (princ "\nEvaluating!")(princ)) SOMETHING _$ (something) Evaluating! _$ (something nil) Error: too many arguments _1$ 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.