martyn3200 发表于 2022-7-5 20:06:45

LISP获取单个l的长度

我到处寻找这个可能很简单的问题的答案。如何在LISP中获得直线的长度?我能想到的最好方法是在VLISP中使用LIST命令来获取对象属性,但由于这是一个命令而不是本机lisp函数,我认为您不能使用CADR NTH等操作lisp对吗。?原谅我的天真。任何帮助都将不胜感激。我肯定我错过了一些简单的事情。

ReMark 发表于 2022-7-5 20:11:12

有一些lisp例程将返回行长度。
 
一个这样的例程的输出。
 

 
lisp例程由Ravikumar Vermana编写,并于2011年10月21日发布在他的博客上。你需要看代码吗?

Tharwat 发表于 2022-7-5 20:18:26

下载我的GetLength程序。

ReMark 发表于 2022-7-5 20:23:38

如果OP只需要一行的长度,那么lisp首先需要什么?通过LIST命令或单击行,然后查看快捷特性或特性,不是很容易获得长度吗?有时,人们在似乎没有实际需要的地方请求lisp例程。

Tharwat 发表于 2022-7-5 20:26:23

 
大多数人从一开始就要求一个非常小的代码,这个要求很快就会变成一个大雪球从高山上滚下来。
我认为你们对这些事情已经足够了解了,我们可能会在这个线程中实现这个想象的景象,谁知道呢?

ReMark 发表于 2022-7-5 20:31:03

我当时预测会发生雪崩。小心

Tharwat 发表于 2022-7-5 20:35:20

这里一直是夏天

martyn3200 发表于 2022-7-5 20:38:41

谢谢大家的回复。我已经看到了lisp例程,它提供了多行的长度,但我正在寻找一段简单的代码来获得一行的长度,以便在我正在开发的lisp例程中使用。
 

Tharwat 发表于 2022-7-5 20:44:24

玩一玩这个
 

(defun c:foo ( / s e )
(princ "\n Pick on one line to get its length :")
(if (setq s (ssget "_+.:S:E" '((0 . "LINE"))))
   (princ (strcat "\n Total Length is : " (rtos (distance (cdr (assoc 10 (setq e (entget (ssname s 0))))) (cdr (assoc 11 e))) 2)))
   )
(princ)
)

David Bethel 发表于 2022-7-5 20:49:01

作为创建稳健功能的入门:
 
 
(defun linelength (e / ed p10 p11 d2 d3)
(and (= (type e) 'ENAME)
   (setq ed (entget e))
   (= "LINE" (cdr (assoc 0 ed)))
   (setq p10 (cdr (assoc 10 ed))
         p11 (cdr (assoc 11 ed)))
   (setq d3 (distance p10 p11))
   (setq d2 (distance (list (car p10) (cadr p10))
                        (list (car p11) (cadr p11)))))
d3)

; (defun       ) : define a local function
;(e /          : supply 1 parameter to the function
;/ ed p10 p11 d2 d3) : declarevariables local to this function only
;(and      ) : inclusive testing - continue evaluating until a nil is returned or test complete
;(type       ) : test for the the type of the parameter
;(entget   ) : get an entity definition
;(distance   ) : calculate the true distance between 2 points
;                : if both points have X Y & Z values, return the 3D distance
;                : if either point has only X & Y values, return the 2D distance
;d3            : return the 3D value or nil if an error occurred

 
 
用法:
 
画一条线->

(prin1 (linelength (entlast)))

 
线点值始终存储在WCS中,因此不需要翻译
 
 
HTH-David
页: [1] 2
查看完整版本: LISP获取单个l的长度