本帖最后由 wjlaugh 于 2019-11-14 11:27 编辑
本人初学Lisp,写了个小程序,由于工作需要,希望能批量打断交叉管线。但是现在程序执行结果只能打断局部的交叉管线,还请各位大神帮忙看下是哪边有问题。已经成功循环打断
- (vl-load-com)
- (defun c:GDDX ()
- (setvar "cmdecho" 0)
- (setq osmtmp (getvar "osmode"))
- (setvar "osmode" 0)
- (print "框选路灯管线:")
- (setq gxld (ssget '((8 . "GX-路灯") (100 . "AcDbPolyline"))));提取路灯管线
- (print "框选通信管线:")
- (setq gxtx (ssget '((8 . "GX-通信") (100 . "AcDbPolyline"))));提取通信管线
- (setq nld 0)
- (setq of 0.5);设置打断距离0.5
- (while (ssname gxld nld);打断与路灯交叉的通信管线
- (setq entgxld (ssname gxld nld))
- (setq e1 (vlax-ename->vla-object entgxld))
- (setq nld (1+ nld))
- (setq ntx 0);重新循环选取通信管线
- (while (ssname gxtx ntx)
- (setq entgxtx (ssname gxtx ntx))
- (setq e2 (vlax-ename->vla-object entgxtx))
- (setq jiaochadian (acet-geom-intersectwith entgxld entgxtx 0));所获得坐标((6996.58 -537.511 0.0)),需要car提取出(6996.58 -537.511 0.0)
- (if jiaochadian
- (progn
- (vla-offset e1 of)
- (setq tmpl1 (entlast))
- (vla-offset e1 (* of -1))
- (setq tmpl2 (entlast))
- (setq tmpjcd1 (acet-geom-intersectwith entgxtx tmpl1 0)
- tmpjcd2 (acet-geom-intersectwith entgxtx tmpl2 0))
- (setq line1 (list entgxtx (car jiaochadian)));返回图原名和坐标值,与entsel返回值类似,以用于打断时选中多段线
- (command "break" line1 "f" (list (car (car tmpjcd1)) (cadr (car tmpjcd1))) (list (car (car jiaochadian)) (cadr (car jiaochadian))));打断命令需要二维坐标
- (ssadd (entlast) gxtx);将打断生成的新通信管线加入通信管线选择集合
- (setq entgxtxtmp (entlast));获取打断生成的新通信管线
- (setq line2 (list entgxtxtmp (car jiaochadian)))
- (command "break" line1 "f" (list (car (car tmpjcd2)) (cadr (car tmpjcd2))) (list (car (car jiaochadian)) (cadr (car jiaochadian))))
- (entdel tmpl1)
- (entdel tmpl2)
- )
- )
- (setq ntx (1+ ntx))
- )
- )
- )
- (setvar "osmode" osmtmp)
- (princ)
- )
|