首页 新闻 会员 周边

lisp语言编写特性匹配

0
悬赏园豆:60 [待解决问题]

用lisp语言编写特性匹配,所刷线段自动打断线相交的点和块相交的点。
一根线段上有很多图快,也有很多相交的线段,用特性匹配相交线或图快和线相交的中间线段时,所刷线段两边的各种交点处自动断开。求源代码!谢谢!

榨菜人生的主页 榨菜人生 | 初学一级 | 园豆:142
提问于:2023-06-12 19:35
< >
分享
所有回答(1)
0

以下是一个示例的Lisp代码,用于根据特性匹配断开线段上与图块或相交线段相交的点:

lisp
Copy code
(defun break-line-at-intersections (line entities / intersections)
(setq intersections (ssget "_X" '((0 . "INSERT,LINE")))) ; 获取所有图块和线段的选择集

(if (and line (> (sslength intersections) 0))
(progn
(command "_.undo" "_begin") ; 开始撤销操作

  (setq i 0)
  (while (< i (sslength intersections))
    (setq ent (ssname intersections i))
    (setq type (cdr (assoc 0 (entget ent))))

    (cond
      ; 处理图块
      ((= type "INSERT")
        (setq block (cdr (assoc 2 (entget ent)))) ; 获取图块名
        (setq vertices (get-entity-vertices ent))
        (break-line-at-vertices line vertices))
      
      ; 处理线段
      ((= type "LINE")
        (setq vertices (get-entity-vertices ent))
        (break-line-at-vertices line vertices)))

    (setq i (1+ i)))
  
  (command "_.undo" "_end") ; 结束撤销操作
  )
)

)

(defun get-entity-vertices (entity / vertices)
(setq vertices '())
(setq ent (entget entity))

(while (setq v (assoc 10 ent))
(setq vertices (cons (cdr v) vertices))
(setq ent (entnext ent))
)

(reverse vertices))

(defun break-line-at-vertices (line vertices)
(setq i 0)
(while (< i (length vertices))
(setq v1 (nth i vertices))
(setq v2 (nth (1+ i) vertices))

(command "_.break" line "_f" v1 v2)
(setq i (1+ i))))

; 示例用法
(setq line (car (entsel "\n选择要断开的线段: ")))
(break-line-at-intersections line)
上述代码包含两个主要函数:

break-line-at-intersections:根据特性匹配,将线段与图块或相交线段的相交点处断开。
get-entity-vertices:获取实体的顶点列表。
要使用上述代码,您可以将其复制到Lisp编辑器中(如AutoCAD的Visual LISP编辑器),然后调用(break-line-at-intersections line)函数,其中line是要断开的线段实体的选择集。该代码将遍历相交的图块和线段,找到相交点并将线段在这些点处断开。

请注意,这是一个基本示例,您可能需要根据您的具体需求进行调整和扩展。

Technologyforgood | 园豆:5718 (大侠五级) | 2023-06-12 22:50

本人是初学lisp,您的代码没看太明白,我尝试使用了一下也不行。我就是想我选中的某一条线段然后特性匹配图中的某一条线段(无论是直线或多线段)而且这条线段上有相交的其它线段(直线、多线段或曲线)图快,在匹配的同时这些相交点自动打断。麻烦您给我写一个可以直接使用的CAD插件(源文件)尽可能的都注释一下,我好好好的学习一下。谢谢

支持(0) 反对(0) 榨菜人生 | 园豆:142 (初学一级) | 2023-06-13 13:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册