;可以闭合了
(defun c:aa (/ dit1 dit2 ss len i ent
enttype objs a2 a1 ssj b1 b2
a1coordlist a2coordlist
) ; 定义程序名和局部变量
(command "_.undo" "begin") ; 开始撤销组
(setvar 'osmode 0) ; 取消捕捉模式
(command "layer" "m" "wall" "c" "6" "wall" "lt" "continuous" "wall" "")
; 设置图层
(setq dit1 500
dit2 (* -1 500)
ss (ssget '((0 . "LINE,LWPOLYLINE")))
) ; 设置偏移距离和选择集
(if ss ; 如果有选择集
(progn
(setq len (sslength ss)
i 0
ssj (ssadd)
) ; 获取选择集中实体的数量
(while (< i len) ; 遍历选择集中的实体
(setq ent (ssname ss i)
enttype (cdr (assoc 0 (entget ent)))
) ; 获取实体名和类型
(if (= enttype "LWPOLYLINE") ; 如果实体是多段线
(progn
(setq objs (vlax-ename->vla-object ent))
; 将实体转换为vla-object
(vlax-invoke objs 'offset dit1)
(setq a1 (entlast)) ; 内偏移得到A1
(setq ssj (ssadd a1 ssj))
(vlax-invoke objs 'offset dit2)
(setq a2 (entlast)) ; 外偏移得到A2
(setq ssj (ssadd a2 ssj))
(if a2 ; 如果A2存在
(progn
(setq a1coordlist (vlax-get (vlax-ename->vla-object a1)
'Coordinates
)
a2coordlist (vlax-get (vlax-ename->vla-object a2)
'Coordinates
)
)
(command "pline"
(list (nth 0 a1coordlist) (nth 1 a1coordlist))
(list (nth 0 a2coordlist) (nth 1 a2coordlist))
""
)
(setq b1 (entlast))
(setq ssj (ssadd b1 ssj))
(command
"pline"
(list (nth (- (length a1coordlist) 2) a1coordlist)
(last a1coordlist)
)
(list (nth (- (length a2coordlist) 2) a2coordlist)
(last a2coordlist)
)
""
)
(setq b2 (entlast))
(setq ssj (ssadd b2 ssj))
(command "pedit" "m" ssj "" "j" "" "")
)
)
(vlax-release-object objs) ; 释放vla-object
)
)
(setq i (1+ i)) ; 遍历下一个实体
)
(sssetfirst nil ss) ; 清除选择集
(princ "处理完成!") ; 输出处理完成
)
(alert "未选择任何线或多段线!") ; 如果没有选择集,输出提示
)
(setvar "clayer" "0")
(command ".undo" "_end") ; 结束撤销组
(princ "") ; 输出空白
) 还是找本书来系统学习循序渐进好些 这个工具作为辅助 能写成这样,这个工具的确厉害
页:
[1]