Pete_IC 发表于 2022-7-6 10:54:18

LISP查找多个顶点的中点

您好,我正在尝试找到一个lisp,它将为我提供一组多段线的中心/中点。
我与船一起工作,经常需要找到船体中一组加强筋的总长度和重心(中点),目前我使用一个名为Tlen的LISP来给我提供加强筋的总长度,但必须估计或手动计算cog,我要找的是一个LISP,它将计算出许多多段线的组合中点。
我附上了一个我将使用的示例
谢谢,皮特
加强筋。图纸

MSasu 发表于 2022-7-6 10:59:44

也许这会帮助你:
 
(defun c:MidPL( / PlinesSet thePline Dist1st Dist2nd PlineLen PointMid OldOsmode )
(setq OldOsmode (getvar "OSMODE"))
(setvar "OSMODE" 0)

(prompt "\nSelect polylines to mark middle point:")
(if (and (setq PlinesSet (ssget '((0 . "LWPOLYLINE"))))   ;select polylines
         (> (sslength PlinesSet) 0))
(while (> (sslength PlinesSet) 0)
(setq thePline (ssname PlinesSet 0))

(setq Dist1st(vlax-curve-getDistAtPoint thePline (vlax-curve-getStartPoint thePline))
      Dist2nd(vlax-curve-getDistAtPoint thePline (vlax-curve-getEndPoint   thePline))
      PlineLen (- Dist2nd Dist1st)
      PointMid (vlax-curve-getPointAtDist thePline (+ Dist1st (* 0.5 PlineLen))))

(entmake (list (cons '0"POINT")                     ;add point entity
               (cons '10 PointMid)))

(setq PlinesSet (ssdel thePline PlinesSet))             ;remove processed polyline
)
)

(setvar "OSMODE" OldOsmode)
(princ)
)
 
当做

alanjt 发表于 2022-7-6 11:03:39

少一点跑腿。
 
(defun c:TEst (/ ss)
(vl-load-com)
(if (setq ss (ssget '((0 . "ARC,LINE,*POLYLINE"))))
   ((lambda (i)
      (while (setq e (ssname ss (setq i (1+ i))))
      (entmakex (list '(0 . "POINT")
                        (cons 10
                              (vlax-curve-GetPointAtDist
                              e
                              (/ (vlax-curve-GetDistAtParam e (vlax-curve-GetEndParam e)) 2.)
                              )
                        )
                  )
      )
      )
    )
   -1
   )
)
(princ)
)

Pete_IC 发表于 2022-7-6 11:04:01

谢谢你的两个回复,他们会派上用场的,但我要找的是有点不同。我不知道我想要的是否可能,但我不明白为什么不能做到。有没有办法用一个数字得到这些点的平均距离,我假设如果我在加强筋的开始处设置一个新的USC,那么我应该能够得到这些线的平均中点的X坐标。
 
我已经附上了lisp,我用它来获得总长度,如果我能得到这样的东西,可以给我的平均x或x和y的位置为中点的所有线结合起来,这将是了不起的。
 
我还附上了一张基本图纸,显示了我需要找到的位置。
 
如果有更多帮助,我们将不胜感激
 
谢谢你,皮特。
特伦。lsp
中点。图纸

Pete_IC 发表于 2022-7-6 11:08:27

有人知道怎么做吗?

Lee Mac 发表于 2022-7-6 11:12:48

试试这个:
 

(defun c:AveMid ( / ss )
;; © Lee Mac~24.05.10
(vl-load-com)

(if (setq ss (ssget '((0 . "ARC,*POLYLINE,LINE"))))
   (
   (lambda ( i / ent mLst l )
       (while (setq ent (ssname ss (setq i (1+ i))))
         (setq mLst
         (cons
             (vlax-curve-getPointatParam ent
               (/ (+ (vlax-curve-getEndParam ent)
                     (vlax-curve-getStartParam ent)) 2.)
             )
             mLst
         )
         )
       )
       (setq l (length mLst))
       (
         (lambda ( p )
         (entmakex
             (list
               (cons 0 "POINT")
               (cons 10 p)
             )
         )
         )
         (mapcar (function /)
         (apply (function mapcar)
             (cons
               (function +) mLst
             )
         )
         (list l l l)
         )
       )
   )
   -1
   )
)
(princ)
)

Pete_IC 发表于 2022-7-6 11:14:10

谢谢李的回复,
 
当我使用AveMid时,这就是我得到的
 
命令:avemid
选择对象:找到1个
选择对象:
; 错误:无函数定义:VLAX-CURVE-GETENDPARAM
 
有什么想法吗?

Lee Mac 发表于 2022-7-6 11:17:24

这只是没有加载Visual LISP函数-代码已更新
 
如果您再次遇到这种情况,只需在代码顶部添加(vl load com)。
 
我们中的大多数人(vl load com)在一个ACADDOC中调用。lsp,所以我们没有注意到它是否丢失

Pete_IC 发表于 2022-7-6 11:21:37

非常感谢李,这正是我想要的。

Lee Mac 发表于 2022-7-6 11:25:45

不客气,皮特
页: [1] 2
查看完整版本: LISP查找多个顶点的中点