求助大神,批量生成了填充后如何获得面积。
我写了个批量的多段线向两侧偏移,两头接上并填充。代码在下面。请问如何获取这些填充的面积。(重叠部分只算一次)(defun c:sx (/ getds ss i e obj e1 e2 e3 e4 e5 p1 p2 p3 p4 vertex_data vertex_coords e5_data)
(vl-load-com)
(setvar "osmode" 0)
(setvar 'cmdecho 0)
(initget 2)
(setq getds (getdist "\n输入偏移距离<可直接量取>:"))
(setq ss (ssget '((0 . "Arc,Circle,Ellipse,*Line"))))
(setq i 0)
(setq long 0)
; 遍历全部多段线
(repeat (sslength ss)
(setq e (ssname ss i)
obj (vlax-ename->vla-object e)
i (1+ i)
)
; 左侧偏移
(vl-catch-all-apply 'vla-offset (list obj getds))
(setq e1 (entlast))
(setq e1_data (entget e1))
(setq vertex_data (vl-remove-if '(lambda (X) (/= 10 (car x))) e1_data))
(setq vertex_coords (mapcar 'cdr vertex_data))
(setq p1 (nth 0 vertex_coords))
(setq p2 (nth (- (length vertex_coords) 1) vertex_coords))
; 右侧偏移
(vl-catch-all-apply 'vla-offset (list obj (* getds -1)))
(setq e2 (entlast))
(setq e2_data (entget e2))
(setq vertex_data (vl-remove-if '(lambda (X) (/= 10 (car x))) e2_data))
(setq vertex_coords (mapcar 'cdr vertex_data))
(setq p3 (nth 0 vertex_coords))
(setq p4 (nth (- (length vertex_coords) 1) vertex_coords))
; 两头接上,合并
(command "pline" p1 p3 "")
(setq e3 (entlast))
(command "pline" p2 p4 "")
(setq e4 (entlast))
(command "join" e1 e2 e3 e4 "")
(setq e5 (entlast))
(setq e5_data (entget e5))
; 填充
(setq e5_data (subst (cons 8 "偏移后") (assoc 8 e5_data) e5_data))
(command "-layer" "c" 5 "偏移后" "")
(entmod e5_data)
(setq e5 (entlast))
(command "-hatch" "p" "ANSI32" "" "" "CO" 5 "" "s" e5 "" "")
)
(princ)
) (setq e5 (entlast))
(princ (vla-get-Area (vlax-ename->vla-objecte5)))
liuhe 发表于 2024-4-24 12:52
(setq e5 (entlast))
(princ (vla-get-Area (vlax-ename->vla-objecte5)))
你好,我是想获得填充的累计面积,这样一个个加起来应该会把重叠部分加两遍 (defun c:tt ()
(setvar 'osmode 0)
(setvar 'cmdecho 0)
(setq dd (Udist 7 "" "偏移距离<输入或鼠标直接量取>" dd nil))
(if (setq ss (ssget '((0 . "Arc,Circle,Ellipse,*Line"))))
(progn
(setq i0
aa 0
)
(xyp-MkLaCo "偏移后" 6)
(repeat (sslength ss)
(setq e (ssname ss i)
obj (vlax-ename->vla-object e)
i (1+ i)
)
(vl-catch-all-apply 'vla-offset (list obj dd)) ; 左侧偏移
(setq e1 (entlast))
(setq p1 (vlax-curve-getStartPoint e1))
(setq p2 (vlax-curve-getEndPoint e1))
(vl-catch-all-apply 'vla-offset (list obj (* dd -1))) ; 右侧偏移
(setq e2 (entlast))
(setq p3 (vlax-curve-getStartPoint e2))
(setq p4 (vlax-curve-getEndPoint e2))
(command "line" p1 p3 "")
(setq e3 (entlast))
(command "line" p2 p4 "")
(setq e4 (entlast))
(command "-hatch" "p" "ANSI32" "" "" "s" e1 e2 e3 e4 "" "")
(xyp-SubUpd (list e1 e2 e3 e4) '(8 62) '("偏移后" 6))
(setq ob (vlax-ename->vla-object (entlast))
aa (+ aa (* (vla-get-area ob) 1e-6))
)
)
(princ "\n面积 = ")
(princ aa)
)
)
(princ)
) xyp1964 发表于 2024-4-24 19:09
你好,是要导入什么第三方库吗?no function definition: XYP-MKLACO
页:
[1]