lisp中的Trim删除了很多
大家好,我有点确定其他人也有同样的问题,但在搜索这个论坛一个小时后,我找不到解决我问题的方法:
在lisp中,我选择2个点来定义一个框架,用这个框架我想修剪通过这个框架的所有元素。之后,我删除了框架内所有没有超过它的对象和框架本身。
但是,如果一条线穿过帧两次,不仅环绕部分,有时也会删除帧外的剩余长度。
当一行一行地做的时候,看起来框架也被修剪了,所以只剩下一条边,但在我的理解中,我不应该在我的修剪对象列表中有这些元素
有人知道我如何避免这个问题吗?
我将把代码复制到下面:
(initget "Yes No")
(setq ans (getkword "\nDo you want to delete objects obviously not to be imported? ?: "))
(while (= ans "Yes") ;While user decide YES
(progn ;Commands to run
(prompt "\nSelect objects by window") ;Tells user what to do
(setq P1 (getpoint "\nFirst Corner: ")) ;Pick first corner
(setq P2 (getpoint "\nSecond Corner: ")) ;Pick second corner
(setq P3 (list (nth 0 P2)(nth 1 P1))) ;Create additional point for frame
(setq P4 (list (nth 0 P1)(nth 1 P2))) ;Create additional point for frame
(setq P5 (list (/ (+ (nth 0 P1)(nth 0 P2)) 2)(/ (+ (nth 1 P1)(nth 1 P2)) 2))) ;Select point in middle of frame
(command "_Pline" P1 P3 P2 P4 "_c") ;Create frame
(setq tmp (entlast)) ;Select created frame
(setq P6 (list (- (nth 0 P1)0.1)(- (nth 1 P1)0.1))) ;define points inside of the frame as selection for trim
(setq P7 (list (- (nth 0 P2)0.1)(- (nth 1 P2)0.1))) ;define points inside of the frame as selection for trim
(setq tbe (ssget "_C" P6 P7)) ;Select objects touching the frame (tbe)
(command "_Trim" tmp "") ;Open trim command
(setq ct -1) ;reset counter
(repeat (sslength tbe) ;run through all objects in tbe selection
(command(list(ssname tbe (setq ct (1+ ct))) P5)) ;Fill required prompts for trim command
) ;End of repeat
(command "") ;Leave trim function
(command "._Erase" tmp "") ;Remove Frame
(princ) ;
(setq ct -1) ;Reset counter
(setq tbe nil) ;Reset list tbe
(setq tbe (ssget "_W" P1 P2)) ;Select all objects in the Window opened by P1 and P2
(command "._Erase" tbe "") ;Delete former selected objects
(setq tbe nil) ;Reset list tbe
(vla-zoomextents (vlax-get-acad-object)) ;Zoom Extents
(initget "Yes No") ;Allow user input
(setq ans (getkword "\nDo you want to delete more? ?: ")) ;Ask user if more should be deleted
(if (= ans "No") ;Start of if, cond. Answer of former question was no
(setq ans nil) ;Set var. ans to nil
(princ)
) ;end of if
) ;End of progn
) ;End of while
(princ)
(setq ct -1)
该代码还选择了pline和pline之外的一些对象。如果P6是左下角,则应为
(setq P6 (list (+ (nth 0 P1)0.1)(+ (nth 1 P1)0.1))) ;define points inside of the frame as selection for trim
您应该询问左下角和右上角,或者比较坐标以检查哪个是左下角。左下角则始终为+ 嗯,如果这能解决问题,我会很高兴的。
我现在修改了lisp,如下所示:
(initget "Yes No")
(setq ans (getkword "\nDo you want to delete objects obviously not to be imported? ?: "))
(while (= ans "Yes") ;While user decide YES
(progn ;Commands to run
(prompt "\nSelect objects by window") ;Tells user what to do
(setq P1 (getpoint "\nFirst Corner: ")) ;Pick first corner
(setq P2 (getpoint "\nSecond Corner: ")) ;Pick second corner
(setq P3 (list (nth 0 P2)(nth 1 P1))) ;Create additional point for frame
(setq P4 (list (nth 0 P1)(nth 1 P2))) ;Create additional point for frame
(setq P5 (list (/ (+ (nth 0 P1)(nth 0 P2)) 2)(/ (+ (nth 1 P1)(nth 1 P2)) 2))) ;Select point in middle of frame
(command "_Pline" P1 P3 P2 P4 "_c") ;Create frame
(setq tmp (entlast)) ;Select created frame
;Identify point positions left/right & up/dn
(setq xp1 (nth 0 P1)) ;set xp1 as x coord of P1
(setq xp2 (nth 0 P2)) ;set xp2 as x coord of P2
(setq yp1 (nth 1 P1)) ;set yp1 as y coord of P1
(setq yp2 (nth 1 P2)) ;set yp2 as y coord of P2
(if (< xp1 xp2) ;check x relative and set values
(progn
(setq xp6 (+ xp1 1))
(setq xp7 (- xp2 1))
)
(progn
(setq xp6 (- xp1 1))
(setq xp7 (+ xp2 1))
)
)
(if (< yp1 yp2) ;check y relative and set values
(progn
(setq yp6 (+ yp1 1))
(setq yp7 (- yp2 1))
)
(progn
(setq yp6 (- yp1 1))
(setq yp7 (+ yp2 1))
)
)
(setq P6 (list xp6 yp6)) ;define points inside of the frame as selection for trim
(setq P7 (list xp7 yp7)) ;define points inside of the frame as selection for trim
(setq tbe (ssget "_C" P6 P7)) ;Select objects touching the frame (tbe)
(command "_Trim" tmp "") ;Open trim command
(setq ct -1) ;reset counter
(repeat (sslength tbe) ;run through all objects in tbe selection
(command(list(ssname tbe (setq ct (1+ ct))) P5)) ;Fill required prompts for trim command
) ;End of repeat
(command "") ;Leave trim function
(command "._Erase" tmp "") ;Remove Frame
(princ) ;
(setq ct -1) ;Reset counter
(setq tbe nil) ;Reset list tbe
(setq tbe (ssget "_W" P1 P2)) ;Select all objects in the Window opened by P1 and P2
(command "._Erase" tbe "") ;Delete former selected objects
(setq tbe nil) ;Reset list tbe
(vla-zoomextents (vlax-get-acad-object)) ;Zoom Extents
(initget "Yes No") ;Allow user input
(setq ans (getkword "\nDo you want to delete more? ?: ")) ;Ask user if more should be deleted
(if (= ans "No") ;Start of if, cond. Answer of former question was no
(setq ans nil) ;Set var. ans to nil
(princ)
) ;end of if
) ;End of progn
) ;End of while
(princ)
(setq ct -1)
不幸的是,它没有解决这个问题。经过更多的测试,如果我把一条线的中心点用框架围起来,它看起来工作得很好,但只要它只在线上切了一个接近的开口,而没有围起来中间点,它就会删除整个剩余部分,包括框架外的部分 主题上的变体您可以向内偏移外部pline少量,并在选择修剪切割对象时使用entlast,这将修剪所有对象,然后作为第二步,使用带擦除的WP获得留下的任何对象。 当然,抵消会有所帮助。没有想过。但是对于P6和P7点,我做的差不多。如果它只是闯入一条线,而不修剪它的整个末端 如果将切割器设置为原始柱脚线,然后使用偏移柱脚线作为使用点的“围栏”选项,它将向右修剪回原始柱脚线,并且不会留下一点点位。然后,您可以将内部pline与“多边形内”选项结合使用来擦除剩余的任何内容。
我不确定,但我认为trim命令的一部分需要在while循环中。
(setq ct -1) ;reset counter
(command "_Trim" tmp "") ;Open trim command
(while (= (getvar 'cmdactive) 1 )
(repeat (sslength tbe)
(command (list(ssname tbe (setq ct (1+ ct))) P5))
)
(command "");Leave trim function
);end_while
我试着在循环中运行它,但什么都没有改变。这太令人沮丧了。它似乎只是在框的一个边缘而不是在两个界限之间修剪线条。。 大家好,谢谢你们的帮助。特别是德拉诺思指出了我的报价错误。
如果有人有什么办法可以解决我的线在被删除之前两边都没有断开的问题,请给我一个提示。不幸的是,最初的问题没有得到解决。 阿门特,
我发现了一些代码,我用来修剪其他两行之间的行,并对其进行了调整以满足您的需要。您的大部分代码保持不变,但我已将创建框架替换为矩形命令。
我还稍微改变了程序流程。它首先完全删除帧内的任何对象,以避免任何修剪错误。然后修剪穿过帧的对象。这一点已经改变,因此它可以循环选择集,并分别修剪每个实体。我想问题就在这里的某个地方。这可能需要更长的时间,但比手工操作要好。
之后,它再次搜索修剪留下的帧内的任何对象,并将其删除。
我已经将其放入函数中进行测试。2012年对我来说很有效。
您应该能够将其插回原始函数中
(defun c:ttest ( / )
(setq P1 (getpoint "\nFirst Corner: ")) ;Pick first corner
(setq P2 (getpoint "\nSecond Corner: ")) ;Pick second corner
(setq P3 (list (/ (+ (car p1) (car p2)) 2) (/ (+ (cadr p1) (cadr p2)) 2)));THIS IS MIDDLE OF RECTANGLE
(setq ct -1)
(setq tbe (ssget "_W" P1 P2)) ;Select all objects in the Window opened by P1 and P2
(repeat (sslength tbe) ;run through all objects in tbe selection
(setq ent (ssname tbe (setq ct (1+ ct))))
(vl-cmdf "._Erase" ent "") ;DELETE EVERY ENTITY THAT WON'T BE TRIMMED TO AVOID TRIM ERROR
);End of repeat
(setq tbe nil)
(command "_rectangle" P1 P2) ;Create frame
(setq tmp (entlast)) ;Select created frame ;Identify point positions left/right & up/dn
(setq xp1 (nth 0 P1)) ;set xp1 as x coord of P1
(setq xp2 (nth 0 P2)) ;set xp2 as x coord of P2
(setq yp1 (nth 1 P1)) ;set yp1 as y coord of P1
(setq yp2 (nth 1 P2)) ;set yp2 as y coord of P2
(if (< xp1 xp2) ;check x relative and set values
(progn
(setq xp6 (+ xp1 1.0))
(setq xp7 (- xp2 1.0))
)
(progn
(setq xp6 (- xp1 1.0))
(setq xp7 (+ xp2 1.0))
)
)
(if (< yp1 yp2) ;check y relative and set values
(progn
(setq yp6 (+ yp1 1.0))
(setq yp7 (- yp2 1.0))
)
(progn
(setq yp6 (- yp1 1.0))
(setq yp7 (+ yp2 1.0))
)
)
(setq P6 (list xp6 yp6)) ;define points inside of the frame as selection for trim
(setq P7 (list xp7 yp7)) ;define points inside of the frame as selection for trim
(setq tbe (ssget "_C" P6 P7)) ;Select objects crossing the frame
(setq ct -1) ;reset counter
(repeat (sslength tbe) ;run through all objects in tbe selection
(setq ent (ssname tbe (setq ct (1+ ct))) ;get name of entity
pp (vlax-curve-getClosestPointTo ent p3) ;get closest point of entity to mid pt of frame
)
(vl-cmdf "_.trim" tmp "" (nentselp pp) "") ;trim entity by selecting it using (nentselp) where pp is the closest point inside frame
);End of repeat
(command "._Erase" tmp "") ;erase Frame
(setq ct -1) ;Reset counter
(setq tbe nil) ;clear selection set
(setq tbe (ssget "_W" P1 P2)) ;Select any entities left behind by trim
(repeat (sslength tbe) ;run through all objects in tbe selection
(setq ent (ssname tbe (setq ct (1+ ct)))) ;get entity name
(vl-cmdf "._Erase" ent "") ;erase entity
);End of repeat
(setq tbe nil) ;Reset list tbe
);end_defun
页:
[1]
2