lisp编码帮助
大家好。。。我发现下面的lisp路由可以插入日期戳,并用一个简单的命令进行更新。这很接近我想要的,但不准确。以下是我想要更改的内容
a) 邮票是“2008年10月9日星期四下午3:16:18”的,我只想把它改成YY-MM-DD(如08-10-09)。
b) 保存时不会自动更新-我不知道这是否可行,但这将非常有用。
如果有人能帮我,我正在努力学习如何写这些愚蠢的代码,我很容易迷路。
这是代码本身
; 函数:makestamp:允许用户放置日期/时间戳。
; upstamp:自动更新现有的日期/时间戳。
;在AutoCAD命令提示下键入makestamp以运行,或键入upstamp以更新
(defun c:makestamp();在图形中创建新戳记
(setq pt(getpoint“\n点击一个点:”)
(setq curdate(menucmd“M=$(edtime,$(getvar,date),YY-MM-DD)”)
(setq对象(列表
(cons 0“文本”)
(cons 100“AcDbEntity”)
(cons 67 0)
(cons 410(getvar“ctab”);获取当前布局。
(cons 8“时间戳”);放在这个层上,用于在下一个lisp中识别以进行更新。不要改变!!!!
;每一次。或者在打印按钮上,在为这个lisp输入小命令之前
;可能需要为此向正确的文本层发出更改clayer。
(cons 100“AcDbText”)
(缺点10
(列表(car pt)(cadr pt)(caddr pt)
)
)
(cons 40(getvar“textsize”))
(cons 1 curdate)
(cons 50(*00(/pi 180)))
(cons 41 1.0)
(cons 51 0)
(cons 7(getvar“cmlstyle”);获取当前多行样式
(cons 71 0)
(cons 72 0)
(cons 100“AcDbText”)
(cons 73 0)
)
)
(entmake对象)
(普林斯)
)
(defun c:upstamp()
(setq curdate2(menucmd“M=$(edtime,$(getvar,date),YY-MM-DD)”)
(setq ssup(ssget“x”(列表(cons 8“TIMESTAMP”))));获取时间戳层上的唯一实体
(setq计数(sslength ssup));测试以查看时间戳层上有多少实体。如果count=0,则lisp出错。
(如果(=计数1)
(程序
(setq b1(entget(ssname ssup 0));如果只有一个实体存在,则lisp将更新为当前时间/日期
(setq c(assoc 1 b1))
(setq d(cons(c车)curdate2))
(setq b2(subst d c b1))
(entmod b2)
)
(progn;如果该层上有多个实体,则lisp会提醒用户。
(警报“错误:时间戳层上有多个实体。”)
(退出)
)
)
(普林斯)
)
谢谢 迪泽里,
试试这个修改过的代码。
; Function(s): makestamp: Allows user to place a date/time stamp.
; upstamp: Auto-updates an existing date/time stamp.
; type makestamp at the AutoCAD command prompt to run or upstamp to update
(defun c:makestamp () ;creates new stamp in drawing
(setq pt (getpoint "\nPick a point: "))
;(setq curdate (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)"))
(setq curdate (getvar "CDATE"))
(setq curdate (rtos curdate 2 4))
(setq year (substr curdate 3 2))
(setq month (substr curdate 5 2))
(setq day (substr curdate 7 2))
(setq curdate (strcat year "-" month "-" day))
(setq object (list
(cons 0 "TEXT")
(cons 100 "AcDbEntity")
(cons 67 0)
(cons 410 (getvar "ctab")) ;gets current layout.
(cons 8 "TIMESTAMP") ;puts on this layer, used to identify in next lisp for updating. Do NOT CHANGE!!!!
;every time. Or on your print button, right before you put the little command for this lisp, you
;may want to issue a change clayer to the correct text layer for this.
(cons 100 "AcDbText")
(cons 10
(list (car pt)(cadr pt)(caddr pt)
)
)
(cons 40 (getvar "textsize"))
(cons 1 curdate)
(cons 50 (* 00 (/ pi 180)))
(cons 41 1.0)
(cons 51 0)
(cons 7 (getvar "cmlstyle"));gets current multi-line style
(cons 71 0)
(cons 72 0)
(cons 100 "AcDbText")
(cons 73 0)
)
)
(entmake object)
(princ)
)
; upstamp: Auto-updates an existing date/time stamp.
(defun c:upstamp ()
;(setq curdate2 (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)"))
(setq curdate2 (getvar "CDATE"))
(setq curdate2 (rtos curdate2 2 4))
(setq year (substr curdate2 3 2))
(setq month (substr curdate2 5 2))
(setq day (substr curdate2 7 2))
(setq curdate2 (strcat year "-" month "-" day))
(setq ssup (ssget "x" (list (cons 8 "TIMESTAMP")))) ;gets the only entity on the TIMESTAMP layer
(setq count (sslength ssup)) ;test to see how many entities are on the TIMESTAMP layer. If count = 0, then lisp errors out.
(if (= count 1)
(progn
(setq b1 (entget (ssname ssup 0))) ;if only one entity exist then the lisp updates the to the current time/date
(setq c (assoc 1 b1))
(setq d (cons (car c) curdate2))
(setq b2 (subst d c b1))
(entmod b2)
)
(progn ;if there is more than one entity on that layer, then lisp alerts user.
(alert "ERROR: You have more than one entity on the TIMESTAMP layer.")
(quit)
)
)
(princ)
)
您可以通过添加以下行来稍微修改upstamp代码:
(命令“.CLOSE”)
在最后的(普林斯)之前。
然后,我建议通过更改行来重命名upstamp例程:
(defun c:upstamp()
例如:
(defun c:uclose()
或者你想要的任何东西。因此,要更新戳记并关闭,您需要在命令行中键入UCLOSE。 谢谢你的代码工作。。。 不客气。很高兴它对你有用。 您知道如何更改代码,使其在每次保存图形时都发生更改吗?
另外,你能解释一下你改变了什么,这样我就可以试着弄明白了。。。。我真的希望有时间能够自己编写和编辑这些例程
我有点理解结束语,但在保存时需要它,因为我需要它显示保存时的新日期。然后我可以打印出新的日期。 我很抱歉。在重读了你的第一篇文章后,我发现我错误地认为你想要更新邮票并关闭。在绘图时更新和保存应该不是问题,但我有一两天的时间不足。我会尽快回复,并做出解释。实际上,按照我介绍的使用CLOSE命令的过程,除了替换QSAVE外,应该在更新例程中最后一个(princ)之前的:(command.QSAVE)中工作。无论如何,我会再打给你。 好的,下面是代码,保存添加到upstamp,并添加一些注释来描述更改/添加的代码。请随时提问。如果您真的想学习Autolisp,有关函数和语法的基本信息包含在帮助文件中,但您可能希望在web上查找教程和代码示例。外面有很多信息。
; Function(s): makestamp: Allows user to place a date/time stamp.
; upstamp: Auto-updates an existing date/time stamp.
; type makestamp at the AutoCAD command prompt for new stamp or upstamp to update and save file.
(defun c:makestamp () ;creates new stamp in drawing
(setq pt (getpoint "\nPick a point: "))
;(setq curdate (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)")) ; commented out
; Next section gets the current date from the system, converts it to a string
; and defines substrings for the year, month and day.
(setq curdate (getvar "CDATE"))
(setq curdate (rtos curdate 2 4))
(setq year (substr curdate 3 2))
(setq month (substr curdate 5 2))
(setq day (substr curdate 7 2))
; Next line concatenates five substrings into the date format YY-MM-DD
(setq curdate (strcat year "-" month "-" day))
(setq object (list
(cons 0 "TEXT")
(cons 100 "AcDbEntity")
(cons 67 0)
(cons 410 (getvar "ctab")) ; gets current layout.
(cons 8 "TIMESTAMP") ; puts on this layer, used to identify in next lisp for updating. Do NOT CHANGE!!!!
; every time. Or on your print button, right before you put the little command for this lisp, you
; may want to issue a change clayer to the correct text layer for this.
(cons 100 "AcDbText")
(cons 10
(list (car pt)(cadr pt)(caddr pt)
)
)
(cons 40 (getvar "textsize"))
(cons 1 curdate)
(cons 50 (* 00 (/ pi 180)))
(cons 41 1.0)
(cons 51 0)
(cons 7 (getvar "cmlstyle")) ; gets current multi-line style
(cons 71 0)
(cons 72 0)
(cons 100 "AcDbText")
(cons 73 0)
)
)
(entmake object)
(princ)
)
; upstamp: Auto-updates an existing date/time stamp.
(defun c:upstamp ()
;(setq curdate2 (menucmd "M=$(edtime, $(getvar,date),YY-MM-DD)")) - commented out
; Next section gets the current date from the system, converts it to a string
; and defines substrings for the year, month and day.
(setq curdate2 (getvar "CDATE"))
(setq curdate2 (rtos curdate2 2 4))
(setq year (substr curdate2 3 2))
(setq month (substr curdate2 5 2))
(setq day (substr curdate2 7 2))
; Next line concatenates five substrings into the date format YY-MM-DD
(setq curdate2 (strcat year "-" month "-" day))
(setq ssup (ssget "x" (list (cons 8 "TIMESTAMP")))) ; gets the only entity on the TIMESTAMP layer
(setq count (sslength ssup)) ; test to see how many entities are on the TIMESTAMP layer. If count = 0, then lisp errors out.
(if (= count 1)
(progn
(setq b1 (entget (ssname ssup 0))) ; if only one entity exist then the lisp updates the to the current time/date
(setq c (assoc 1 b1))
(setq d (cons (car c) curdate2))
(setq b2 (subst d c b1))
(entmod b2)
)
(progn ; if there is more than one entity on that layer, then lisp alerts user.
(alert "ERROR: You have more than one entity on the TIMESTAMP layer.")
(quit)
)
)
(command ".QSAVE") ; quick save the file - asks for filename only if first save
(princ)
)
谢谢,我会找一些在线教程。。。
如果日期更改,我明天会通知您,但到目前为止,代码工作得很好。谢谢 我们只使用嵌入在图形中的字段的文本属性。可能性是无穷无尽的(见附图)。
使用ddedit命令单击左下角的一个属性,任何显示为灰色阴影的属性都是具有指定字段的属性。双击阴影属性,将打开“字段”对话框。使用字段类别查看哪些选项对您可用。
请注意,在“字段类别:日期和时间”、“字段名称:保存日期”下的“示例”框中提供了多个报告选项。
示例日期用户戳记。图纸
页:
[1]