乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: prodromosm

[编程交流] 总面积lisp

[复制链接]

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 06:49:17 | 显示全部楼层
你得到了天平,但从未将其放入命令。
 
  1. (command "text" pt1 scl "" (strcat "E = "(rtos myArea 2 2)"sq.m"))

 
 
此外,当您试图本地化我们的变量时,您忘记了“/”。。。
 
  1. (defun C:GetArea2 (/ ent myArea pt1 ht scl)
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 06:54:47 | 显示全部楼层
谢谢Commandobill,它能工作。我能问你其他同样的问题吗?
 
我做了另一个改变,发现了一个问题。我正在努力学习,所以需要帮助!!
 
这是代码
 
  1. ;GetArea.lsp - Total the areas of selected polyline entities.
  2. (defun C:GetArea2 (/ ent myArea pt1 h )
  3. ;turn off the system echo
  4. (setvar "cmdecho" 0)
  5. ;set up a variable to hold the accumulated areas
  6. (setq myArea 0)
  7. ;while the user keeps making a selection
  8. (while(setq ent(entsel))
  9.    ;if an entity was selected and not a point in space     
  10.    (if(car ent)
  11.       (progn
  12.          ;let AutoCAD get the area of the object...cheap yet effective way out...
  13.          ;Note: AutoCAD stores the area in the system variable "Area"
  14.          (command "area" "Object" (car ent))
  15.          ;print the area to the command line
  16.          (princ (strcat "\n Ε = " (rtos (getvar "Area") 2 2)" sq.m"))
  17.          ;accumulate the area if it exist
  18.          (if (getvar "Area")(setq myArea(+ myArea (getvar "Area"))))
  19.       )
  20.    )
  21. )
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. (setq h (getdist "\n give text size:"))
  24. ;ask for a text insertion point
  25. (setq pt1(getpoint "\n insert point: "))
  26. ;print the area in the drawing
  27. (command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m"))
  28. ;suppress the last echo
  29. (princ)
  30. )

 
我有旋转问题。为什么?
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 06:58:05 | 显示全部楼层
在lisp中使用“命令行隐藏”有时是不可靠的。你可以试试这个:
 
  1. (defun C:GetArea2 (/ ent myArea pt1 h )
  2. ;turn off the system echo
  3. (setvar "cmdecho" 0)
  4. ;set up a variable to hold the accumulated areas
  5. (setq myArea 0)
  6. ;while the user keeps making a selection
  7. (while(setq ent(entsel))
  8.    ;if an entity was selected and not a point in space     
  9.    (if(car ent)
  10.       (progn
  11.          ;let AutoCAD get the area of the object...cheap yet effective way out...
  12.          ;Note: AutoCAD stores the area in the system variable "Area"
  13.          (command "area" "Object" (car ent))
  14.          ;print the area to the command line
  15.          (princ (strcat "\n ? = " (rtos (getvar "Area") 2 2)" sq.m"))
  16.          ;accumulate the area if it exist
  17.          (if (getvar "Area")(setq myArea(+ myArea (getvar "Area"))))
  18.       )
  19.    )
  20. )
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. (setq h (getdist "\n give text size:"))
  23. ;ask for a text insertion point
  24. (setq pt1(getpoint "\n insert point: "))
  25. ;print the area in the drawing
  26. (command "text" pt1 h 0 (strcat "E = "(rtos myArea 2 2)"sq.m"))
  27. ;suppress the last echo
  28. (princ)
  29. )

 
但我不确定这会有多大不同。我唯一的另一个想法是,也许你在UCS而不是世界?
回复

使用道具 举报

0

主题

99

帖子

99

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 07:01:01 | 显示全部楼层
  1. ;GetArea.lsp - Total the areas of selected polyline entities.
  2. (defun C:GetArea2 (/ ent myArea pt1 )
  3. ;turn off the system echo
  4. (setvar "cmdecho" 0)
  5. ;set up a variable to hold the accumulated areas
  6. (setq myArea 0)
  7. ;while the user keeps making a selection
  8. (while(setq ent(entsel))
  9.    ;if an entity was selected and not a point in space     
  10.    (if(car ent)
  11.       (progn
  12.          ;let AutoCAD get the area of the object...cheap yet effective way out...
  13.          ;Note: AutoCAD stores the area in the system variable "Area"
  14.          (command "area" "Object" (car ent))
  15.          ;print the area to the command line
  16.          (princ (strcat "\n ? = " (rtos (getvar "Area") 2 2)" sq.m"))
  17.          ;accumulate the area if it exist
  18.          (if (getvar "Area")(setq myArea(+ myArea (getvar "Area"))))
  19.       )
  20.    )
  21. )
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. [color="red"];(setq h (getdist "\n give text size:"))[/color] ; don't need
  24. ;ask for a text insertion point
  25. (setq pt1(getpoint "\n insert point: "))
  26. ;print the area in the drawing
  27. [color="red"]  ;(command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m"))[/color]
  28. (command "text" pt1[color="red"] 0  [/color](strcat "E = "(rtos myArea 2 2)"sq.m"))
  29. ;suppress the last echo
  30. (princ)
  31. )
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 07:04:22 | 显示全部楼层
谢谢你Commandobill它很好用
 
干杯
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 07:06:47 | 显示全部楼层
Jdiala-代码中的变量“h”表示文本的比例。。。他需要这样做,因为这正是他最初想要的。你的代码不起作用。你应该在将来发布之前测试你的代码。
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 07:09:26 | 显示全部楼层
 
你会发现,当你诚实地努力学习并自己动手时,帮助就会变得容易得多。
 
回复

使用道具 举报

0

主题

99

帖子

99

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-6 07:12:33 | 显示全部楼层
 
错过帖子之间的“h”部分。
我在#13上尝试了你的代码,但在我的代码上也不起作用。
Autocad 2014上的text命令没有高度选项,因此我在#14的帖子中删除了它。
 
  1. Command: .text
  2. Current text style:  "ROMANS"  Text height:  0'-10"  Annotative:  No  Justify:  Left
  3. Specify start point of text or [Justify/Style]:
  4. Specify rotation angle of text <18.21>: 0

 
prodromosm说他有旋转问题,所以我猜这里不需要“h”。文字高度基于当前的文字样式设置。代表autocad 2014发言。抱歉,无法在以前的版本上测试它。
 
  1. (command "text" pt1 [color="red"]h[/color] 0 (strcat "E = "(rtos myArea 2 2)"sq.m"))

 
这个可能是:
  1. ;GetArea.lsp - Total the areas of selected polyline entities.
  2. (defun C:GetArea2 (/ ent myArea pt1 )
  3. ;turn off the system echo
  4. (setvar "cmdecho" 0)
  5. ;set up a variable to hold the accumulated areas
  6. (setq myArea 0)
  7. ;while the user keeps making a selection
  8. (while(setq ent(entsel))
  9.    ;if an entity was selected and not a point in space     
  10.    (if(car ent)
  11.       (progn
  12.          ;let AutoCAD get the area of the object...cheap yet effective way out...
  13.          ;Note: AutoCAD stores the area in the system variable "Area"
  14.          (command "area" "Object" (car ent))
  15.          ;print the area to the command line
  16.          (princ (strcat "\n ? = " (rtos (getvar "Area") 2 2)" sq.m"))
  17.          ;accumulate the area if it exist
  18.          (if (getvar "Area")(setq myArea(+ myArea (getvar "Area"))))
  19.       )
  20.    )
  21. )
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;(setq h (getdist "\n give text size:")) ; don't need
  24. ;ask for a text insertion point
  25. (setq pt1(getpoint "\n insert point: "))
  26. ;print the area in the drawing
  27. ;(command "text" pt1 h "" (strcat "E = "(rtos myArea 2 2)"sq.m"))
  28. [color="red"] (entmakex
  29.   (list
  30.      (cons 0 "TEXT")
  31.      (cons 1 (strcat "E = "(rtos myArea 2 2)"sq.m"))
  32.      (cons 10 pt1)
  33.      (cons 11 pt1)
  34.      (cons 40 10) [color="#2e8b57"];set text height here[/color]
  35.      (cons 72 1)
  36.      (cons 73 2)
  37.   )
  38. )[/color]
  39. ;suppress the last echo
  40. (princ)
  41. )
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 07:16:06 | 显示全部楼层
我确实说过“命令行逃避”是不可靠的。我喜欢你的改变,但我不想在他身上改变太多。
 
然而,如果要放入entmakex,仍然应该保留放置比例的选项,如下所示。
 
  1. 12
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 18:34 , Processed in 0.558468 second(s), 68 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表