|
发表于 2022-1-25 06:20:37
|
显示全部楼层
谢谢楼主分享,请教下,这个LSP 能实现类似加工说明的自动注解输出么?
就是类似把加工信息添加到扩展数据里面,然后标注出图时自动读取?
类似以下程序思路(参考pressCAD)
(defun c:writexdata(/)
(setq the_ent_list(entget (car (entsel "\n 请选择元素: "))))
;;先判断是否已经有了日期
(setq cur_date_list(assoc -3 the_ent_list))
(if (null cur_date_list)
(progn
(setq cur_date(getstring "请输入日期(8位 如:20011201):"))
;以下注册扩展数名,数据名"MDRAW_DATA"相当于MicroDraw控件内的属性名称
(regapp "MDRAW_DATA")
(setq tem_list (cons '1000 cur_date))
(setq tem_list (list "MDRAW_DATA" tem_list '(1070 . 1)))
(setq tem_list (list -3 tem_list))
(setq exdata (list tem_list))
;(setq exdata '((-3
; ("MDRAW_DATA" (1000 . "20010101") (1070 . 1))
; ))
;)
(setq newent
(append the_ent_list exdata))
(entmod newent)
)
;;如果已经有了日期
(progn
(setq date_list1 (assoc -3 the_ent_list))
(setq date_list2 (car (cdr date_list1)))
(setq date_list (nth 1 date_list2))
(setq cur_date (cdr date_list))
(setq the_prompt(strcat "\n当前日期:" cur_date "修改为:"))
(setq new_date(getstring the_prompt))
(setq date_list20(subst new_date cur_date date_list2))
(setq date_list1(subst date_list20 date_list2 date_list1))
(setq date_list1 (cons -3 date_list1))
(setq the_ent_list (subst date_list1 (assoc -3 the_ent_list) the_ent_list))
(entmod the_ent_list)
)
)
)
;;从元素内读出扩展数据
(defun c:readxdata(/)
(setq sel_ent_list (entget (car (entsel " \n 请选择元素:")) (list "*")))
(setq ent_name(cdr (assoc 5 sel_ent_list)))
(setq ent_type (cdr (assoc 0 sel_ent_list)))
(princ)
(princ "元素类型是:")
(princ ent_type)
;(if (= ent_type "TRACE")
; (setq trace_name ent_name)
; (progn
; (princ "选择错误!")
; (princ)
; (exit)
; )
;)
(setq trace_list (entget (handent ent_name) (list "*")))
;(if(= trace_list nil)
; (progn
; (princ "没有扩展数据")
; (princ)
; (exit)
; )
;)
(setq cur_date "")
(setq date_list (assoc -3 trace_list))
(if (not (null date_list))
(progn
(setq date_list (car (cdr date_list)))
(setq date_list (nth 1 date_list))
(setq cur_date (cdr date_list))
(setq cur_date (strcat "[日]" cur_date))
)
;else
(progn
(princ "没有扩展数据")
(princ)
(exit)
)
)
(setq open_price (nth 2 (assoc 10 trace_list))) ;Get the open price
(setq close_price(nth 2 (assoc 12 trace_list))) ;Get the close price
(setq line_list (entget (entnext (handent trace_name)) (list "*")))
(setq high_price (nth 2 (assoc 10 line_list))) ;Get the low price
(setq low_price (nth 2 (assoc 11 line_list))) ;Get the high pice one day
(setq open_price (* open_price value_scale)
close_price(* close_price value_scale)
high_price (* high_price value_scale)
low_price(* low_price value_scale))
(setq str1 (strcat "[开]" (rtos (+ open_price 1) 2 2)))
(setq str2 (strcat "[高]" (rtos high_price 2 2)))
(setq str3 (strcat "[低]" (rtos low_price 2 2)))
(setq str4 (strcat "[收]" (rtos (- close_price 1) 2 2)))
(setq str_all (strcat "<<>>" cur_date str1 str2 str3 str4))
(setvar "modemacro" str_all)
)
复制代码
虽然MicroDraw和Acad是两个完全不同的CAD平台,但提供了兼容Acad内扩展数据的方法;
在 acad内命令行键入 (load "c:\\op_xdata.lsp") 加载lsp程序 【注:lsp文件在c盘上,文件名称是 op_xdata.lsp】
写入扩展数据
command:writedata [回车]
读取扩展数据
command:readdata [回车]
以下我们要讨论的是如何在MicroDra控件环境内读取这些扩展属性:
"(-3 " 表示扩展数据???
((-1 . <图元名: 7efc6f58>) (0 . "TRACE") (330 . <图元名: 7efb9cd0>) (5 .
"2DDB") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "KLRED") (100 .
"AcDbTrace") (10 22556.0 9250.0 0.0) (11 22564.0 9250.0 0.0) (12 22556.0 9319.0
0.0) (13 22564.0 9319.0 0.0) (39 . 0.0) (210 0.0 0.0 1.0) (-3 ("MDRAW_DATA"
(1000 . "20011201") (1070 . 1))))
|
|