乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 72|回复: 4

join and close polyline as much as possible

[复制链接]

1

主题

6

帖子

2

银币

初来乍到

Rank: 1

铜币
10
发表于 2004-5-27 08:23:00 | 显示全部楼层 |阅读模式
[code]
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
   ; close them.
   
   ;;; returns the first group value of an entity.
   ;;; like the wellknown (dxf) function but accepts all kinds of
   ;;; entity representations (ename, entget list, entsel list)
   
   (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   ;--------------------------------------------------------------------
   ;;;   (gettyp pline) => "POLYLINE"   (defun GETTYP (ele)                                         ;return type
       (getval 0 ele))   ;--------------------------------------------------------------------
   ;;; assure ENAME
   ;;; 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       )   )   ;--------------------------------------------------------------------
  
   (defun getval (grp ele) (cdr (assoc grp (entget (entity ele)))))   ;--------------------------------------------------------------------
   ;;; (istypep ele "TEXT")
   ;;; is element a "SOLID"?   (defun istypep (ele typ)                                     ;check type
       (= (gettyp ele) typ))   ;--------------------------------------------------------------------
   ;;; (istypep ele '("TEXT" "ATTDEF"))
   ;;; 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)))   ;--------------------------------------------------------------------
   ;;; (getpt (entsel))   => ( 0.1 10.0 24)   (defun GETPT (ele)       ;return the startpoint of any element       (getval 10 ele))       ;group 10   ;--------------------------------------------------------------------
   ;;; (getflag pline)   => 1 if closed   (defun GETFLAG (ele) (getval 70 ele)) ;same with the entity flag   ;--------------------------------------------------------------------
   ;;; bitvalue val in flag of element set?
   ;;; (flagsetp 1 pline)     => T if closed
   
   (defun FLAGSETP (val ele)       (bitsetp val (getflag ele)))     
   ;--------------------------------------------------------------------
   ;;; (bitsetp 4 12) => T     ;bitvalue 4 (=2.Bit) in 12 (=4+8) is set   (defun BITSETP (val flag)       (= (logand val flag) val))
   ;--------------------------------------------------------------------
   ;;; convert selection set to list,
   ;;; it's to use ai_ssget, because some ents could be on locked layers
   ;;; (sslist (ai_ssget (ssget))) => list of selected unlocked ents
   ;;; or   (mapcar 'entupd (sslist (ssget "X" '((8 . "TEMP")))))
   ;;;             - 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)))))   ;--------------------------------------------------------------------
   ;;; apply a function to each ent in ss,
   ;;; (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))))))))   ;--------------------------------------------------------------------
   ;;; 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
              ; lines or arcs????                       ;(command "_PEDIT" ele "_Y" "_J" ss "" ""); convert and JOIN                   ;)                   ((and (istypep ele '("POLYLINE" "LWPOLYLINE"))                                (not (flagsetp 1 ele))                   ;not closed
                               (龙龙仔, 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
                                                                                                                         (vla-object (ssname SS N)))
                         )
        )
                                         (vla-put-closed ENT :vlax-true)
                         )
                         (setq N (1+ N))
         )
         (princ)
)
回复

使用道具 举报

29

主题

1152

帖子

10

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1268
发表于 2004-5-27 15:08:00 | 显示全部楼层
龙版,为什么我在测试楼上的程序的时候出现:closepoly ; 错误: COM 异常: 访问 OLE 注册表的错误,
公司里是win2000的操作系统,我们没有安装权限, 是不是和权限有关,所以无法运行(vl-load-com)这一句?
回复

使用道具 举报

1

主题

6

帖子

2

银币

初来乍到

Rank: 1

铜币
10
发表于 2004-5-28 01:48:00 | 显示全部楼层
(vl-load-com) 是載入 Visual LISP 延伸函數至 AutoLISP
這個函數載入 Visual LISP 提供的延伸 AutoLISP 函數。Visual LISP 延伸函數實施 ActiveX 及經由 AutoLisp 支援 AutoCAD 反應裝置,另外也提供 ActiveX 公用程式及資料轉換函數、字典處理函數及曲線測量函數。
如果已載入該副檔名,vl-load-com 不做任何事。
你用那一版AUTOCAD?
回复

使用道具 举报

29

主题

1152

帖子

10

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1268
发表于 2004-5-28 07:56: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 . "")))
  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 . ""))) "" "c" "")
  4. )
回复

使用道具 举报

1

主题

6

帖子

2

银币

初来乍到

Rank: 1

铜币
10
发表于 2004-5-28 09:05:00 | 显示全部楼层
本來想判斷只有一段的pline不閉合,但又懶.... 8-)
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-8-17 19:34 , Processed in 1.816711 second(s), 63 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表