记住用户输入以备将来使用
大家好,我有Lisp程序,效果很好,但我想把它提高到一个新的水平。我的LISP询问用户他们想要使用的半径。然后继续执行命令。
如果该命令稍后在同一会话中再次使用,我希望LISP能够记住用户的最后输入。很像offset命令;首次使用时,指定偏移量并完成命令。如果您在执行完20个其他命令后返回,它会记住最后使用的值并将其显示在括号中,用户只需点击回车键,不需要再次输入值。我希望这有意义。。。
有人能教我怎么做,或者至少给我指出正确的方向吗?
提前谢谢! 你能把你的代码贴在这里吗。。。所以我可以通过编辑给你看
示例:-
(setq a b)
(setq b (getint (strcat "\nSpecify Radius "
(if (not a)
": "
(strcat "<" (itoa a) ">: ")
)
)
)
)
(if (and (not b) a)
(setq b a)
)
(setvar“users1”offsetdistance)
(atof(getvar“users1”)) ;(setvar“users1”offsetdistance)
;(atof(getvar“users1”))
(定义c:mj()
(setq点1(getpoint“\n选择点
点2(getpoint pt1“\n选择点
距离(距离pt1 pt2))
;;拯救
(setvar“USERS1”(rtos ds 2 1))
(命令“move”(ssget)“pause(atof(getvar“users1”))
)
非常感谢你!我会试试这个。我想试着用你先给我的信息自己弄清楚。(这样我学得更好。)但如果我被卡住了,我会大胆地把它贴出来,然后再次联系你。
再次非常感谢! 本教程可能会有所帮助:使用默认选项进行提示。
谢谢你,李,这真是太棒了!!非常感谢! 我使用全局变量前缀场景来存储信息,以备将来使用:
前缀为gv_的所有变量仅对该会话是全局的
(setq xdef (if gv_xval gv_xval 100))
(setq x (getdist (strcat "\n X Axis Value <" (rtos xdef 2 2) ">: ")))
(or x (setq x xdef))
(setq gv_xval x)
要查看所有gv_变量的当前设置:
(defun c:gv (/ fl af)
(setq af (reverse (acad_strlsort (atoms-family 1))))
(foreach a af
(and (= "GV_"(strcase (substr a 1 3)))
(setq fl (cons (cons a (eval (read a))) fl))))
(textpage)
(princ "Global Variable Settings:")
(foreach a fl (terpri) (prin1 a))
(prin1))
一次设置10->20个gv_值并不罕见
-大卫
当然没问题:拇指支撑:
李·麦克,
很高兴你回复了这篇文章,因为我正在尝试修改你的Lisp程序。最初,用户要求我修改它,以便他可以指定半径。所以我为他这么做了。现在他想要我指定的附加功能。
我已经阅读了你发给我的链接(顺便说一句,这很好),我有一个问题,不确定我是否完全理解。它始终不会读取最后输入的值。
您将看到,我注释掉了我的原始更改(setq bDis(getreal“\n为跳转半径输入新值:”),它确实有效。
;;; JMPR.lsp
;;;
;;; Description
;;; Jumper will auto-create the radius jump for pipe crossings.
;;;
;;; Author: Lee Mac (CADTutor)
;;; Date: 03/25/10
;;;
;;; Revision: 1
;;; Revision Date: 10/30/15
;;; Description - Modified by David Prontnicki
;;; Added the ability to select your radius at the beginning of the command.
;;; Changed interface verbage
;;;
;;; Command: JMPR
;;; -----------------------------------------------------------------------------;
(defun c:jmpr (/ *error* A AENT B1 B2 BDIS BENT DOC ENT OV P1 P2 UFLAG VL O W)
;(setq bDis (getreal "\n Enter new value for Jump Radius: ")) ; Modified by David Prontnicki
(setq bDis
(cond
(
(getreal
(strcat "\n Enter new value for Jump Radius <"
(itoa
(setq bDis
(cond ( bDis ) (1) )
)
)
">: "
)
)
)
( bDis )
)
)
(defun *error* (msg)
(and uFlag (vla-EndUndoMark doc))
(and ov(mapcar (function setvar) vl ov))
(and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **"))))
(princ))
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl))
(setvar "PEDITACCEPT" 1)
(while (and (setq uFlag (not (vla-StartUndoMark doc)))
(mapcar (function setvar) (cdr vl) '(0 32))
(setq p1(getpoint "\nPick the crossing intersection: ")) ; Modified by David Prontnicki
(setq ent (entsel "\nSelect the line to break: "))) ; Modified by David Prontnicki
(setq p2 (osnap (cadr ent) "_nea")
b1 (polar p1 (setq a (angle p1 p2)) bDis)
b2 (polar p1 (+ pi a) bDis))
(setvar "OSMODE" 0)
(command "_.break" b1 b2)
(setq bEnt (entlast))
(if (> a (/ pi 2.))
(command "_.arc" b2 "_E" b1 "_A" 180.)
(command "_.arc" b1 "_E" b2 "_A" 180.))
(setq aEnt (entlast))
(if (eq "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (car ent))))))
(progn
(setq w (vla-get-ConstantWidth (setq o (vlax-ename->vla-object ent))))
(command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "")
(vla-put-ConstantWidth (vlax-ename->vla-object (entlast)) w)))
(setq uFlag (vla-EndUndoMark doc)))
(*error* nil)
(princ))
任何帮助都将不胜感激。提前谢谢你。
页:
[1]
2