乐筑天下

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

[编程交流] 总面积lisp

[复制链接]

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 06:14:43 | 显示全部楼层 |阅读模式
我有这个总面积Lisp程序
 
  1. ;GetArea.lsp - Total the areas of selected polyline entities.
  2. (defun C:GetArea()
  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 Area = " (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. ;ask for a text insertion point
  23. (setq pt1(getpoint "\n insert point: "))
  24. ;print the area in the drawing
  25. (command "text" pt1 "" "" (strcat "Area = "(rtos myArea 2 2)"sq.m"))
  26. ;suppress the last echo
  27. (princ)
  28. )

 
我需要添加一个命令来更改文本大小。
回复

使用道具 举报

1

主题

80

帖子

79

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:19:04 | 显示全部楼层
你从哪里得到这个LISP的,你应该列出来源。
 
使用“entmake”而不是“text”命令。添加提示以询问文本高度,另存为变量,并添加到entmake。
 
演示如何添加命令,如有必要,我可以帮助您完成。
这毕竟是CADTutor
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 06:23:48 | 显示全部楼层
我不认识lisp,所以你能做到吗。。。
谢谢
回复

使用道具 举报

10

主题

8258

帖子

8335

银币

初来乍到

Rank: 1

铜币
31
发表于 2022-7-6 06:27:15 | 显示全部楼层
通常,当“借用”其他人创建的lisp例程以在代码顶部确认作者时。这被认为是一件光荣的事。
 
你没有写“我需要添加一个命令…”?您没有询问有关如何或在何处添加命令的建议。
 
您将再次听到代码发布指南。不要说我没有警告你。
回复

使用道具 举报

8

主题

1133

帖子

1164

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 06:29:18 | 显示全部楼层
它看起来非常类似于Jeffery P Sanders lisp,并且似乎采用了当前的文本高度。因此,您所要做的就是在图形中以所需的高度绘制一些文本,然后启动lisp。
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 06:31:45 | 显示全部楼层
 
这绝对是杰夫在这里看到的http://www.jefferypsanders.com/autolisp_examp.html#GetArea.lsp
 
可怜的家伙没有本地化他的变量虽然。。。
回复

使用道具 举报

12

主题

395

帖子

384

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-6 06:35:13 | 显示全部楼层
 
你肯定不想学任何东西,但我会尝试教你,而不是直接给出答案。
 
以下行是创建文本的行:
  1. (command "text" pt1 "" "" (strcat "Area = "(rtos myArea 2 2)"sq.m"))

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

使用道具 举报

1

主题

80

帖子

79

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:39:23 | 显示全部楼层
 
甚至没有尝试?
 
我有一个你正在寻找的工作版本,真的不介意帮助。我给了一个起点,至少你能做的就是努力。
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 06:43:10 | 显示全部楼层
 
我不认识作者。我这几年Lisp程序
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 06:47:45 | 显示全部楼层
我试过了,但不起作用。。。。。
 
  1. ;GetArea.lsp - Total the areas of selected polyline entities.
  2. (defun C:GetArea2 (ht scl)
  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 scl(/ (getreal  "\n give scale (100,200,500,etc) : ") 100))
  24. (setq ht(* 0.175 scl))
  25. ;ask for a text insertion point
  26. (setq pt1(getpoint "\n insert point: "))
  27. ;print the area in the drawing
  28. (command "text" pt1 "" "" (strcat "E = "(rtos myArea 2 2)"sq.m"))
  29. ;suppress the last echo
  30. (princ)
  31. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 18:30 , Processed in 0.544236 second(s), 72 queries .

© 2020-2025 乐筑天下

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