本帖最后由 yjr111 于 2011-10-22 21:16 编辑
除了块内矩形选边外,其他问题基本都处理了一下,效果没有高手那么炫,不过已经可以满足自己的使用需求,代码实时更新,有兴趣的可以试试。。。
- (defun c:yxpq(/ e1 e2 ee s11 s22 point_e1 vla_e1 vla_e2 dxf_10 p1 jux_ang e1_ang1 e1_ang2 hudu1
- JIAODU1 HUDU2 JIAODU2 JIAODU3)
- (vl-load-com)
- (setvar "cmdecho" 0)
- (setq e1 (car(setq ee(nentsel"\n 请选择要对齐的物体:"))))
- (setq s11 (entget e1))
- (setq point_e1 (cdr(assoc 10 s11)))
- (setq e2 (car(setq eee(entsel"\n 请选择物体要对齐的曲线"))))
- (setq s22 (entget e2))
-
- ;;;;;;;;;;;取得点击点处最近的在实体或曲线的位置;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (setq vla_e1(vlax-ename->vla-object e1))
- (setq vla_e2(vlax-ename->vla-object e2))
-
- (if(WCMATCH(cdr(assoc 0 s11))"*POLYLINE")
- (progn
- (setq p1(vlax-curve-getclosestpointto vla_e1 (cadr ee)));;;;;实体点击点若不在实体上,找到在实体上最近的点
-
- (SETQ dxf_10 (massoc 10 s11))
- (setq jux_ang(angle (nth 0 dxf_10)(nth 1 dxf_10)))
- (setq e1_ang1(angle (nth 0 dxf_10) p1))
- (setq e1_ang2(angle p1(nth 2 dxf_10) ) )
-
- (if(= e1_ang1 pi)(setq e1_ang1 0.0))
- (if(= e1_ang2 pi)(setq e1_ang2 0.0))
- (if(= jux_ang pi)(setq jux_ang 0.0))
- )
- )
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;取得待对齐的实体的旋转角度;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (cond((=(cdr(assoc 0 s11))"LINE") (setq hudu1 (ATAN(/(-(cADdr(assoc 10 s11))
- (cADdr(assoc 11 s11)))(-(cAdr(assoc 10 s11))(cAdr(assoc 11 s11)))))))
- ((WCMATCH(cdr(assoc 0 s11))"*POLYLINE,ARC")(if(or(equal jux_ANG e1_ang1 0.001)(equal jux_ANG e1_ang2 0.001))
- (setq hudu1 jux_ang )
-
- (setq hudu1 (+ jux_ang (* 0.5 pi) ))))
-
- ((WCMATCH(cdr(assoc 0 s11))"CIRCLE,SPLINE,ELLIPSE,XLINE")(setq hudu1 0 ))
-
- (t (setq hudu1 (cdr(assoc 50 s11))))
- )
- (SETQ JIAODU1 (* (/ HUDU1 PI)180))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;返回关联表中相同组码保存的信息,明经lsp QQ群信息;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun massoc (code xlist / x nlist)
- (setq nlist nil)
- (foreach x xlist
- (if (eq code (car x))
- (setq nlist (cons (cdr x) nlist))
- )
- )
- (reverse nlist)
- )
- ;;;;;;;;;;;;;;;;;;;;;;;;取得对齐直线的旋转角度;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (COND((=(cdr(assoc 0 s22))"LINE") (if (/= (setq chushu1(-(cAdr(assoc 10 s22))(cAdr(assoc 11 s22))))0)
- (setq hudu2 (ATAN(/ (-(cADdr(assoc 10 s22)) (cADdr(assoc 11 s22))) chushu1)))
- (setq hudu2 (* 0.5 pi))))
- ((WCMATCH(cdr(assoc 0 s22))"*POLYLINE,ARC,SPLINE")(setq p2(vlax-curve-getclosestpointto vla_e2 (cadr eee)));;;;;曲线点击点若不在曲线上,找到在曲线上最近的点
- (setq p3(vlax-curve-getclosestpointto vla_e2 (list (+(car p2)0.001)(+(cadr p2)0.001)(+(caddr p2)0.0))))
- (setq hudu2 (angle p2 p3)))
- )
-
- (SETQ JIAODU2 (* (/ HUDU2 PI)180))
- ;;;;;;;;;;;;;;旋转平移;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (IF (> (LENGTH ee)2) (PROGN (SETQ e1 (CAAR (REVERSE ee)))
- (setq point_e1 (cdr(assoc 10 (ENTGET e1)))
- jiaodu3 (*(/(cdr(assoc 50 (ENTGET e1)))PI)180))))
- (cond ((and(and(and e1 e2)(< (LENGTH ee)3))(WCMATCH(cdr(assoc 0 s11))"*POLYLINE"))
- (command "_.rotate" e1 "" p1 (- jiaodu2 jiaodu1))
- (command "_.MOVE" e1 "" p1 pause))
- ((and(and e1 e2)(> (LENGTH ee)2))
- (command "_.rotate" e1 "" point_e1 (- jiaodu2 jiaodu1 jiaodu3))
- (command "_.MOVE" e1 "" point_e1 pause))
-
- (t(command "_.rotate" e1 "" point_e1 (- jiaodu2 jiaodu1 ))
- (command "_.MOVE" e1 "" point_e1 pause))
-
- )
- (princ)
- )
|