<*** 修剪水平線和垂直線 ***>
本帖最后由 lee50310 于 2023-7-17 04:40 编辑<*** 修剪水平線和垂直線***>
執行指令 ttim
功能功能如動圖所示
源碼已分享請在 9樓 下載
本帖最后由 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)
) 本帖最后由 lee50310 于 2023-7-2 06:01 编辑
kzd2004 发表于 2023-7-1 22:34
刚刚测试了一下,非常感谢,目前使用稳定,大佬能否把原码发一下,就是想把命令改成"t2",这样要快些。{:1_1 ...
ok
源碼分享.....
執行指令 ttim
jiman 发表于 2023-7-5 12:39
我也贴一版供大家参考。上几天有网友发帖求这个,再次借楼贴一下供大家参考。
(defun c:TTrim2( / #Vcomec ...
参数类型错误!!!cad2022 谢谢lee50310分享的程序 谢谢分享,这个在什么地方可能需要使用呀。 谢谢楼主分享! 大佬最近要爆发啊 分享了很多好用的插件。 大佬无处不在,更新这么快,感谢分享哦~ 谢谢楼主分享! 本帖最后由 kzd2004 于 2023-7-1 22:38 编辑
刚刚测试了一下,非常感谢,目前使用稳定,大佬能否把原码发一下,就是想把命令改成"t2",这样要快些。{:1_1:} 感谢分享、