乐筑天下

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

[编程交流] lisp中的Trim删除了很多

[复制链接]

13

主题

55

帖子

42

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 15:06:29 | 显示全部楼层 |阅读模式
大家好,
 
我有点确定其他人也有同样的问题,但在搜索这个论坛一个小时后,我找不到解决我问题的方法:
 
在lisp中,我选择2个点来定义一个框架,用这个框架我想修剪通过这个框架的所有元素。之后,我删除了框架内所有没有超过它的对象和框架本身。
 
但是,如果一条线穿过帧两次,不仅环绕部分,有时也会删除帧外的剩余长度。
 
当一行一行地做的时候,看起来框架也被修剪了,所以只剩下一条边,但在我的理解中,我不应该在我的修剪对象列表中有这些元素
 
 
有人知道我如何避免这个问题吗?
 
 
 
我将把代码复制到下面:
 
  1. (initget "Yes No")
  2.        (setq ans (getkword "\nDo you want to delete objects obviously not to be imported? [Yes/No]?: "))
  3.        (while (= ans "Yes")                                                                    ;While user decide YES
  4.            (progn                                                                                 ;Commands to run
  5.                (prompt "\nSelect objects by window")                                            ;Tells user what to do
  6.                (setq P1 (getpoint "\nFirst Corner: "))                                            ;Pick first corner
  7.                (setq P2 (getpoint "\nSecond Corner: "))                                        ;Pick second corner
  8.                (setq P3 (list (nth 0 P2)(nth 1 P1)))                                            ;Create additional point for frame
  9.                (setq P4 (list (nth 0 P1)(nth 1 P2)))                                            ;Create additional point for frame
  10.                (setq P5 (list (/ (+ (nth 0 P1)(nth 0 P2)) 2)(/ (+ (nth 1 P1)(nth 1 P2)) 2)))    ;Select point in middle of frame
  11.                (command "_Pline" P1 P3 P2 P4 "_c")                                                ;Create frame
  12.                (setq tmp (entlast))                                                            ;Select created frame
  13.                (setq P6 (list (- (nth 0 P1)0.1)(- (nth 1 P1)0.1)))                                ;define points inside of the frame as selection for trim
  14.                (setq P7 (list (- (nth 0 P2)0.1)(- (nth 1 P2)0.1)))                                ;define points inside of the frame as selection for trim
  15.                (setq tbe (ssget "_C" P6 P7))                                                    ;Select objects touching the frame (tbe)
  16.                (command "_Trim" tmp "")                                                        ;Open trim command
  17.                (setq ct -1)                                                                    ;reset counter
  18.                (repeat (sslength tbe)                                                            ;run through all objects in tbe selection
  19.                    (command(list(ssname tbe (setq ct (1+ ct))) P5))                            ;Fill required prompts for trim command
  20.                )                                                                                ;End of repeat
  21.                (command "")                                                                    ;Leave trim function
  22.                (command "._Erase" tmp "")                                                        ;Remove Frame
  23.                (princ)                                                                            ;
  24.                (setq ct -1)                                                                    ;Reset counter
  25.                (setq tbe nil)                                                                    ;Reset list tbe
  26.                (setq tbe (ssget "_W" P1 P2))                                                    ;Select all objects in the Window opened by P1 and P2
  27.                (command "._Erase" tbe "")                                                        ;Delete former selected objects
  28.                (setq tbe nil)                                                                    ;Reset list tbe
  29.                (vla-zoomextents (vlax-get-acad-object))                                        ;Zoom Extents
  30.                (initget "Yes No")                                                                ;Allow user input
  31.                (setq ans (getkword "\nDo you want to delete more? [Yes/No]?: "))                ;Ask user if more should be deleted
  32.                (if (= ans "No")                                                                ;Start of if, cond. Answer of former question was no
  33.                (setq ans nil)                                                                    ;Set var. ans to nil
  34.                (princ)
  35.                )                                                                                ;end of if
  36.            )                                                                                    ;End of progn
  37.        )                                                                                        ;End of while
  38.        (princ)
  39.        (setq ct -1)   
回复

使用道具 举报

0

主题

946

帖子

978

银币

限制会员

铜币
-3
发表于 2022-7-5 15:11:41 | 显示全部楼层
 
 
 
 
该代码还选择了pline和pline之外的一些对象。如果P6是左下角,则应为
 
  1. (setq P6 (list (+ (nth 0 P1)0.1)(+ (nth 1 P1)0.1)))                                  ;define points inside of the frame as selection for trim

您应该询问左下角和右上角,或者比较坐标以检查哪个是左下角。左下角则始终为+
回复

使用道具 举报

13

主题

55

帖子

42

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 15:13:16 | 显示全部楼层
嗯,如果这能解决问题,我会很高兴的。
 
 
 
我现在修改了lisp,如下所示:
 
  1. (initget "Yes No")
  2.        (setq ans (getkword "\nDo you want to delete objects obviously not to be imported? [Yes/No]?: "))
  3.        (while (= ans "Yes")                                                                    ;While user decide YES
  4.            (progn                                                                                 ;Commands to run
  5.                (prompt "\nSelect objects by window")                                            ;Tells user what to do
  6.                (setq P1 (getpoint "\nFirst Corner: "))                                            ;Pick first corner
  7.                (setq P2 (getpoint "\nSecond Corner: "))                                        ;Pick second corner
  8.                (setq P3 (list (nth 0 P2)(nth 1 P1)))                                            ;Create additional point for frame
  9.                (setq P4 (list (nth 0 P1)(nth 1 P2)))                                            ;Create additional point for frame
  10.                (setq P5 (list (/ (+ (nth 0 P1)(nth 0 P2)) 2)(/ (+ (nth 1 P1)(nth 1 P2)) 2)))    ;Select point in middle of frame
  11.                (command "_Pline" P1 P3 P2 P4 "_c")                                                ;Create frame
  12.                (setq tmp (entlast))                                                            ;Select created frame
  13.                
  14.                                                                                                ;Identify point positions left/right & up/dn
  15.                (setq xp1 (nth 0 P1))                                                            ;set xp1 as x coord of P1
  16.                (setq xp2 (nth 0 P2))                                                            ;set xp2 as x coord of P2
  17.                (setq yp1 (nth 1 P1))                                                            ;set yp1 as y coord of P1
  18.                (setq yp2 (nth 1 P2))                                                            ;set yp2 as y coord of P2
  19.                (if (< xp1 xp2)                                                                    ;check x relative and set values
  20.                    (progn
  21.                        (setq xp6 (+ xp1 1))
  22.                        (setq xp7 (- xp2 1))
  23.                    )
  24.                    (progn
  25.                        (setq xp6 (- xp1 1))
  26.                        (setq xp7 (+ xp2 1))
  27.                    )
  28.                )
  29.                (if (< yp1 yp2)                                                                    ;check y relative and set values
  30.                    (progn
  31.                        (setq yp6 (+ yp1 1))
  32.                        (setq yp7 (- yp2 1))
  33.                    )
  34.                    (progn
  35.                        (setq yp6 (- yp1 1))
  36.                        (setq yp7 (+ yp2 1))
  37.                    )
  38.                )   
  39.                (setq P6 (list xp6 yp6))                                ;define points inside of the frame as selection for trim
  40.                (setq P7 (list xp7 yp7))                                ;define points inside of the frame as selection for trim
  41.                (setq tbe (ssget "_C" P6 P7))                                                    ;Select objects touching the frame (tbe)
  42.                (command "_Trim" tmp "")                                                        ;Open trim command
  43.                (setq ct -1)                                                                    ;reset counter
  44.                (repeat (sslength tbe)                                                            ;run through all objects in tbe selection
  45.                    (command(list(ssname tbe (setq ct (1+ ct))) P5))                            ;Fill required prompts for trim command
  46.                )                                                                                ;End of repeat
  47.                (command "")                                                                    ;Leave trim function
  48.                (command "._Erase" tmp "")                                                        ;Remove Frame
  49.                (princ)                                                                            ;
  50.                (setq ct -1)                                                                    ;Reset counter
  51.                (setq tbe nil)                                                                    ;Reset list tbe
  52.                (setq tbe (ssget "_W" P1 P2))                                                    ;Select all objects in the Window opened by P1 and P2
  53.                (command "._Erase" tbe "")                                                        ;Delete former selected objects
  54.                (setq tbe nil)                                                                    ;Reset list tbe
  55.                (vla-zoomextents (vlax-get-acad-object))                                        ;Zoom Extents
  56.                (initget "Yes No")                                                                ;Allow user input
  57.                (setq ans (getkword "\nDo you want to delete more? [Yes/No]?: "))                ;Ask user if more should be deleted
  58.                (if (= ans "No")                                                                ;Start of if, cond. Answer of former question was no
  59.                (setq ans nil)                                                                    ;Set var. ans to nil
  60.                (princ)
  61.                )                                                                                ;end of if
  62.            )                                                                                    ;End of progn
  63.        )                                                                                        ;End of while
  64.        (princ)
  65.        (setq ct -1)   

 
 
不幸的是,它没有解决这个问题。经过更多的测试,如果我把一条线的中心点用框架围起来,它看起来工作得很好,但只要它只在线上切了一个接近的开口,而没有围起来中间点,它就会删除整个剩余部分,包括框架外的部分
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 15:18:43 | 显示全部楼层
主题上的变体您可以向内偏移外部pline少量,并在选择修剪切割对象时使用entlast,这将修剪所有对象,然后作为第二步,使用带擦除的WP获得留下的任何对象。
回复

使用道具 举报

13

主题

55

帖子

42

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 15:20:19 | 显示全部楼层
当然,抵消会有所帮助。没有想过。但是对于P6和P7点,我做的差不多。如果它只是闯入一条线,而不修剪它的整个末端
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 15:24:12 | 显示全部楼层
如果将切割器设置为原始柱脚线,然后使用偏移柱脚线作为使用点的“围栏”选项,它将向右修剪回原始柱脚线,并且不会留下一点点位。然后,您可以将内部pline与“多边形内”选项结合使用来擦除剩余的任何内容。
回复

使用道具 举报

0

主题

946

帖子

978

银币

限制会员

铜币
-3
发表于 2022-7-5 15:27:32 | 显示全部楼层
 
 
我不确定,但我认为trim命令的一部分需要在while循环中。
 
 
  1. (setq ct -1)                                ;reset counter
  2. (command "_Trim" tmp "")              ;Open trim command
  3. (while (= (getvar 'cmdactive) 1 )
  4.    (repeat (sslength tbe)
  5.      (command (list(ssname tbe (setq ct (1+ ct))) P5))
  6.    )
  7.    (command "")  ;Leave trim function
  8. );end_while
回复

使用道具 举报

13

主题

55

帖子

42

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 15:29:59 | 显示全部楼层
我试着在循环中运行它,但什么都没有改变。这太令人沮丧了。它似乎只是在框的一个边缘而不是在两个界限之间修剪线条。。
回复

使用道具 举报

13

主题

55

帖子

42

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 15:34:14 | 显示全部楼层
大家好,谢谢你们的帮助。特别是德拉诺思指出了我的报价错误。
 
如果有人有什么办法可以解决我的线在被删除之前两边都没有断开的问题,请给我一个提示。不幸的是,最初的问题没有得到解决。
回复

使用道具 举报

0

主题

946

帖子

978

银币

限制会员

铜币
-3
发表于 2022-7-5 15:37:10 | 显示全部楼层
阿门特,
 
我发现了一些代码,我用来修剪其他两行之间的行,并对其进行了调整以满足您的需要。您的大部分代码保持不变,但我已将创建框架替换为矩形命令。
 
我还稍微改变了程序流程。它首先完全删除帧内的任何对象,以避免任何修剪错误。然后修剪穿过帧的对象。这一点已经改变,因此它可以循环选择集,并分别修剪每个实体。我想问题就在这里的某个地方。这可能需要更长的时间,但比手工操作要好。
 
之后,它再次搜索修剪留下的帧内的任何对象,并将其删除。
 
我已经将其放入函数中进行测试。2012年对我来说很有效。
您应该能够将其插回原始函数中
 
  1. (defun c:ttest ( / )
  2.               (setq P1 (getpoint "\nFirst Corner: "))                                    ;Pick first corner
  3.                (setq P2 (getpoint "\nSecond Corner: "))                                  ;Pick second corner
  4.                (setq P3 (list (/ (+ (car p1) (car p2)) 2) (/ (+ (cadr p1) (cadr p2)) 2)));THIS IS MIDDLE OF RECTANGLE
  5.                (setq ct -1)
  6.                (setq tbe (ssget "_W" P1 P2))                                             ;Select all objects in the Window opened by P1 and P2
  7.                (repeat (sslength tbe)                                                    ;run through all objects in tbe selection
  8.                  (setq ent (ssname tbe (setq ct (1+ ct))))                              
  9.                  (vl-cmdf "._Erase" ent "")                                              ;DELETE EVERY ENTITY THAT WON'T BE TRIMMED TO AVOID TRIM ERROR
  10.                );End of repeat
  11.                (setq tbe nil)
  12.                (command "_rectangle" P1 P2)                                              ;Create frame
  13.                (setq tmp (entlast))                                                      ;Select created frame                                                                                                               ;Identify point positions left/right & up/dn
  14.                (setq xp1 (nth 0 P1))                                                     ;set xp1 as x coord of P1
  15.                (setq xp2 (nth 0 P2))                                                     ;set xp2 as x coord of P2
  16.                (setq yp1 (nth 1 P1))                                                     ;set yp1 as y coord of P1
  17.                (setq yp2 (nth 1 P2))                                                     ;set yp2 as y coord of P2
  18.                (if (< xp1 xp2)                                                           ;check x relative and set values
  19.                    (progn
  20.                        (setq xp6 (+ xp1 1.0))
  21.                        (setq xp7 (- xp2 1.0))
  22.                    )
  23.                    (progn
  24.                        (setq xp6 (- xp1 1.0))
  25.                        (setq xp7 (+ xp2 1.0))
  26.                    )
  27.                )
  28.                (if (< yp1 yp2)                                                           ;check y relative and set values
  29.                    (progn
  30.                        (setq yp6 (+ yp1 1.0))
  31.                        (setq yp7 (- yp2 1.0))
  32.                    )
  33.                    (progn
  34.                        (setq yp6 (- yp1 1.0))
  35.                        (setq yp7 (+ yp2 1.0))
  36.                    )
  37.                )
  38.                
  39.                (setq P6 (list xp6 yp6))                                ;define points inside of the frame as selection for trim
  40.                (setq P7 (list xp7 yp7))                                ;define points inside of the frame as selection for trim
  41.                (setq tbe (ssget "_C" P6 P7))                           ;Select objects crossing the frame
  42.                (setq ct -1)                                            ;reset counter
  43.                (repeat (sslength tbe)                                  ;run through all objects in tbe selection
  44.                  (setq ent (ssname tbe (setq ct (1+ ct)))              ;get name of entity
  45.                        pp (vlax-curve-getClosestPointTo ent p3)        ;get closest point of entity to mid pt of frame
  46.                  )
  47.                  (vl-cmdf "_.trim" tmp "" (nentselp pp) "")            ;trim entity by selecting it using (nentselp) where pp is the closest point inside frame
  48.                );End of repeat
  49.                (command "._Erase" tmp "")                              ;erase Frame
  50.                (setq ct -1)                                            ;Reset counter
  51.                (setq tbe nil)                                          ;clear selection set
  52.                (setq tbe (ssget "_W" P1 P2))                           ;Select any entities left behind by trim
  53.                (repeat (sslength tbe)                                  ;run through all objects in tbe selection
  54.                  (setq ent (ssname tbe (setq ct (1+ ct))))             ;get entity name
  55.                  (vl-cmdf "._Erase" ent "")                            ;erase entity
  56.                );End of repeat
  57.                (setq tbe nil)                                          ;Reset list tbe
  58. );end_defun  
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-15 00:49 , Processed in 2.775735 second(s), 72 queries .

© 2020-2025 乐筑天下

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