明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2123|回复: 11

程序的一点bug,请大虾们给点建议!

  [复制链接]
发表于 2004-7-16 13:08:00 | 显示全部楼层 |阅读模式




以上代码是一个画圆中心线的小程序,执行完程序后按ctrl+z(两下),问题出现了.


1.只取消一条中心线.


2.程序中所有系统变量没有恢复到程序未执行的状态.包括osmode,cmdecho,layer,clayer.


请教大虾,问题如何解决?                                         

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2004-7-16 13:12:00 | 显示全部楼层
这样: (defun c:ac (/ oce osm c1 cp c2 c3 )
(command "_.undo" "be")
(setq oce (getvar "cmdecho"))
(setq osm (getvar "osmode"))
(setvar "cmdecho" 0)
(setvar "osmode" 4)
(initget "C")
(setq c1 (nentsel "\nSelect circle or [Center point]:"))
(cond
((not c1) (princ "\nNothing is selected!") )
((eq c1 "C")
(setq cp (getpoint "\nPick center point: "))
(nl)
)
(t (setq
c2 (entget (car c1))
c3 (cdr (assoc 0 c2))
)
(if (or (= c3 "CIRCLE") (= c3 "ARC"))
(progn
(setq cp (cdr (assoc 10 c2)))
(nl)
)
(princ (strcat "\nThe selected is not circle,it's "c3"!"))
)
)
)
(setvar "cmdecho" oce)
(setvar "osmode" osm)
(command "_.undo" "e")
(princ)
)
(defun nl (/ cd p1 p2 p3 p4 a cl)
(setvar "osmode" 0)
(setq
cd (getdist cp "\nEnter dist or pick a point:")
p1 (polar cp 0 cd)
p2 (polar cp (/ pi 2.0) cd)
p3 (polar cp pi cd)
p4 (polar cp (* 1.5 pi) cd)
)
(setq a (length (tblsearch "layer" "center")))
(setq cl (getvar "clayer"))
(if (= a 0)
(progn
(command ".layer" "N" "CENTER" "C" 1 "CENTER" "L" "CENTER" "CENTER" "LW" "0.09" "CENTER" "")
(command ".layer" "S" "CENTER" "")
)
)
(command ".layer" "S" "CENTER" "")
(command "._LINE" p3 p1 "")
(command "._LINE" p2 p4 "")
(command ".layer" "S" cl "")
)
 楼主| 发表于 2004-7-16 13:29:00 | 显示全部楼层
太好了,解决了,谢谢了!!!!!
发表于 2004-7-16 13:53:00 | 显示全部楼层
这个程序代码可以做省点的吧.
 楼主| 发表于 2004-7-16 18:54:00 | 显示全部楼层
BDYCAD发表于2004-7-16 13:53:00这个程序代码可以做省点的吧.

请教如何做省点,在下菜鸟,希望能得到一点迷津....... 谢谢!!!
发表于 2004-7-16 20:34:00 | 显示全部楼层
看这条. 不记得是哪个大侠写的了. 支持框选对象. (defun c:test ()
(setvar "osmode" 0)
(setq olayer (getvar "clayer"))
(mlayer "cline" "1" "center2")
(setq ss (ssget))
(if (< (length (ssnamex ss 0)) 2)
(setq pq (cadr (last (car (ssnamex ss 0)))))
(setq pq (cadr (nth 2 (cadr (ssnamex ss 0)))))
);i
(setq ns (sslength ss) n 0)
(while (< n ns)
(setq ent (ssname ss n))
(setq pc (dxf 10 ent))
(cond
((= (dxf 0 ent) "ARC")
(setq rad (dxf 40 ent)
d (/ (fix (* rad 100)) 1000.0)
p1 (polar pc (dxf 50 ent)(+ rad d))
p2 (polar pc (angle p1 pc)(+ rad d))))
((= (dxf 0 ent) "CIRCLE")
(setq rad (dxf 40 ent)
d (/ (fix (* rad 100)) 1000.0)
p1 (polar pc 0 (+ rad d))
p2 (polar pc pi (+ rad d))))
((= (dxf 0 ent) "ELLIPSE")
(setq px (dxf 11 ent)
px (list (+ (car pc)(car px))(+ (cadr pc)(cadr px)) 0)
rad (distance pc px)
d (/ (fix (* rad 10)) 100.0)
p1 (polar pc (angle pc px)(+ rad d))
p2 (polar pc (angle px pc)(+ rad d))
rad1 (* (dxf 40 ent) rad)
ri (/ (+ rad1 d)(+ rad d))))
);c
(if p2 (vl-cmdf "line" p1 p2 "" ))
(setq lline (entlast))
(vl-cmdf "copy" (entlast) "" pc pc "rotate" (entlast) "" pc 90 )
(if (= (dxf 0 ent) "ELLIPSE")(vl-cmdf "scale" lline "" pc ri ))
(setq n (1+ n))
);w
(setvar "clayer" olayer)
(setvar "osmode" 37)
(princ)
);defun
(defun mlayer (name color ltype)
(if (tblsearch "layer" name)
(vl-cmdf ".layer" "s" name "")
(progn
(setq regen (getvar "regenmode"))
(setvar "regenmode" 0)
(vl-cmdf ".layer" "m" name)
(if color (vl-cmdf "c" color name))
(if ltype (vl-cmdf "lt" ltype name))
(vl-cmdf "")
(setvar "regenmode" regen)
)
)
) (defun dxf (code ename)(cdr (assoc code (entget ename))));
 楼主| 发表于 2004-7-16 20:49:00 | 显示全部楼层
太好了,程序有点长,我慢慢研究研究!!!
 楼主| 发表于 2004-7-16 20:52:00 | 显示全部楼层
BDYCAD,偶1楼的ac.lsp能再减肥吗?
发表于 2004-7-16 22:04:00 | 显示全部楼层
BDYCAD,偶试了你的程序当我第一次框选时,结果正确,但接着选取时就出错了(选取第一次的园和绘制的十字线)
发表于 2004-7-17 10:14:00 | 显示全部楼层
O, 不会吧. 我这边试过不会出错呢.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 15:54 , Processed in 0.210505 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表