prodromosm 发表于 2022-7-6 06:14:43

总面积lisp

我有这个总面积Lisp程序
 
;GetArea.lsp - Total the areas of selected polyline entities.

(defun C:GetArea()

;turn off the system echo
(setvar "cmdecho" 0)

;set up a variable to hold the accumulated areas
(setq myArea 0)

;while the user keeps making a selection
(while(setq ent(entsel))

   ;if an entity was selected and not a point in space   
   (if(car ent)
      (progn

         ;let AutoCAD get the area of the object...cheap yet effective way out...
         ;Note: AutoCAD stores the area in the system variable "Area"
         (command "area" "Object" (car ent))

         ;print the area to the command line
         (princ (strcat "\n Area = " (rtos (getvar "Area") 2 2)" sq.m"))

         ;accumulate the area if it exist
         (if (getvar "Area")(setq myArea(+ myArea (getvar "Area"))))
      )
   )
)

;ask for a text insertion point
(setq pt1(getpoint "\n insert point: "))

;print the area in the drawing
(command "text" pt1 "" "" (strcat "Area = "(rtos myArea 2 2)"sq.m"))

;suppress the last echo
(princ)
)
 
我需要添加一个命令来更改文本大小。

CheSyn 发表于 2022-7-6 06:19:04

你从哪里得到这个LISP的,你应该列出来源。
 
使用“entmake”而不是“text”命令。添加提示以询问文本高度,另存为变量,并添加到entmake。
 
演示如何添加命令,如有必要,我可以帮助您完成。
这毕竟是CADTutor

prodromosm 发表于 2022-7-6 06:23:48

我不认识lisp,所以你能做到吗。。。
谢谢

ReMark 发表于 2022-7-6 06:27:15

通常,当“借用”其他人创建的lisp例程以在代码顶部确认作者时。这被认为是一件光荣的事。
 
你没有写“我需要添加一个命令…”?您没有询问有关如何或在何处添加命令的建议。
 
您将再次听到代码发布指南。不要说我没有警告你。

eldon 发表于 2022-7-6 06:29:18

它看起来非常类似于Jeffery P Sanders lisp,并且似乎采用了当前的文本高度。因此,您所要做的就是在图形中以所需的高度绘制一些文本,然后启动lisp。

Commandobill 发表于 2022-7-6 06:31:45

 
这绝对是杰夫在这里看到的http://www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp
 
可怜的家伙没有本地化他的变量虽然。。。

Commandobill 发表于 2022-7-6 06:35:13

 
你肯定不想学任何东西,但我会尝试教你,而不是直接给出答案。
 
以下行是创建文本的行:
(command "text" pt1 "" "" (strcat "Area = "(rtos myArea 2 2)"sq.m"))


 
“pt1”后的双引号是文本命令中要求提供所需比例的点。如果你想要一个固定的比例,那么我就把数字放在那里。如果没有,如前所述,您应该用
或者另一种获取数字的代码。他们把那个变量放在那个位置。
 
祝你好运

CheSyn 发表于 2022-7-6 06:39:23

 
甚至没有尝试?
 
我有一个你正在寻找的工作版本,真的不介意帮助。我给了一个起点,至少你能做的就是努力。

prodromosm 发表于 2022-7-6 06:43:10

 
我不认识作者。我这几年Lisp程序

prodromosm 发表于 2022-7-6 06:47:45

我试过了,但不起作用。。。。。
 
;GetArea.lsp - Total the areas of selected polyline entities.

(defun C:GetArea2 (ht scl)

;turn off the system echo
(setvar "cmdecho" 0)

;set up a variable to hold the accumulated areas
(setq myArea 0)

;while the user keeps making a selection
(while(setq ent(entsel))

   ;if an entity was selected and not a point in space   
   (if(car ent)
      (progn

         ;let AutoCAD get the area of the object...cheap yet effective way out...
         ;Note: AutoCAD stores the area in the system variable "Area"
         (command "area" "Object" (car ent))

         ;print the area to the command line
         (princ (strcat "\n Ε = " (rtos (getvar "Area") 2 2)" sq.m"))

         ;accumulate the area if it exist
         (if (getvar "Area")(setq myArea(+ myArea (getvar "Area"))))
      )
   )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(setq scl(/ (getreal"\n give scale (100,200,500,etc) : ") 100))
(setq ht(* 0.175 scl))

;ask for a text insertion point
(setq pt1(getpoint "\n insert point: "))

;print the area in the drawing
(command "text" pt1 "" "" (strcat "E = "(rtos myArea 2 2)"sq.m"))


;suppress the last echo
(princ)
)
页: [1] 2
查看完整版本: 总面积lisp