chwnin 发表于 2013-10-22 16:46:28

请问大家快速选择首尾相连的所有线段,如何用lisp实现啊

请问大家快速选择首尾相连的所有线段,如何用lisp实现啊?

需要选择任何一条线段,都可以吧整个N条线段全部选择
lisp如何编写?
拜托大家帮我编写一个lsp!!

crazylsp 发表于 2013-10-22 17:10:33

ET工具有一个
    FASTSEL.LSP
;;;    Created 7/21/97 by Randy Kintzley
;;;    Copyright ?1999 by Autodesk, Inc.
;;;
;;;    Your use of this software is governed by the terms and conditions of the
;;;    License Agreement you accepted prior to installation of this software.
;;;    Please note that pursuant to the License Agreement for this software,
;;;    "opying of this computer program or its documentation except as
;;;    permitted by this License is copyright infringement under the laws of
;;;    your country.If you copy this computer program without permission of
;;;    Autodesk, you are violating the law."
;;;
;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.AUTODESK, INC.
;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
;;;    UNINTERRUPTED OR ERROR FREE.
;;;
;;;    Use, duplication, or disclosure by the U.S. Government is subject to
;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
;;;    (Rights in Technical Data and Computer Software), as applicable.
;;;
;;;----------------------------------------------------------------

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:fastsel ( / old_err ss ss2 n na )
(setq old_err *error*)
(defun *error* ( a / )
(princ a)
(setq *error* old_err)
(princ)
);defun

(fsmode_init)
(princ "\n使用 'FSMODE 以控制链选择。")
(princ (strcat "\nFSMODE = " #fsmode))
(setq ss2 (fs_get_current_sel)
       ss (fastsel)
);setq

(if (and ss
         (princ (strcat (itoa (sslength ss))
                        " 个对象被找到。"
                )
         )
         (not (equal (getvar "cmdnames") ""))
    );and
    (command ss);then pass in the selection set
    (progn
   (if (and ss
            (equal 1 (getvar "pickfirst"))
         );and
         (progn
          (if (not ss2)
            (setq ss2 ss)
            (progn
               (setq n 0)
               (repeat (sslength ss)
                (setq na (ssname ss n));setq
                (if (not (ssmemb na ss2))
                  (setq ss2 (ssadd na ss2))
                );if
                (setq n (+ n 1));setq
               );repeat
            );progn then combine the previously gripped stuff with
                      ;the selection set returned from fastsel
          );if
          (sssetfirst ss2 ss2)

         );progn else just set a grip-ed selection set.
         (princ "\n没有找到")
   );if
    );progn else
);if

(setq *error* old_err)
(princ "\n现存的快速选择")
(princ)
);defun c:fastsel


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:fs ()
(c:fastsel)
);defun c:fs

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:fsmode ( / old_err fsmode )
(setq old_err *error*)
(defun *error* ( a / )
(princ a)
(setq *error* old_err)
(princ)
);defun

(fsmode_init)
(initget "ON OFf")
(if (setq fsmode (getkword (strcat "\nFASTSEL链选择 <" #fsmode ">: ")));setq
    (progn
   (setq #fsmode (xstrcase fsmode))
   (setenv "BNS_FSMODE" #fsmode)
    );progn then
);if

(setq *error* old_err)
(princ)
);defun c:fsmode

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun fsmode_init ()
(if (not #fsmode)
   (setq #fsmode (getenv "BNS_FSMODE"))
);if
(if (and (not (equal "ON" #fsmode))
          (not (equal "OFF" #fsmode))
   );and
   (progn
      (setq #fsmode "OFF");setq
      (setenv "BNS_FSMODE" #fsmode)
   );progn then
);if
);defun fsmode_init

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun fastsel ( / flt na fsmode lst2 ss px px2 z j lst a b lst3 lst4
                     n c d ss2 ss4 ss5
               )

(setq    flt '(
                (0 . "LINE") (0 . "POLYLINE") (0 . "LWPOLYLINE") (0 . "CIRCLE")
                (0 . "ARC") (0 . "ATTDEF") (0 . "TEXT") (0 . "MTEXT")
                (0 . "ELLIPSE") (0 . "IMAGE") (0 . "SPLINE") (0 . "POINT")
                (0 . "INSERT") (0 . "3DFACE") (0 . "TRACE") (0 . "SOLID")
            )
          na (bns_fast_sel "\n选择接触的对象: " flt)
         flt (append '((-4 . "<OR")) flt '((-4 . "OR>")))
      fsmode "ON"
);setq
(if na
    (progn
   (setqlst2 (list na)
            ss (ssadd na (ssadd))
            px (acet-geom-pixel-unit)
             px2 (* px 0.75)
               z 0
               j 0
   );setq
   (while (and (< j (length lst2))
               (equal fsmode "ON")
            );and
      (setq fsmode #fsmode)
      (setq na (nth j lst2));setq
      (setqlst (acet-list-remove-adjacent-dups (acet-geom-object-point-list na (/ px 2.0)))
               a (car lst)
               b (cadr lst)
      );setq
      (if b
          (setq lst3 (list (polar a (+ (angle b a) (/ pi 2.0)) px2));list
                lst4 (list (polar a (- (angle b a) (/ pi 2.0)) px2));list
          );setq then
      );if
      (setq n 0)
      (repeat (max 0 (- (length lst) 1))
       (setq a (nth n lst)
             b (nth (+ n 1) lst)
             c (polar b (- (angle a b) (/ pi 2.0)) px2)
             d (polar b (+ (angle a b) (/ pi 2.0)) px2)
       );setq
       (if (not (equal c (last lst3) 0.00001))
         (setq lst3 (append lst3 (list c)));setq then
       );if
       (if (not (equal d (last lst4) 0.00001))
         (setq lst4 (append lst4 (list d)));setq then
       );if
       (setq n (+ n 1));setq
      );repeat
      (setq ss2 (f_on_screen lst flt))
      (setq ss4 (f_on_screen lst3 flt))
      (setq ss5 (f_on_screen lst4 flt))
      (if ss2
          (progn
         (setq n 0)
         (repeat (sslength ss2)
            (setq na (ssname ss2 n))
            (if (not (member na lst2))
                (setq lst2 (append lst2 (list na))
                        ss (ssadd na ss)
                );setq
            );if
            (setq n (+ n 1));setq
         );repeat
          );progn
      );if
      (if ss4
          (progn
         (setq n 0)
         (repeat (sslength ss4)
            (setq na (ssname ss4 n))
            (if (not (member na lst2))
                (progn
               (setq lst2 (append lst2 (list na))
                         ss (ssadd na ss)
               );setq
                );progn then
            );if
            (setq n (+ n 1));setq
         );repeat
          );progn
      );if
      (if ss5
          (progn
         (setq n 0)
         (repeat (sslength ss5)
            (setq na (ssname ss5 n))
            (if (not (member na lst2))
                (progn
               (setq lst2 (append lst2 (list na))
                         ss (ssadd na ss)
               );setq
                );progn then
            );if
            (setq n (+ n 1));setq
         );repeat
          );progn
      );if
      (setq j (+ j 1))
   );while

    );progn then
);if

ss
);defun fastsel



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;select the seed ent.
(defun bns_fast_sel ( msg flt / filter_check na)
;local function
(defun filter_check ( na flt / e1 a n flag)
(cond
   ((not na) (setq flag nil))
   ((not flt) (setq flag T))
   (T
    (setq e1 (entget na));setq
    (setq n 0)
    (while (and (not flag)
                (< n (length flt))
         );and
   (setq a (nth n flt));setq
   (if (member a e1)
         (setq flag T);setq then got a match for the filter
   );if
   (setq n (+ n 1));setq
    );while
   )
);cond close
flag
);defun filter_check

(if (not (equal (substr msg 1 1) "\n"))
    (setq msg (strcat "\n" msg))
);if
(while (not na)
(setvar "errno" 0)
(while (or (and (not (setq na (car (entsel msg))))
               (equal 7 (getvar "errno"))
            );and
            (and na
               (not (filter_check na flt))
            );and
      );or
   (if (equal 7 (getvar "errno"))
       (princ "\n0 found")
       (progn
      (if na
            (princ (strcat "\n*无效* 必须选择 "
                           "直线、多段线、圆、圆弧、属性定义、文字、"
                           "多行文字、椭圆、椭圆弧、或图像对象。\n"
                   );strcat
            );princ
      );if
       );progn
   );if
   (setvar "errno" 0)
);while
(cond
((equal (getvar "errno") 52) ;enter
   (setq na 99);
)
);cond close
);while
(if (equal na 99) (setq na nil))
na
);defun bns_fast_sel

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun fs_get_current_sel ( / ss)
(if (and (equal 1 (getvar "pickfirst"))
         (cadr (ssgetfirst))
    );and
    (setq ss (cadr (ssgetfirst)));then something is already selected so get it.
);if
ss
);defun fs_get_current_sel

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;returns a list of points on screen if the first two lists do not
;contain segments that intersect each other.
;
(defun f_on_screen ( lst flt / vd p1 p2 p3 p4 lst2 lst3 n a b c d
                               x1 x2 x3 x4 pnt j ss ss2 na pnt2 dst dlst
                   )

(setqvd (trans (getvar "viewdir") 1 0 T)
       p1 (acet-geom-m-trans (acet-geom-view-points) 1 vd)      ;variables p1, p2, p3, andp4 are corner points
       p3 (cadr p1)                     ; of the current view
       p1 (car p1)
       p2 (list (car p3) (cadr p1));list
       p4 (list (car p1) (cadr p3));list
      dst (distance (getvar "extmin") (getvar "extmax"))
      lst (acet-geom-m-trans lst 1 vd)
      a (car lst)               ;the first point in lst expressed in view coords.
      c (list (car a) (cadr a))
);setq

(if (and (<= (car c) (car p3))    ;if the first point is on screen then add it to lst2
         (<= (cadr c) (cadr p3))
         (>= (car c) (car p1))
         (>= (cadr c) (cadr p1))
    );and
    (setq lst2 (list a));setq
);if

(setq n 0)
(repeat (max (- (length lst) 1)
             0
      )
(setqa (nth n lst)             ;the first point
      c (list (car a) (cadr a)) ;the same point without the z
      b (nth (+ n 1) lst)       ;the second point
      d (list (car b) (cadr b)) ;ditto with no z
       x1 (inters p1 p2 c d)      ;check for intersections
       x2 (inters p2 p3 c d)
       x3 (inters p3 p4 c d)
       x4 (inters p4 p1 c d)
);setq
(if (or x1 x2 x3 x4)
   (progn             ;then intersection(s) were found
      (setq dlst nil)   ;Now build a list of sublist containing the
                        ;the distance from the intersecting point to point 'a'
                        ; and 'a' the point it's self.
      (if x1
          (setq dlst (append dlst (list (list (distance x1 c) x1))));setq
      );if
      (if x2
          (setq dlst (append dlst (list (list (distance x2 c) x2))));setq
      );if
      (if x3
          (setq dlst (append dlst (list (list (distance x3 c) x3))));setq
      );if
      (if x4
          (setq dlst (append dlst (list (list (distance x4 c) x4))));setq
      );if
      (setq dlst (acet-list-isort dlst 0)) ;sort the list of sublists based on distance from 'a'
      (setq j 0)
      (repeat (length dlst)                              ;then add them one at a time to lst2
       (setq pnt (nth j dlst)                            ;the sub-list (dist, point)
             pnt (cadr pnt)                              ;the point
             pnt (list (car pnt) (cadr pnt) (* -1.0 dst));now get ready to create a segment
            pnt2 (list (car pnt) (cadr pnt) dst)         ;that is normal to the view and very long
             pnt (inters a b pnt pnt2 nil)               ;check for 3d intersect to get true
                                                         ;location
       );setq
       (if (and pnt
                (not (equal pnt (last lst2)))
         );and
         (setq lst2 (append lst2 (list pnt)));setq
       );if
      (setq j (+ j 1));setq
      );repeat
   );progn then find the intersection closest to a
   (setq dlst nil);else no intersections
);if
(if (and (<= (car d) (car p3))
          (<= (cadr d) (cadr p3))
          (>= (car d) (car p1))
          (>= (cadr d) (cadr p1))
          (not (equal b (last lst2)))
   );and
   (setq lst2 (append lst2 (list b)));setq then
);if
(if dlst
   (progn
      (setq lst2 (acet-geom-m-trans lst2 vd 1)
            lst3 (append lst3 (list lst2))
            lst2 nil
      );setq
      (if (and (<= (car d) (car p3))
               (<= (cadr d) (cadr p3))
               (>= (car d) (car p1))
               (>= (cadr d) (cadr p1))
               (not (equal b (last lst2)))
          );and
          (setq lst2 (append lst2 (list b)));setq then
      );if
   );progn then
);if
(setq n (+ n 1));setq
);repeat
(if (and lst2
         (setq lst2 (acet-geom-m-trans lst2 vd 1))
         (not (member lst2 lst3))
    );and
    (setq lst3 (append lst3 (list lst2)));setq then
);if

(setq ss2 (ssadd))
(setq n 0)
(repeat (length lst3)

(if (and (> (length (nth n lst3)) 1)
         (setq ss (ssget "_f" (nth n lst3) flt));setq
    );and
    (progn

   (setq j 0)
   (repeat (sslength ss)
      (setq na (ssname ss j))
      (if (not (ssmemb na ss2))
          (setq ss2 (ssadd na ss2));setq then
      );if
   (setq j (+ j 1));setq
   );repeat
    );progn
);if
(setq n (+ n 1));setq
);repeat

ss2
);defun f_on_screen


(princ)

chwnin 发表于 2013-10-22 17:31:16

谢谢楼上大哥!!请问如何使用,我的意思是点选一条直线,与它相连(和相连后的直线的的相连直线)所有直线全部选择上。就是递归相连的所有直线。不知我这样解释明白不?

chwnin 发表于 2013-10-22 17:31:50

crazylsp 发表于 2013-10-22 17:10 static/image/common/back.gif
ET工具有一个
    FASTSEL.LSP
;;;    Created 7/21/97 by Randy Kintzley


谢谢楼上大哥!!请问如何使用,我的意思是点选一条直线,与它相连(和相连后的直线的的相连直线)所有直线全部选择上。就是递归相连的所有直线。不知我这样解释明白不?

crazylsp 发表于 2013-10-22 17:39:38

本帖最后由 crazylsp 于 2013-10-22 17:41 编辑

就是你的意思,拾取一个获取相连的所有直线。加载所有fas文件,加载fastsel.lsp文件,都是ET里面的工具,我只是把这个提出来了。

chwnin 发表于 2013-10-22 20:00:51

crazylsp 发表于 2013-10-22 17:39 static/image/common/back.gif
就是你的意思,拾取一个获取相连的所有直线。加载所有fas文件,加载fastsel.lsp文件,都是ET里面的工具,我 ...

大哥谢谢了,我下载了试下,只能选首尾相连的两条,不能递归选下去啊。我的意思是选了1后可以自动选上2345678的

edata 发表于 2013-10-22 20:51:36

如果真的是首尾相连的直线,多段线,用命令pe 选择一条线,转为多段线后,输入j 接着输入all就能全选所有线,直接连接。

chwnin 发表于 2013-10-22 20:57:40

edata 发表于 2013-10-22 20:51 static/image/common/back.gif
如果真的是首尾相连的直线,多段线,用命令pe 选择一条线,转为多段线后,输入j 接着输入all就能全选所有线 ...

不行的,这样只能用1选时只能选到234567,选不到8的,有分支是选不到的

edata 发表于 2013-10-22 21:35:31

chwnin 发表于 2013-10-22 20:57 static/image/common/back.gif
不行的,这样只能用1选时只能选到234567,选不到8的,有分支是选不到的

8算不上首尾相连了。只能算有同一点,你最好将你要实现的功能图解,提供源dwg,对于你说的8,如果是pl线,是要画两次的。

chwnin 发表于 2013-10-22 22:01:11

edata 发表于 2013-10-22 21:35 static/image/common/back.gif
8算不上首尾相连了。只能算有同一点,你最好将你要实现的功能图解,提供源dwg,对于你说的8,如果是pl线, ...

当选择PL线1时,PL线2、3、4、5、6、7能同时选择到。因为我导出的图有几百条多段线,一条条选相连的线太麻烦了,所以要找个快捷的方法,就象这个GIF一样,不过是要多段线 。大哥有办法吗?
http://bbs.mjtd.com/forum.php?mod=attachment&aid=NTg4ODh8ZGRjOGRkYTR8MTM4MjQ1MDI3N3w0MjQ1MzJ8ODY5MTc%3D&noupdate=yes



页: [1] 2
查看完整版本: 请问大家快速选择首尾相连的所有线段,如何用lisp实现啊