(command "text" pt1 scl "" (strcat "E = "(rtos myArea 2 2)"sq.m"))
此外,当您试图本地化我们的变量时,您忘记了“/”。。。
(defun C:GetArea2 (/ ent myArea pt1 ht scl) 谢谢Commandobill,它能工作。我能问你其他同样的问题吗?
我做了另一个改变,发现了一个问题。我正在努力学习,所以需要帮助!!
这是代码
;GetArea.lsp - Total the areas of selected polyline entities.
(defun C:GetArea2 (/ ent myArea pt1 h )
;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 h (getdist "\n give text size:"))
;ask for a text insertion point
(setq pt1(getpoint "\n insert point: "))
;print the area in the drawing
(command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m"))
;suppress the last echo
(princ)
)
我有旋转问题。为什么? 在lisp中使用“命令行隐藏”有时是不可靠的。你可以试试这个:
(defun C:GetArea2 (/ ent myArea pt1 h )
;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 h (getdist "\n give text size:"))
;ask for a text insertion point
(setq pt1(getpoint "\n insert point: "))
;print the area in the drawing
(command "text" pt1 h 0 (strcat "E = "(rtos myArea 2 2)"sq.m"))
;suppress the last echo
(princ)
)
但我不确定这会有多大不同。我唯一的另一个想法是,也许你在UCS而不是世界? ;GetArea.lsp - Total the areas of selected polyline entities.
(defun C:GetArea2 (/ ent myArea pt1 )
;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 h (getdist "\n give text size:")) ; don't need
;ask for a text insertion point
(setq pt1(getpoint "\n insert point: "))
;print the area in the drawing
;(command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m"))
(command "text" pt1 0(strcat "E = "(rtos myArea 2 2)"sq.m"))
;suppress the last echo
(princ)
) 谢谢你Commandobill它很好用
干杯 Jdiala-代码中的变量“h”表示文本的比例。。。他需要这样做,因为这正是他最初想要的。你的代码不起作用。你应该在将来发布之前测试你的代码。
你会发现,当你诚实地努力学习并自己动手时,帮助就会变得容易得多。
错过帖子之间的“h”部分。
我在#13上尝试了你的代码,但在我的代码上也不起作用。
Autocad 2014上的text命令没有高度选项,因此我在#14的帖子中删除了它。
Command: .text
Current text style:"ROMANS"Text height:0'-10"Annotative:NoJustify:Left
Specify start point of text or :
Specify rotation angle of text <18.21>: 0
prodromosm说他有旋转问题,所以我猜这里不需要“h”。文字高度基于当前的文字样式设置。代表autocad 2014发言。抱歉,无法在以前的版本上测试它。
(command "text" pt1 h 0 (strcat "E = "(rtos myArea 2 2)"sq.m"))
这个可能是:
;GetArea.lsp - Total the areas of selected polyline entities.
(defun C:GetArea2 (/ ent myArea pt1 )
;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 h (getdist "\n give text size:")) ; don't need
;ask for a text insertion point
(setq pt1(getpoint "\n insert point: "))
;print the area in the drawing
;(command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m"))
(entmakex
(list
(cons 0 "TEXT")
(cons 1 (strcat "E = "(rtos myArea 2 2)"sq.m"))
(cons 10 pt1)
(cons 11 pt1)
(cons 40 10) ;set text height here
(cons 72 1)
(cons 73 2)
)
)
;suppress the last echo
(princ)
) 我确实说过“命令行逃避”是不可靠的。我喜欢你的改变,但我不想在他身上改变太多。
然而,如果要放入entmakex,仍然应该保留放置比例的选项,如下所示。
12
页:
1
[2]