jan_ek 发表于 2022-7-5 16:57:50

autolisp多段线计算

你好
我想创建一个列表,如下图所示
使用AutoLISP时如何计算长度和角度
https://www.cadtutor.net/forum/attachment.php?attachmentid=59834&cid=1&stc=1
我将非常感谢您的建议。
我认为我最大的问题是坐标变换。

BIGAL 发表于 2022-7-5 17:21:17

一个简单的方法可能很有用,制作一个pline的副本,将所有半径设置为零,然后你可以很容易地得到坐标并计算出所有值。
 

; copy object using entmake where is it put it here
(command "_.fillet" "_r" 0.0 "_.fillet" "_polyline" (entlast))

 
 

; pline co-ords example
; By Alan H
(defun getcoords (ent)
(vlax-safearray->list
   (vlax-variant-value
   (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
   )
   )
)
)

(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq len (length co-ords))
(setq numb (/ len 2)) ; even and odd check required
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)

; program starts here
(setq obj (entmake (entget (car (entsel))))) ; makes a copy of the entity
(command "_.fillet" "_r" 0.0 "_.fillet" "_polyline" (entlast))

;(setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
(setq co-ords (getcoords (car (entlast)))) ;changed for this post
(co-ords2xy) ; list of 2d points making pline
; do your thing here re measurements
(command "_.Erase" "" obj)

jan_ek 发表于 2022-7-5 17:32:35

你好
非常酷的想法:(命令“_.fillet”“\u r”*0.0“\u.fillet”“\u polyline”(entlast))
 
然而,我不会更改图纸中的任何内容。
我想用“inters”写一个函数

ziele_o2k 发表于 2022-7-5 17:40:10

您的示例pline有10个顶点。
第一:
在顶点1-2和顶点3-4之间的第二条线之间绘制温度线,当你得到这个值时,用以下公式计算点2的坐标:
http://www.lee-mac.com/intersectionfunctions.html和实用程序扩展两者
当你得到点2时,你可以得到角度:
https://www.theswamp.org/index.php?topic=41621.msg467214#msg467214
然后对pline的其他段重复上述操作。

Grrr 发表于 2022-7-5 17:48:22

一些人认为:

; eoh - entity / vla-object / handle ( MultiSegment polyline )
; mDeg - if T returns degrees else radians
; Returns: assoc list of dotted pairs, where each item is: (< Length > . < Angle >) ; for every segment of the curve
(defun PlineInfo ;| Written by: Grrr, credits to: Lee Mac, Tharwat |; ( eoh mDeg / handobj GetLength RTD eo objs Lst )
(defun handobj ( hand ) (vlax-ename->vla-object (handent hand)))
(defun GetLength ( eo / prm )
        (if (not (vl-catch-all-error-p (setq prm (vl-catch-all-apply 'vlax-curve-GetEndParam (list eo)))))
                (vlax-curve-getDistAtParam eo prm)
        )
)
(defun RTD (a) (/ (* a 180) PI))
(cond
        ((eq 'VLA-OBJECT (type eoh)) eoh)
        ((eq 'ENAME (type eoh)) (setq eoh (vlax-ename->vla-object eoh)))
        ((eq 'STR (type eoh)) (setq eoh (handobj eoh)))
        (T (setq eoh nil))
)
(if eoh
        (progn
                (setq objs (vlax-invoke eoh 'Explode))
                (setq Lst
                        (mapcar 'cons
                                (mapcar 'GetLength objs)
                                (mapcar '(lambda (x / a) (setq a (angle (vlax-get x 'EndPoint) (vlax-get x 'StartPoint))) (if mDeg (RTD a) a)) objs)
                        )
                )
                (mapcar 'vla-Delete objs)
        )
)
Lst
);| defun PlineInfo |; (or vlax-get-acad-object (vl-load-com)) (princ)

BIGAL 发表于 2022-7-5 17:59:22

Jan_ek制作一个临时对象不是问题,看看这个。
 
我编辑了之前的帖子,添加了entmake
 

(setq tempobj (entlast))
... do your thing
(command "erase" tempobj "")
页: [1]
查看完整版本: autolisp多段线计算