woodman78 发表于 2022-7-6 11:47:48

多段线长度

有人有lisp只显示或输出多段线的长度而不给出总长度吗。我需要按顺序给出每条线的长度,我甚至可以通过交叉窗口来选择这些线。
 
谢谢

Lee Mac 发表于 2022-7-6 12:04:46

这将使你朝着正确的方向前进:
 

(defun c:PolyLen (/ ss)
(vl-load-com)

(if (ssget '((0 . "*POLYLINE")))
   (progn
   (vlax-for obj (setq ss (vla-get-ActiveSelectionSet
                              (vla-get-ActiveDocument
                              (vlax-get-acad-object))))
       (print (vla-get-length obj)))

   (vla-delete ss)))

(princ))

 
为什么不尝试学习相关的过程?

klpocska 发表于 2022-7-6 12:13:50

有人有VBA宏来获取多段线的总长度吗?

Lee Mac 发表于 2022-7-6 12:25:56

 
例子:
 

Sub Example_Length ()

   Dim lineObj As AcadLWPolyline
   Dim Points(0 To 9) As Double

   points(0) = 1: points(1) = 1
   points(2) = 1: points(3) = 2
   points(4) = 2: points(5) = 2
   points(6) = 3: points(7) = 2
   points( = 4: points(9) = 4

   ' Create the line in model space
   Set lineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)

   ThisDrawing.Application.ZoomAll
   
   MsgBox "The length of the new Line is: " & lineObj.length
End Sub

woodman78 发表于 2022-7-6 12:35:44

我希望能够很容易地编码。我已经花了很多时间,但这并不容易,目前我有点时间不足,在可预见的未来,我看不到自己有更多的时间花在这方面。
 
谢谢你的帮助,李。

Lee Mac 发表于 2022-7-6 12:44:36

这可能更有用(适用于圆、圆弧、直线、多段线、样条曲线…)
 

(defun c:PLen (/ ent Len)
(vl-load-com)

(while
   (progn
   (setq ent (car (nentsel "\nSelect Object: ")))

   (cond ((eq 'ENAME (type ent))

            (if (vl-catch-all-error-p
                  (setq Len
                      (vl-catch-all-apply (function vlax-curve-getDistatParam)
                        (list ent (vlax-curve-getEndParam ent)))))

                (princ "\n** Invalid Object **")
                (princ (strcat "\n-->>Length = " (rtos Len)"<<--")))))))
(princ))

   

 
~'J'~

fixo 发表于 2022-7-6 12:48:34

页: [1]
查看完整版本: 多段线长度