谢谢,测试后OK,以下是修改后的代码。
 - (defun c:my_hatch( ta sc / i p1 p2 ent_t ss)
- ;测试使用
- (if (not ta) (setq ta "ANSI31")) ;设置填充图案ANSI31
- ;(if (not la) (command "-layer" "s" "0" "")) ;设置图层
- (if (not sc) (setq sc (* 10 (getvar "HPSCALE")))) ;设置填充比例,此比例不是天正比例,使用会出问题。
- (if (not smode) (setq smode "R")) ;全局变量,填充模式(矩形、封闭对象、内部点),默认矩形填充
- (setq i t) ;一直循环标志
- (while i
- (cond
- ((= smode "R")
- (initget 1 "S C P")
- (setq p1 (getpoint "\n输入第一点或[选择对象(S)/创建封闭多义线填充(C)/内部点(p)]"))
- (if (= (type p1) 'LIST)
- (progn
- (setq i f) ;退出循环标志
- (setq p2 (getcorner p1 "\n输入第二个点"))
- (command "rectang" p1 p2)
- (setq ent_t (entlast))
- (command "-bhatch" "p" ta sc "" "s" ent_t "" "") ;填充 图案开关 图案名称 比例 角度 选择对象开关
- (entdel ent_t)
- )
- (progn ;下次循环,如果输入值为nil,假定填充模式为封闭对象
- (if (not p1)
- (setq smode "S")
- (setq smode p1)
- )
- )
- )
- )
- ((= smode "P")
- (initget 1 "R S C")
- (setq p1 (getpoint "\n指定内部点或[矩形填充(R)/选择对象(S)]/创建封闭多义线填充(C)"))
- (if (= (type p1) 'LIST)
- (progn
- (setq i f);退出循环标志
- (command "_bhatch" "p" ta sc "" p1 "")
- )
- (progn
- (if (not p1)
- (setq smode "R")
- (setq smode p1);继续循环
- )
- )
- )
- )
- ((= smode "S")
- (princ "\n选择对象或[矩形填充<space>]")
- (setq ss (ssget '( (-4 . "<or")
- (-4 . "<and") (0 . "LWPOLYLINE") (70 . 1) (-4 . "and>")
- (0 . "CIRCLE,ELLIPSE")
- (-4 . "or>")))) ;选择封闭多义线图形、圆、椭圆
- (if (not ss)
- (progn
- (setq smode "r");下次循环,设置填充模式为R
- )
- (progn
- (setq i f);退出循环
- (command "_bhatch" "p" ta sc "" "s" ss "" "")
- )
- )
- )
- ((= smode "C")
- (initget 1 "R S P")
- (setq p1 (getpoint "\n指定起点或[矩形填充(R)/选择对象(S)/指定内部点(P)]"))
- (if (= (type p1) 'LIST)
- (progn
- (setq i f);退出循环标志
- (command ".pline" p1 );创建封闭多义线,感谢Lisphk@晓东CAD
- (while (= (getvar "cmdactive") 1)
- (princ "\r下一点[闭合(C)]<退出>:")
- (command pause)
- )
- (command "_bhatch" "p" ta sc "" "s" (entlast) "" "");填充
- )
- (progn
- (if (not p1)
- (setq smode "R");下次循环,设置填充模式为R
- (setq smode p1)
- )
- )
- )
- )
- ( t
- (setq smode "R")
- )
- )
- )
- (princ)
- )
|