本帖最后由 wzg356 于 2014-7-13 01:30 编辑
很抱歉,记不清原帖子的位置了
适用范围比较大
曲线、椭圆、圆、圆弧等转换的数学指标按相似度调整,如果是直线、未拟合的多线段不受相似度影响- ;;将各种线段转为多线段,将多线段上的弧线段也转为多线段
- ;;(CurveToPoline en);;参数:图元名;;示例(CurveToPoline (car(entsel "\n选择对象: ")))
- ;;适用"line,lwpolyline,polyline,spline,circle,arc,ellipse"
- (defun CurveToPoline ( en / c2 C ob a n pt D l m q p b o r F )
- (vl-load-com)
- (setq C2 0.65) ;;可理解为相似度,不要小于0.65,不能为1
- (setq C(/(- 1.0 C2)2))
- (setq ob (vlax-ename->vla-object en)
- a 0
- n 1
- pt nil
- D (vla-get-objectname ob)
- l (vlax-curve-getdistatparam ob(vlax-curve-getendparam ob))
- m (cond((= D"AcDb3dPolyline")3)((= D"AcDb2dPolyline")2)((= D"AcDbPolyline")2))
- )
- (if(or(= D"AcDb3dPolyline")(= D"AcDbPolyline"))
- (if(vl-catch-all-error-p(vl-catch-all-apply 'vla-get-Coordinates(list ob)))(setq Pt(StarEnd ob))
- (progn
- (setq q(vlax-safearray->list(vlax-variant-value(vla-get-Coordinates ob))))
- (repeat(/(length q)m)
- (cond
- ((= m 2)(setq p(list(nth a q)(nth(+ a 1)q))))
- ((= m 3)(setq p(list(nth a q)(nth(+ a 1)q)(nth(+ a 2)q))))
- )
- (setq a(+ a m)
- Pt(if(or(null Pt)(>(distance p(cdr(car(reverse Pt))))0.00005))
- (append Pt(list(append(list(vlax-curve-getparamatpoint ob p))p)))pt)
- )
- )
- )
- )
- (setq Pt(StarEnd ob))
- )
- (while(< n(length Pt))
- (setq m(1- n)
- a(vlax-curve-getdistAtparam ob(car(nth m Pt)))
- b(-(vlax-curve-getdistAtparam ob(car(nth n Pt)))a)
- )
- (if(<= b 0)(setq b(- l a)))
- (setq o(vlax-curve-getparamatdist ob(+(/ b 2)a))
- r(append(list o)(vlax-curve-getpointatparam ob o))
- F(count-f ob (* b c2)(cdr(nth m Pt))(cdr r)(cdr(nth n Pt))c)
- )
- (cond
- ((= F 1)(setq n(1+ n)))
- ((= F 2)(setq Pt(insertlist Pt r n)))
- )
- )
- (setq F(if(vlax-curve-isClosed ob)1 0)
- b(entget(vlax-vla-object->ename ob)'("*"))
- Pt(if(and(= F 1)(NULL(vl-string-search "Polyline" D)))(reverse(cdr(reverse Pt)))Pt)
- )
- (setq a (list(cons 0 "LWPOLYLINE")
- (cons 8(cdr(assoc 8 b)))
- (cons 6(if(assoc 6 b)(cdr(assoc 6 b))"Bylayer"))
- (cons 62(if(assoc 62 b)(cdr(assoc 62 b))256))
- (cons 370(if(assoc 370 b)(cdr(assoc 370 b))0))
- (cons 48(if(assoc 48 b)(cdr(assoc 48 b))1))
- (cons 100 "AcDbEntity")
- (cons 100 "AcDbPolyline")
- (cons 90(-(length Pt)F))
- (cons 70 (+ 128 F))
- (cons 43(if(assoc 43 b)(cdr(assoc 43 b))0))
- (cons 38(caddr(vlax-curve-getstartpoint ob)))
- (cons 39(if(assoc 39 b)(cdr(assoc 39 b))0))
- )
- a (append a(foreach b Pt(setq Pt(subst(subst 10(car b)b)b Pt))))
- )
- (entmake(if(assoc -3 b)(append a(list(assoc -3 b)))a))
- (prin1)
- )
- ;;以下为3个子函数
- (defun StarEnd(ob)
- (list(append(list(vlax-curve-getstartparam ob))(vlax-curve-getstartpoint ob))
- (append(list(vlax-curve-getendparam ob))(vlax-curve-getendpoint ob)))
- )
- (defun count-f (OBJ l p q o C / F)
- (setq F (if(and (>(+(distance p q)(distance q o))l)
- (<(abs(*(distance p q)(sin(-(angle p q)(angle p o)))))C)
- )
- 1
- 2
- )
- )
- )
- (defun insertlist(Lst en n / l m s)
- (cond
- ((= n 0)(setq s(append(list en)LST)))
- ((= n(setq l(length LST)))(setq s(append LST(list en))))
- (T(setq m 1 s(list(car LST)))
- (while(< m n)(setq s(append s(list(nth m LST)))m(1+ m)))
- (setq s(append s (list en)))
- (while(< m l)(setq s(append s(list(nth m LST)))m(1+ m)))
- )
- )
- (setq Lst s)
- )
|