明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2805|回复: 11

join and close polyline as much as possible

  [复制链接]
发表于 2004-5-27 08:23:00 | 显示全部楼层 |阅读模式
  1. hey, guys,here is the code i tried to join polyline as much as possible, then close them, but it just could close one polyline, any idea about this?   thank u very much!!!   ; this routine is try to join ployline as much as possible, then
  2.    ; close them.
  3.    
  4.    ;;; returns the first group value of an entity.
  5.    ;;; like the wellknown (dxf) function but accepts all kinds of
  6.    ;;; entity representations (ename, entget list, entsel list)
  7.    
  8.    (defun GETVAL (grp ele)                                 ;"dxf value" of any ent...       (cond ((= (type ele) 'ENAME)                   ;ENAME                       (cdr (assoc grp (entget ele))))                   ((not ele) nil)                                 ;empty value                   ((not (listp ele)) nil)                 ;invalid ele                   ((= (type (car ele)) 'ENAME)       ;entsel-list                       (cdr (assoc grp (entget (car ele)))))                   (T (cdr (assoc grp ele)))))         ;entget-list   ;--------------------------------------------------------------------
  9.    ;;;   (gettyp pline) => "POLYLINE"   (defun GETTYP (ele)                                         ;return type
  10.        (getval 0 ele))   ;--------------------------------------------------------------------
  11.    ;;; assure ENAME
  12.    ;;; convert the entity to type ENAME    (defun ENTITY (ele)                                         ;convert to element name       (cond           ;accepts the following types:           ((= (type ele) 'ENAME) ele)                         ; ENAME           ((not (listp ele)) nil)                                 ; error: no list           ((= (type (car ele)) 'ENAME) (car ele)) ; entsel-list           ((cdr (assoc -1 ele)))                                   ; entget-list or nil       )   )   ;--------------------------------------------------------------------
  13.   
  14.    (defun getval (grp ele) (cdr (assoc grp (entget (entity ele)))))   ;--------------------------------------------------------------------
  15.    ;;; (istypep ele "TEXT")
  16.    ;;; is element a "SOLID"?   (defun istypep (ele typ)                                     ;check type
  17.        (= (gettyp ele) typ))   ;--------------------------------------------------------------------
  18.    ;;; (istypep ele '("TEXT" "ATTDEF"))
  19.    ;;; is element a "TEXT" or a "ATTDEF"?   (defun ISTYPEP (ele typ)     ;better implementation to accept lists too       (cond           ((listp typ)     (member (gettyp ele) typ))            ((stringp typ) (= (gettyp ele) typ))           ;assume typ uppercase           (T nil)))   ;--------------------------------------------------------------------
  20.    ;;; (getpt (entsel))   => ( 0.1 10.0 24)   (defun GETPT (ele)       ;return the startpoint of any element       (getval 10 ele))       ;group 10   ;--------------------------------------------------------------------
  21.    ;;; (getflag pline)   => 1 if closed   (defun GETFLAG (ele) (getval 70 ele)) ;same with the entity flag   ;--------------------------------------------------------------------
  22.    ;;; bitvalue val in flag of element set?
  23.    ;;; (flagsetp 1 pline)     => T if closed
  24.    
  25.    (defun FLAGSETP (val ele)       (bitsetp val (getflag ele)))     
  26.    ;--------------------------------------------------------------------
  27.    ;;; (bitsetp 4 12) => T     ;bitvalue 4 (=2.Bit) in 12 (=4+8) is set   (defun BITSETP (val flag)       (= (logand val flag) val))
  28.    ;--------------------------------------------------------------------
  29.    ;;; convert selection set to list,
  30.    ;;; it's to use ai_ssget, because some ents could be on locked layers
  31.    ;;; (sslist (ai_ssget (ssget))) => list of selected unlocked ents
  32.    ;;; or   (mapcar 'entupd (sslist (ssget "X" '((8 . "TEMP")))))
  33.    ;;;             - regens all entities on layer TEMP   (defun SSLIST (ss / n lst)       (if (= (type ss) 'PICKSET)           (repeat (setq n (sslength ss))               (setq n (1- n)                           lst (cons (ssname ss n) lst)))))   ;--------------------------------------------------------------------
  34.    ;;; apply a function to each ent in ss,
  35.    ;;; (ssmap 'entupd (ssget))     ; regenerate only some entities   (defun SSMAP (fun ss / n)       (if (= 'PICKSET (type ss))           (repeat (setq n (sslength ss))               (apply fun (list (ssname ss (setq n (1- n))))))))   ;--------------------------------------------------------------------
  36.    ;;; This tries to join as much polylines as possible.   (defun C:JOINPOLY (/ ele ss)       (foreach ele (sslist (setq ss (ssget)))         ;process lists           (if (entget ele)                                                   ;not already joined               (cond                                                                     ;(then it would be nil)                   ;((istypep ele '("ARC" "LINE"))             ; some pillars might use
  37.               ; lines or arcs????                       ;(command "_PEDIT" ele "_Y" "_J" ss "" ""); convert and JOIN                   ;)                   ((and (istypep ele '("POLYLINE" "LWPOLYLINE"))                                (not (flagsetp 1 ele))                   ;not closed
  38.                                (< (rem (getflag ele) 128) 8))   ;ignore meshes and such                       (command "_PEDIT" ele "_J" ss "" "")                   )               )           )       )   )
  39.    ;--------------------------------------------------------------------
  40.    ;;; This closes as much polylines as possible.   (defun C:CLOSEPOLY (/ ele ss)         (foreach ele (sslist (setq ss (ssget)))         ;process lists               (if (and (istypep ele '("POLYLINE" "LWPOLYLINE"))                                (not (flagsetp 1 ele))                   ;not closed
  41.                                (< (rem (getflag ele) 128) 8))   ;ignore meshes and such                       (command "_PEDIT" ele "_C" ss "" "")         (command "_PEDIT" ele "_X" ss "" "")         
  42.       
  43.                )         )   )  
发表于 2004-5-27 15:08:00 | 显示全部楼层
 楼主| 发表于 2004-5-28 01:48:00 | 显示全部楼层
龙龙仔, my purpose is to join polylines as much as possible, after that, i need to close every polyline, but the aotolisp code below just close only one polyline, u know the "pedit" command for polyline ask "Close" or "Open" all the time, do u have any idea overcome this problem??? ;;; This closes as much polylines as possible. (defun C:CLOSEPOLY (/ ele ss) (foreach ele (sslist (setq ss (ssget))) ;process lists (if (and (istypep ele '("POLYLINE" "LWPOLYLINE")) (not (flagsetp 1 ele)) ;not closed
(< (rem (getflag ele) 128) 8)) ;ignore meshes and such (command "_PEDIT" ele "_C" ss "" "") (command "_PEDIT" ele "_X" ss "" "")

) ) )
发表于 2004-5-28 07:56:00 | 显示全部楼层
傳個測試圖上來吧!
 楼主| 发表于 2004-5-28 09:05:00 | 显示全部楼层

本帖子中包含更多资源

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

x
发表于 2004-5-28 12:24:00 | 显示全部楼层
(defun C:CLOSEPOLY (/ ENT N SS)
(vl-load-com)
(setq SS (ssget '((0 . "*POLYLINE")))
N 0
)
(repeat (sslength SS)
(if (= :vlax-false
(vla-get-closed
(setq ENT (vlax-ename->vla-object (ssname SS N)))
)
)
(vla-put-closed ENT :vlax-true)
)
(setq N (1+ N))
)
(princ)
)
发表于 2004-5-28 12:35:00 | 显示全部楼层
龙版,为什么我在测试楼上的程序的时候出现:closepoly ; 错误: COM 异常: 访问 OLE 注册表的错误,


公司里是win2000的操作系统,我们没有安装权限, 是不是和权限有关,所以无法运行(vl-load-com)这一句?
发表于 2004-5-28 12:42:00 | 显示全部楼层
(vl-load-com) 是載入 Visual LISP 延伸函數至 AutoLISP
這個函數載入 Visual LISP 提供的延伸 AutoLISP 函數。Visual LISP 延伸函數實施 ActiveX 及經由 AutoLisp 支援 AutoCAD 反應裝置,另外也提供 ActiveX 公用程式及資料轉換函數、字典處理函數及曲線測量函數。
如果已載入該副檔名,vl-load-com 不做任何事。 你用那一版AUTOCAD?
发表于 2004-5-28 13:52:00 | 显示全部楼层
lucas,我觉得不必先判断是否闭合,以下即便ss的filter不进行筛选,直接put-closed也可以。没必要花时间在判断是否闭合上
  1. ;;将不闭合的pl线闭合.
  2. (defun C:CLOSEPOLY (/ N SS)
  3.    (vl-load-com)
  4.    (setq SS (ssget '((0 . "*polyline")(-4 . "<NOT")(-4 . "&") (70 . 1)(-4 . "NOT>")))
  5.                  N   -1)
  6.    (repeat (sslength SS)
  7.          (vla-put-closed (vlax-ename->vla-object (ssname SS (setq N (1+ N)))) :vlax-true)
  8.    )(princ)
  9. )
  1. ;;;将不闭合的pl线闭合.---命令方式.
  2. (defun C:CLOSEPOLY ()
  3.    (vl-cmdf "_.pedit" "m" (ssget '((0 . "*polyline")(-4 . "<NOT")(-4 . "&") (70 . 1)(-4 . "NOT>"))) "" "c" "")
  4. )
发表于 2004-5-28 14:07:00 | 显示全部楼层
本來想判斷只有一段的pline不閉合,但又懶.... 8-)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-10-1 08:18 , Processed in 0.178664 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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