请大神优化公差标注程序
程序目前能达到功能要求,因为是用 COMMAND 实线 所以命令栏有该提示不想让命令栏出现这些提示,还有其他函数能达到要求吗?
红色区域的代码需要优化......
以下是源码:
**********************************************************************************
**********************************************************************************
;;快速设置公差
(defun c:gc()
**********************************************************************************************
;;读取参数文件信息
(setq TKK_text (open (findfile "GC.dat") "r") ;打开读取文件 "r"代表读取
%sk1 (read-line TKK_text) ;读取正公差
%sk2 (read-line TKK_text) ;读取负公差
%sk3 (read-line TKK_text) ;读取对称公差比例
%sk4 (read-line TKK_text) ;读取极限公差比例
)
(close TKK_text ) ;关闭文件
**********************************************************************************************
(setq fname(vl-filename-mktemp "GC.dcl") f (open fname "w"))
(write-line "zhuc:dialog {label=\"快速公差 @ JAYCHOU\";" f)
(write-line ":boxed_column {label=\"公差值设置\" ;" f) ;; 分行符
(write-line ":edit_box{label=\"正公差 +\";key=\"e01\";edit_width=6;}" f)
(write-line ":edit_box{label=\"负公差 -\";key=\"e02\";edit_width=6;}}" f)
(write-line ":boxed_column {label=\"公差比例设置\" ;" f)
(write-line ":edit_box{label=\"对称公差标注比例 \";key=\"e03\";edit_width=6;}" f)
(write-line ":edit_box{label=\"极限公差标注比例 \";key=\"e04\";edit_width=6;}}" f)
(write-line ":row{:button {label=\"确定\";key=\"e05\";is_default=true;}" f)
(write-line " :button {label=\"退出\";is_cancel=true;}}}" f)
(close f)
(new_dialog "zhuc" (setq dcl_re (load_dialog fname)))
(set_tile "e01" %sk1) ;;正公差
(set_tile "e02" %sk2) ;;负公差
(set_tile "e03" %sk3) ;;对称公差比例
(set_tile "e04" %sk4) ;;极限公差比例
(mode_tile "e01"2 )
(action_tile "e01" "(setq %sk1 (get_tile \"e01\"))") ;;正公差
(action_tile "e02" "(setq %sk2 (get_tile \"e02\"))") ;;负公差
(action_tile "e03" "(setq %sk3 (get_tile \"e03\"))") ;;对称公差比例
(action_tile "e04" "(setq %sk4 (get_tile \"e04\"))") ;;极限公差比例
(if (= (start_dialog) 1)
(progn
;; (vl-registry-write "HKEY_CURRENT_USER\\SOFTWARE\\Autodesk\\AutoCAD" "+gc" %sk1)
;; (vl-registry-write "HKEY_CURRENT_USER\\SOFTWARE\\Autodesk\\AutoCAD" "-gc" %sk2)
**********************************************************************************************
;;写入参数文件信息
(SETQ TKK_text (OPEN (findfile "GC.dat") "W"));打开读取文件
(close TKK_text)
(setq TKK_text (open (findfile "GC.dat") "a"))
(write-line%sk1 TKK_text) ;写入正公差
(write-line%sk2 TKK_text) ;写入负公差
(write-line%sk3 TKK_text) ;写入对称公差比例
(write-line%sk4 TKK_text) ;写入极限公差比例
(close TKK_text ) ;关闭文件
**********************************************************************************************
(c:gcc)))
(unload_dialog dcl_re)
(vl-file-delete fname)
(princ)
)
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
**********************************************************************************************
;;设置公差
(defun c:gcc()
**********************************************************************************************
;;读取参数文件信息
(setq TKK_text (open (findfile "GC.dat") "r") ;打开读取文件 "r"代表读取
%sk1 (read-line TKK_text) ;读取正公差
%sk2 (read-line TKK_text) ;读取负公差
%sk3 (read-line TKK_text) ;读取对称公差比例
%sk4 (read-line TKK_text) ;读取极限公差比例
)
(close TKK_text ) ;关闭文件
**********************************************************************************************
(princ "\n命令: 选择标注尺寸:")
(setq n (atof %sk1)) ;;将字符串转换为数字
(setq m (atof %sk2)) ;;将字符串转换为数字
(setq bl1 (atof %sk3)) ;;将字符串转换为数字
(setq bl2 (atof %sk4)) ;;将字符串转换为数字
(setq k 0)
(while (<= k 5)
(setq a (fix (* (EXPT 10 (- 5 K)) n)))
(setq b (* 10 (fix (* (expt 10 (- 4 k)) n))))
(setq k1 (- 5 k))
(IF (= a b)
(SETQ K (+ K 1))
(setq K 6)
)
)
(setq k 0)
(while (<= k 5)
(setq a (fix (* (EXPT 10 (- 5 K)) M)))
(setq b (* 10 (fix (* (expt 10 (- 4 K)) M))))
(SETQ K2 (- 5 k))
(IF (= a b)
(SETQ K (+ K 1))
(setq K 6)
)
)
(setQ d2 (max K1 K2))
(if (= n m)
(setq c bl1) ;;对称公差比例
(setq c bl2) ;;极限公差比例
)
(if (and (= n 0) (= m 0))
(COMMAND "_DIMOVERRIDE" "dimtol" "off" "")
(while (setq ss (ssget ":S" '((0 . "DIMENSION"))))
(COMMAND "_DIMOVERRIDE" "DIMTP" n "DIMTM"
M "DIMTOL" "ON" "DIMTFAC" c
"DIMTDEC" D2 "DIMTZIN" 8""SS""
)
))
**********************************************************************************
;;中间这段代码也可以写公差,但是不能调整公差精度和大小比例
;; (defun vla-ssname (ss index)
;; (vlax-ename->vla-object (ssname ss index))
;; )
;;(while (setq ss (ssget ":S" '((0 . "DIMENSION"))))
;; (repeat (setq i (sslength ss))
;; (setq vobj (vla-ssname ss (setq i (1- i))))
;; (vla-put-ToleranceDisplay vobj acTolDeviation)
;; (vla-put-ToleranceUpperLimit vobj %sk1)
;; (vla-put-ToleranceLowerLimit vobj %sk2)
;; )
;; )
;;中间这段代码也可以写公差,但是不能调整公差精度和大小比例
**********************************************************************************
(c:gcc)
(princ)
)
**********************************************************************************
**********************************************************************************
页:
[1]