明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2559|回复: 2

归范化多义线

[复制链接]
发表于 2004-8-17 12:16 | 显示全部楼层 |阅读模式
;;;------------------------------------------------------------------------;;;
;;; 归范化多义线 ;;;
;;; 1. 消除折环 ;;;
;;; 2. 消除冗余结点 ;;;
;;;------------------------------------------------------------------------;;; ;;; http://devcad.vicp.net (vl-load-com) (defun c:test ( / old_osmd sset len i item lst coords name ssp txtobj
retlst ptcur pt j pti)
(setq old_osmd (getvar "osmode"))
(setvar "osmode" 0)

(vla-ZoomExtents (vlax-get-acad-object))

(setq sset (ssget "x" (list
(cons -4 "<or")
(cons -4 "<and")
(cons 0 "LWPOLYLINE")
(cons -4 "and>")
(cons -4 "<and")
(cons 0 "POLYLINE")
(cons -4 "and>")
(cons -4 "or>")
)
))
(setq len (sslength sset)) (setq i 0)
(repeat len
(setq ename (ssname sset i))
(setq item (vlax-ename->vla-object ename))
;取得多义线坐标
(setq lst (vlax-safearray->list
(vlax-variant-value
(vlax-get-property item 'Coordinates))
)
)

(setq coords nil)
(if (= (vlax-get-property item 'ObjectName) "AcDb2dPolyline")
(progn
(while lst
(if (= coords nil)
(setq coords (list (list (nth 0 lst) (nth 1 lst))) )
(setq coords (append coords (list (list (nth 0 lst) (nth 1 lst)))))
)
(setq lst (cdr (cdr (cdr lst))))
)
)
)

(if (= (vlax-get-property item 'ObjectName) "AcDbPolyline")
(progn
(while lst
(if (= coords nil)
(setq coords (list (list (nth 0 lst) (nth 1 lst))) )
(setq coords (append coords (list (list (nth 0 lst) (nth 1 lst)))))
)
(setq lst (cdr (cdr lst)))
)
)
)
;处理坐标coords
(setq lastpt (car (reverse coords))) ;提取最后一个结点坐标
(setq coords (reverse (cdr (reverse coords)))) ;从coords中删除最后一个结点坐标 ;构建新的坐标表
(setq retlst nil)
(while coords
(if (= retlst nil)
(setq retlst (list (nth 0 coords) )) ;提取第一个点
(progn
(setq ptcur (nth 0 coords))
;判断pt是否已经在retlst中,若为F,加入到retlst
(setq exist nil j 0)
(while (setq pt (nth j retlst))
;ptcur与pt和lastpt比较
(if (or (and (= (nth 0 ptcur) (nth 0 pt)) (= (nth 1 ptcur) (nth 1 pt)))
(and (= (nth 0 ptcur) (nth 0 lastpt)) (= (nth 1 ptcur) (nth 1 lastpt)))
)
(setq exist t)
);
(setq j (+ j 1))
);while

;
(if (not exist)
(setq retlst (append retlst (list ptcur)))
)
);progn
);if
(setq coords (cdr coords))
) (setq retlst (append retlst (list lastpt))) ;判断是否封闭
(setq closed nil)
(vlax-dump-object item t)
(if (vlax-property-available-p item 'Closed)
(setq closed (vlax-get-property item 'Closed))
)

;绘新多义线
(command "pline")
(foreach pti retlst (command pti))
(if (= closed :vlax-true)
(command "C" "")
(command "" "")
)

(command) ;属性匹配
(command "matchprop" ename (entlast) "") ;删除线对象
(vlax-invoke-method item 'Delete) (setq i (+ i 1))
(grtext -1 (itoa i))
);repeat (setvar "osmode" old_osmd) (grtext -1 "OK")
(princ "\nOK!")
(alert "OK!")
(grtext -1 "")
(princ)
);defun

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2004-8-25 03:43 | 显示全部楼层
好像只是专门对付闭合冗余结点的,对么?



看上去只是处理了第一和最末尾的点



试了一下,曲线段都变成直的了:(
 楼主| 发表于 2004-8-28 09:34 | 显示全部楼层

回复

是, 有些方法给初学者借鉴吧.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-21 01:11 , Processed in 0.541084 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表