欢迎来到Cadtutor
抛物线试验。lsp V1.2:对称选项:t/nil
V1.1:将子函数包装在C中:测试
(defun c:test (/ user p [b]symmetric[/b] [color="red"]*equation*[/color]) ; localize if no user prompt *OPTIONAL;due to the sub-function is global variable, so prefix [color="red"]hp:[/color] is just making it unique name to avoid conflict(defun [b]hp:graph[/b] (str i dist pt / X lst);;; hanhphuc 25.12.2014 merry Xmas (or cal (arxload "geomcal")) (if (and str i dist pt) (progn (setq X 0.0 ) ;_ end of setq (repeat (1+ (abs (fix (/ dist i)))) (setq lst (cons (list (+ (car pt) X) (+ (cadr pt) (cal str))) lst) X (+ X i) ) ;_ end of setq ) ;_ end of repeat (entmakex (vl-list* '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(70 . 0) (cons 90 (length lst)) (mapcar ''((x) (cons 10 (trans x 1 0))) lst) ) ;_ end of vl-list* ) ;_ end of entmakex ) ;_ end of progn ) ;_ end of if (princ) ) ;_ end of defun[b][color="red"](setq symmetric [color="blue"]t[/color])[/color][/b] ; [color="blue"]<--- t / nil : user setting v1.2[/color] (or *equation* (setq *equation* [color="red"]"[b]X^2[/b]"[/color])) ;[color="blue"]<-- default example[/color] [color="red"];*[u]OPTIONAL: un-commented after this paragraph which prompt for user input[/u];(setq user (getstring (strcat "\nKey your equation, Y= " *equation* " ? ")); *equation* (if (= user ""); *equation*; user; ) ;_ end of if; ) ;_ end of setq[/color] (if (setq p (getpoint "\nPick point.. "))(foreach x '([color="red"][b]0.5 -0.5[/b][/color]) ;[color="blue"] <-- increment[/color] ([b]hp:graph[/b] [b][color="red"] (if symmetric [color="gray"]; v1.2[/color](if (minusp x) ((lambda(str)(last (mapcar ''((a b) (setq str (vl-string-translate a b str))) '("+" "-" "?") '("?" "+" "-")) ) ;_ end of last ) *equation* ) *equation* ) ;_ end of if*equation*)[/color][/b] x [color="red"][b]50.0[/b][/color] ;[color="blue"] <-- Distance[/color] p) ) ) ;_ end of if (princ) ) ;_ end of defun