批量向内或向外偏移
借用了明经里一些大神的代码,自己修改了一下,供大家学习学习。可向外或向内偏移,负数向外,正数向内。带记忆偏移距离。(defun c:gg (/ ss i obj len objlast lenlast en)
(if (not dist0) (setq dist0 30))
(setq dist (getreal (strcat "\n请输入批量偏移距离(负数向外,正数向内)<初始值:"(rtos dist0)">")))
(if (null dist)(setq dist dist0)(setq dist0 dist))
(setq ss (ssget '((0 . "CIRCLE,ARC,LWPOLYLINE"))))
(setq i 0)
(repeat (sslength ss)
(setq obj (vlax-ename->vla-object (ssname ss i)))
(setq len (vlax-curve-getdistatparam obj(vlax-curve-getendparam obj)))
(vla-offset obj 0.00001)
(setq objlast (entlast))
(setq lenlast (vlax-curve-getdistatparam objlast(vlax-curve-getendparam objlast) ))
(entdel objlast)
(cond ((> lenlast len)(progn (vla-offset obj (- dist))
(setq en (entget (entlast)))(entmod (subst (cons 62 8) (assoc 8 en) en))))
((< lenlast len)(progn(vla-offset obj dist)
(setq en (entget (entlast)))(entmod (subst (cons 62 8) (assoc 8 en) en)))) )
(setq i (1+ i)))
(princ))
记得vla-offset的正负,与第一段弧有关系。 这东西是不是很难学 ;;批量偏移 By Gu_xl 2013.04.01
(defun c:py (/ CLOCKWISEP OFFSET KD SS N EN kd0)
(defun CLOCKWISEP (en / lw minp MaxP lst)
(setq lw (vlax-ename->vla-object en))
(vla-GetBoundingBox lw 'MinP 'MaxP)
(setq
minp (vlax-safearray->list minp)
MaxP (vlax-safearray->list MaxP)
lst(mapcar
(function
(lambda (x)
(vlax-curve-getParamAtPoint
lw
(vlax-curve-getClosestPointTo lw x)
)
)
)
(list minp
(list (car minp) (cadr MaxP))
MaxP
(list (car MaxP) (cadr minp))
)
)
)
(if (or
(<= (car lst) (cadr lst) (caddr lst) (cadddr lst))
(<= (cadr lst) (caddr lst) (cadddr lst) (car lst))
(<= (caddr lst) (cadddr lst) (car lst) (cadr lst))
(<= (cadddr lst) (car lst) (cadr lst) (caddr lst))
)
t
)
)
(initget 7 "W N S")
(setq kd0 (getkword "\n[向外偏移W/向内偏移N/双向偏移S]<W>"))
(if (= "" kd0)
(setq kd0 "W")
)
(initget 6)
(setq offset (getreal "\n[输入偏移距离]<0.5>"))
(if (null offset)
(setq offset 0.5)
)
(initget 7 "Y N")
(setq kd (getkword "\n[删除源对象<Y>/不删除源对象<N>]<N>:"))
(if (= kd "")
(setq kd "N")
)
(while (setq ss (ssget '((0 . "*polyline,arc,circle"))))
(repeat (setq n (sslength ss))
(setq en (ssname ss (setq n (1- n))))
(cond
((or (= "ARC" (cdr (assoc 0 (entget en))))
(= "CIRCLE" (cdr (assoc 0 (entget en))))
)
(cond ((= kd0 "W")
(vla-offset (vlax-ename->vla-object en) offset)
(vla-put-Color (vlax-ename->vla-object (entlast)) 1)
)
((= kd0 "N")
(vla-offset (vlax-ename->vla-object en) (- offset))
(vla-put-Color (vlax-ename->vla-object (entlast)) 1)
)
(t
(vla-offset (vlax-ename->vla-object en) offset)
(vla-put-Color (vlax-ename->vla-object (entlast)) 1)
(vla-offset (vlax-ename->vla-object en) (- offset))
(vla-put-Color (vlax-ename->vla-object (entlast)) 1)
)
)
)
(t
(cond ((= kd0 "W")
(if (CLOCKWISEP en)
(vla-offset (vlax-ename->vla-object en) (- offset))
(vla-offset (vlax-ename->vla-object en) offset)
)
(vla-put-Color (vlax-ename->vla-object (entlast)) 4)
)
((= kd0 "N")
(if (CLOCKWISEP en)
(vla-offset (vlax-ename->vla-object en) offset)
(vla-offset (vlax-ename->vla-object en) (- offset))
)
(vla-put-Color (vlax-ename->vla-object (entlast)) 1)
)
(t
(vla-offset (vlax-ename->vla-object en) offset)
(vla-put-Color (vlax-ename->vla-object (entlast)) 1)
(vla-offset (vlax-ename->vla-object en) (- offset))
(vla-put-Color (vlax-ename->vla-object (entlast)) 4)
)
)
)
)
(if (= kd "Y")
(entdel en)
)
)
)
(princ)
) 自贡黄明儒 发表于 2022-5-17 12:45
记得vla-offset的正负,与第一段弧有关系。
是的,一些奇怪的图形,很难判断它的内外。
你说的vla-offset,又跟方向有关。。。
:'(太难了!!! xiao88gang 发表于 2022-7-14 13:40
;;批量偏移 By Gu_xl 2013.04.01
(defun c:py (/ CLOCKWISEP OFFSET KD SS N EN kd0)
(defun CLOCKWISE ...
这个偏移圆跟方形怎么改成一个颜色呢 循环到一个小于偏移值时 之后的就不能偏移了偏移结束 这个能改一下不
页:
[1]