求一个cad lisp 双向偏移的代码
(PRINC "\ 双向偏移 \(2005.8.8胡晓航\) ")
(setq d 20 p1 nil pee (/ pi 2)e 3 pckbox (getvar "pickbox")line " ")
(if(= #parof nil)(setq #parof(/(getvar "viewsize")10)))
(princ "\n当前偏移量 <")(princ #parof)
(setq answer(getstring ">: "))
(if (/= (atof answer) 0.0)(setq #parof(atof answer)))
(princ line)
(setvar "pickbox" pckbox)
(setq ent(entsel "\n拾取线: "))
(setvar "pickbox" 2)
(setq point(cadr ent))
(princ line)
(setq side(getpoint "\n拾取要偏移的一方: "))
(setq dist(distance side point))(setq ang(angle side point))
(if(or(or(< ang 0.78)(> ang 5.5))(and(> ang 2.35)(< ang 3.92)))
(setq ang(- 0 ang))(setq ang(- pi ang))
);end if
(setq other(polar point ang dist))
(command "offset" #parof ent side ent other "")
;(entdel(car ent))
(setvar "pickbox" pckbox)
(princ)
(princ)
)
(Prompt "\n键入OO唤起命令:")
这个代码有2个问题
1.我看不到上次偏移的数值(我关闭命令行的时候)
2.如果我没点到目标对象,我的选取框会变小 展开
1,程序未将运行此命令前的OFFSET偏移值取出并于计算后还原;
2,未选择目标对象时,程序已运算出错,后面的将pickbox即选取框大小值还原部分未运算,所以无法还原选取框的大小。试试下面的代码吧:
(defun c:gg ( )
(if (setq obj (entsel "\n选择双向偏移对象: "))
(progn
(setq cm (getvar "cmdecho") of (getvar "offsetdist"))
(if (null (setq nf (getdist (strcat "\n偏移量: <" (rtos of 2 3) "> "))))
(setq nf of)
)
(setvar "cmdecho" 0) (setvar "offsetdist" nf) (vl-load-com)
(setq obj (vlax-ename->vla-object (car obj)))
(vla-offset obj nf) (vla-offset obj (* nf -1))
(setvar "offsetdist" of) (setvar "cmdecho" cm)
)
(princ "\n未选择偏移对象,程序退出.")
)
(princ)
)
(defun c:gg (/ pt1 pt2 ss o i s)
(setq pt1 (getpoint "First Pt:"))
(setq pt2 (getpoint "Second Pt:"))
(setq ss (ssget "c" pt1 pt2 '((0 . "*LINE")))) ; 框选:c
(setq o 0.55) ; 偏移距离
(setq i 0)
(while (setq s (ssname ss i))
; first line
(vla-Offset (vlax-EName->vla-Object s) o) ; 正向偏移
(vla-put-layer (vlax-EName->vla-Object (entlast)) (getvar "clayer")) ; 将偏移后的线段设置为当前图层
; second line
(vla-Offset (vlax-EName->vla-Object s) (* o -1)) ; 反向偏移
(vla-put-layer (vlax-EName->vla-Object (entlast)) (getvar "clayer"))
(setq i (+ i 1))
)
(princ)
) (vl-load-com)