在Autolisp中使用Area命令
我试图使用area命令获取面积,并通过将其乘以用户给定的输入来打印输出。我不擅长编程,所以使用了本论坛中给出的一些代码。
我已经尝试了以下代码来完成工作。。。但它打印出了一些错误。。。。你能帮我做这件事吗。
(defun c:Test (/ val)
(command "_.area")
(while (< 0 (getvar 'cmdactive))
(progn (princ "\nSpecify point: ")
(command PAUSE)
)
)
(setq SupPercent (getreal "\n Enter Super Built Percentage : "))
(setq supArea (* (getvar 'AREA) (/ SupPercent 100)) )
(princ (strcat "\n" (rtos (getvar 'AREA)) " m²") )
(princ (strcat (rtos SupPercent) "% Sup Area = " (rtos supArea)) " m²") )
)
还有一件事,是否可以使用Autocad Area命令通过(1)选择点(如上述代码所示)和(2)通过对象选择(如闭合多边形)来获取面积。实际上,我希望代码能够通过两种方式获得面积。
提前感谢 请阅读代码发布指南并编辑您的帖子,将代码包含在代码标签中。
Your Code Here=
Your Code Here 编辑完成。。。。。。 删除“while”行上的额外括号:
(while (< 0 (getvar 'cmdactive))
最简单的问题是,在开始时你要问哪种方法,唯一可能的一个选择是当你选择第一个点时,它是一个普林线物体还是圆,我可以看到这一点,问题是一个点在同一点上有直线等。使用vla get area对象可能是最简单的,所以使用点生成一个新的pline get area,然后最后擦除。
; create pline by picking points press enter when finished
(command "_pline")
(while (= (getvar "cmdactive") 1 ) (command pause)
)
(alert (strcat "Area is " (rtos (vla-get-area (vlax-ename->vla-object (entlast))) 2 3 )))
(command "erase" "Last" "" )
试试这个
(defun c:test ( / obj)
(setq obj (vlax-ename->vla-object (car (entsel "Pick object"))))
(if (= (vlax-get obj 'ObjectName) "AcDbPolyline")
(alert (strcat "Area is " (rtos (vla-get-area obj) 2 3 )))
(progn
(alert "Pick all points including start") ; avoids finding start point of picked object
(command "_pline")
(while (= (getvar "cmdactive") 1 ) (command pause)
) ; while
(setq obj (vlax-ename->vla-object (entlast)))
(alert (strcat "Area is " (rtos (vla-get-area obj) 2 3 )))
(command "erase" "last" "")
) ; progn
) ; if
) ; defun
(c:test)
页:
[1]