ZYX2129
发表于 2023-7-2 16:08:49
感谢分享感谢分享
loveu515
发表于 2023-7-2 16:58:56
感谢lee分享源码
pyj643921
发表于 2023-7-4 08:55:14
感谢大佬的分享.
jiman
发表于 2023-7-5 12:39:19
本帖最后由 jiman 于 2023-7-5 12:47 编辑
我也贴一版供大家参考。上几天有网友发帖求这个,再次借楼贴一下供大家参考。
(defun c:TTrim2( / #Vcomecho startPt endPt ss horizEntList vertEntList startTempValue endTempValue ssLen borderHorizLine1 borderHorizLine2 tempEnt borderVertLine1 borderVertLine2 tempPt1 tempPt2 iTempValue1 TempValue2)
(setq #Vcomecho (getvar "cmdecho"))
(setq #Vosmode (getvar "osmode")) ;获取捕捉对象的系统变量
(setvar "cmdecho" 0)
(setvar "osmode" 0) ;设置不捕捉
(setq startPt(getpoint "框选起点\n"))
(setq endPt(getcorner startPt "框选终点\n"))
(setq ss(ssget "_C" startPt endPt(list(cons 0 "LINE"))))
(setq horizEntList '()) ;水平直线的表集合
(setq vertEntList '()) ;竖直直线的表集合
(setq startTempValue 0)
(setq endTempValue 0)
(setq i 0)
(if (/= ss nil)
(progn
(setq ssLen(sslength ss))
;将所选直线分类为水平和竖直,放置两个表中
(while (< i ssLen)
(setq startTempValue (cadr(assoc 10(entget (ssname ss i)))))
(setq endTempValue (cadr(assoc 11(entget (ssname ss i)))))
(if (= startTempValue endTempValue) (setq vertEntList (cons (ssname ss i) vertEntList)) (setq horizEntList (cons (ssname ss i) horizEntList)))
(setq i (+ i 1))
)
;判断直线数量,少于2条则退出程序
(cond
( (< (length horizEntList) 2)
(progn
(alert "框选的水平和竖直线都不能少于2条!")
(setvar "cmdecho" #Vcomecho)
(setvar "osmode" #Vosmode)
(quit)
)
)
( (< (length vertEntList) 2)
(progn
(alert "框选的水平和竖直线都不能少于2条!")
(setvar "cmdecho" #Vcomecho)
(setvar "osmode" #Vosmode)
(quit)
)
)
)
;获取水平边界线
(setq borderHorizLine1 (nth 0 horizEntList))
(setq borderHorizLine2 (nth 0 horizEntList))
(foreach tempEnt horizEntList
(if (< (caddr(assoc 10 (entget borderHorizLine1)) ) (caddr(assoc 10 (entget tempEnt))))
(setq borderHorizLine1 tempEnt)
)
(if (> (caddr(assoc 10 (entget borderHorizLine2)) ) (caddr(assoc 10 (entget tempEnt))))
(setq borderHorizLine2 tempEnt)
)
)
;获取竖直边界线
(setq borderVertLine1 (nth 0 vertEntList))
(setq borderVertLine2 (nth 0 vertEntList))
(foreach tempEnt vertEntList
(if (> (cadr(assoc 10 (entget borderVertLine1)) ) (cadr(assoc 10 (entget tempEnt))))
(setq borderVertLine1 tempEnt)
)
(if (< (cadr(assoc 10 (entget borderVertLine2)) ) (cadr(assoc 10 (entget tempEnt))))
(setq borderVertLine2 tempEnt)
)
)
;剪裁;通过计算赋值,排除窗交的点处于框选的直线上从而导致剪裁失效
(if (> (cadr endPt) (cadr startPt) )
(progn
(setq i 0)
(while (< i (length vertEntList))
(if (< ( abs (- (cadr (cdr (assoc 10 (entget (nth i vertEntList)))) ) (cadr (cdr (assoc 10 (entget borderHorizLine1)) ) )) )(abs (- (cadr (cdr (assoc 10 (entget (nth i vertEntList)))) ) (cadr (cdr (assoc 10 (entget borderHorizLine2)) ) )) ))
(entmakex (list (cons 0 "LINE") (assoc 10 (entget (nth i vertEntList))) (list 11 (car (cdr (assoc 10 (entget (nth i vertEntList)))) ) (cadr (cdr (assoc 10 (entget borderHorizLine1)) ) ) 0)) )
(entmakex (list (cons 0 "LINE")(assoc 10 (entget (nth i vertEntList))) (list 11 (car (cdr (assoc 10 (entget (nth i vertEntList)))) ) (cadr (cdr (assoc 10 (entget borderHorizLine2)) ) ) 0)) )
)
(if (< ( abs (- (cadr (cdr (assoc 11 (entget (nth i vertEntList)))) ) (cadr (cdr (assoc 10 (entget borderHorizLine1)) ) )) )(abs (- (cadr (cdr (assoc 11 (entget (nth i vertEntList)))) ) (cadr (cdr (assoc 10 (entget borderHorizLine2)) ) )) ))
(entmakex (list (cons 0 "LINE")(assoc 11 (entget (nth i vertEntList))) (list 10 (car (cdr (assoc 10 (entget (nth i vertEntList)))) ) (cadr (cdr (assoc 10 (entget borderHorizLine1)) ) ) 0)) )
(entmakex (list (cons 0 "LINE")(assoc 11 (entget (nth i vertEntList))) (list 10 (car (cdr (assoc 10 (entget (nth i vertEntList)))) ) (cadr (cdr (assoc 10 (entget borderHorizLine2)) ) ) 0)) )
)
(entdel (nth i vertEntList))
(setq i (+ i 1))
)
)
(progn
(setq i 0)
(while (< i (length horizEntList))
(if (< ( abs (- (car (cdr (assoc 10 (entget (nth i horizEntList)))) ) (car (cdr (assoc 10 (entget borderVertLine1)) ) )) )(abs (- (car (cdr (assoc 10 (entget (nth i horizEntList)))) ) (cadr (cdr (assoc 10 (entget borderVertLine2)) ) )) ))
(entmakex (list (cons 0 "LINE")(assoc 10 (entget (nth i horizEntList))) (list 11 (car (cdr (assoc 10 (entget borderVertLine1))) ) (cadr (cdr (assoc 10 (entget (nth i horizEntList))) ) ) 0)) )
(entmakex (list (cons 0 "LINE")(assoc 10 (entget (nth i horizEntList))) (list 11 (car (cdr (assoc 10 (entget borderVertLine2))) ) (cadr (cdr (assoc 10 (entget (nth i horizEntList))) ) ) 0)) )
)
(if (< ( abs (- (car (cdr (assoc 11 (entget (nth i horizEntList)))) ) (cadr (cdr (assoc 10 (entget borderVertLine1)) ) )) )(abs (- (cadr (cdr (assoc 11 (entget (nth i horizEntList)))) ) (cadr (cdr (assoc 10 (entget borderVertLine2)) ) )) ))
(entmakex (list (cons 0 "LINE") (cons 10 (cdr (assoc 11 (entget (nth i horizEntList))))) (list 11 (car (cdr (assoc 10 (entget borderVertLine1))) ) (cadr (cdr (assoc 10 (entget (nth i horizEntList) )) ) ) 0)) )
(entmakex (list (cons 0 "LINE") (cons 10 (cdr (assoc 11 (entget (nth i horizEntList))))) (list 11 (car (cdr (assoc 10 (entget borderVertLine2))) ) (cadr (cdr (assoc 10 (entget (nth i horizEntList))) ) ) 0)) )
)
(entdel (nth i horizEntList))
(setq i (+ i 1))
)
)
)
)
)
(setvar "cmdecho" #Vcomecho)
(setvar "osmode" #Vosmode)
(princ)
)
蓝盾设计
发表于 2023-7-5 19:52:10
对于矩形封闭线横竖相交修剪,命令无效
lee50310
发表于 2023-7-5 21:20:22
蓝盾设计 发表于 2023-7-5 19:52
对于矩形封闭线横竖相交修剪,命令无效
很抱歉! 程式不支援此種類型(封閉)
longer1000
发表于 2023-7-8 13:40:17
建议增加修建线段长度范围值,扩大适用性
lxl217114
发表于 2023-7-20 10:20:26
谢谢分享好工具,收藏
kzd2004
发表于 2023-7-20 23:19:10
jiman 发表于 2023-7-5 12:39
我也贴一版供大家参考。上几天有网友发帖求这个,再次借楼贴一下供大家参考。
(defun c:TTrim2( / #Vcomec ...
参数类型错误!!!cad2022
decemc
发表于 2023-8-9 11:01:09
CAD2020,用不了