Andyhon 发表于 2011-10-31 14:56
...都是只剪切内部的线...
请上传更新后的代码+调试用的文件(*.Dwg)
感谢Andyhon。犯了低级错误,用偏移后的圆作为边界,肯定会得到错误的结果。上传单向偏移的代码,可以剪切圆外部
- (defun c:ctrim ( / circ_pts lst ang inc tmp seg pt ent
- ctrim_err x f_pts svd_os svd_cmd svd_err)
- (defun ctrim_err (s)
- (if(/= s "Function cancelled")
- (princ(strcat "\n\n" s)) )
- (setvar "cmdecho" svd_cmd)
- (setvar "osmode" svd_os)
- (setq *error* svd_err)
- )
- (defun circ_pts (enm)
- (setq lst (entget enm)
- ang (* pi 2)
- inc (/ ang 64)
- tmp '()
- seg 65
- )
- (repeat seg
- (setq pt (polar(cdr(assoc 10 lst))ang
- (-(cdr(assoc 40 lst))0.01))
- ang (+ inc ang)
- )
- (setq tmp(cons pt tmp))
- )
- tmp
- )
- (defun meoffset (obj dst / tmplst)
- (if (not (vl-catch-all-error-p (setq tmplst (vl-catch-all-apply 'vlax-invoke (list obj 'offset dst)))))
- tmplst
- )
- )
- (setq ent (car(entsel "\nSelect circle: "))
- svd_err *error*
- *error* ctrim_err
- svd_os (getvar "osmode")
- svd_cmd (getvar "cmdecho")
- )
- (setvar "cmdecho" 0)
- (setvar "osmode" 0)
- (if(and ent
- (=(cdr(assoc 0(entget ent)))"CIRCLE")
- )
- (progn
- (meoffset (vlax-ename->vla-object ent) 0.1)
- (setq f_pts(circ_pts (entlast)))
- (repeat 2
- (command "trim" ent "" "f")
- (foreach x f_pts(command x))
- (command "" "")
- )
- (command "erase" (entlast) "")
- )
- )
- (setvar "cmdecho" svd_cmd)
- (setvar "osmode" svd_os)
- (setq *error* svd_err)
- (princ)
- )
但是又有新的问题。为何此处非要执行两次?一次只能剪切一边,奇哉怪也。有兴趣的帮忙测试一下啊。谢谢
- (repeat 2
- (command "trim" ent "" "f")
- (foreach x f_pts(command x))
- (command "" "")
- )
|