乐筑天下

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

[编程交流] lisp嵌套块的帮助

[复制链接]

2

主题

4

帖子

2

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 10:59:36 | 显示全部楼层 |阅读模式
大家好,
 
我有一个lisp用于使用属性,但这个lisp不能用于嵌套块,有人能告诉我如何解决这个问题吗。
 
  1. ;;local defun
  2. ;;helper method to group a list of items by their tags
  3. (defun group-by-car (lst)
  4. ;;ensure that the list is not empty
  5. (if lst
  6. (cons
  7. (vl-remove-if-not
  8. ;;this is a lambda function to compare the equality of the tags
  9. (function (lambda (x)
  10. (equal (car x) (caar lst) 0.00001)))
  11. lst
  12. )
  13. ;;recursive call to group a sublist
  14. (group-by-car
  15. (vl-remove-if
  16. (function (lambda (x)
  17. (equal (car x) (caar lst) 0.00001)))
  18. lst))))
  19. )
  20. ;;main program
  21. ;;define the main function, localize all variables.
  22. (defun C:SUMTABLE (/ acsp att atts block_obj data en ent_list item
  23. match_list pt sset tag tags tmp)
  24. ;;look for block
  25. (if (not (tblsearch "block" "GKW_Totaal"))
  26. (progn
  27. ;;if it is not found, alert user and exit program
  28. (alert "Block "GKW_Totaal" does not exist. Exit program.")
  29. (exit)(princ))
  30. )
  31. (setq acsp (vla-get-block ;;get the block representation of the layout
  32. (vla-get-activelayout ;;get the current layout
  33. (vla-get-activedocument ;;get the current drawing
  34. (vlax-get-acad-object)))) ;;get AutoCAD application
  35. )
  36. ;;create a list to match attribute tags
  37. (setq match_list (list "GKW" "FLOW" "KPA"))
  38. ;;get a selection set of all blocks with attributes
  39. (setq sset (ssget (list (cons 0 "INSERT") (cons 66 1)))
  40. )
  41. ;;start to loop through selection set
  42. (while (setq en (ssname sset 0))
  43. ;;add current entity to a list of entities
  44. (setq ent_list (cons en ent_list))
  45. ;;get the first attribute from the entity
  46. (setq att (entnext en))
  47. ;;start while loop through attributes in the block
  48. (while (/= (cdr (assoc 0 (entget att))) "SEQEND")
  49. ;;if there is an attribute
  50. (if (and att
  51. ;;AND its tag is in the list of tags to match
  52. (member (setq tag (cdr (assoc 2 (entget att)))) match_list))
  53. ;;then get the value from the tag and place into a dotted pair list
  54. (setq tags (cons (cons tag (cdr (assoc 1 (entget att)))) tags)))
  55. ;;get the next attribute
  56. (setq att (entnext att)))
  57. ;;deletes an entity from the current selection set
  58. (ssdel en sset)
  59. )
  60. ;;loop through each pair of dotted pairs in the tags list
  61. (foreach item (group-by-car tags)
  62. ;;if the tag is KPA...
  63. (if (eq (caar item) "KPA")
  64. ;;get the maximum for KPA
  65. (setq tmp (list (caar item)
  66. (vl-princ-to-string (apply 'max (mapcar 'atof (mapcar 'cdr item))))))
  67. ;;otherwise, sum all other values together
  68. (setq tmp (list (caar item)
  69. (vl-princ-to-string (apply '+ (mapcar 'atof (mapcar 'cdr item))))))
  70. )
  71. ;;NOTE: mapcar is used to apply a function to a list of items. The function is applied
  72. ;;to every item in the list. atof will turn a string into a real number
  73. ;;add the computed values to a list
  74. (setq data (cons tmp data)
  75. )
  76. )
  77. ;;turn all values into strings, rtos is used to accomplish this
  78. (setq data (mapcar (function (lambda(x)
  79. (cons (car x)
  80. (rtos (atoi (cadr x)) 2 0))))
  81. data
  82. )
  83. )
  84. ;;prompt user for an insertion point
  85. (setq pt (getpoint "\nSpecify insertion point of the block: ")
  86. )
  87. ;;insert a block with a scale of 1 and rotation of 0
  88. (setq block_obj (vlax-invoke acsp 'Insertblock pt "GKW_Totaal" 1 1 1 0))
  89. ;;get the attributes for the inserted block
  90. (setq atts (vlax-invoke block_obj 'GetAttributes))
  91. ;;loop through the attributes in the inserted block
  92. (foreach att atts
  93. ;;if the tag for the attribute is found...
  94. (if (setq item (assoc (vla-get-tagstring att) data))
  95. ;;put the value into the attribute
  96. (vla-put-textstring att (cdr item)))
  97. )
  98. ;;silent exit
  99. (princ)
  100. )
  101. ;;inform the user how to start the program
  102. (prompt "\n\t\t***\tType SUMTABLE to execute\t***")
  103. (prin1)
  104. ;;load VL* functions
  105. (vl-load-com)
回复

使用道具 举报

1

主题

10

帖子

9

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 11:48:47 | 显示全部楼层
破译一个程序充其量是一项乏味的任务。
 
提供更多细节将帮助人们真正解决你的问题。
 
你能简单描述一下吗
1、你想要实现什么?
2.到底出了什么问题?
 
也许可以举一个原始绘图的例子,一个带有预期结果的绘图和一个显示您实际获得的结果的绘图可能会有很大的帮助。
 
这可能是一个很好的起点。人们可能需要您提供的更多详细信息。
 
这样,我们将更容易配置问题的可能解决方案。
 
如果您还没有找到解决方案,请提供这些详细信息。
 
-桑杰·库尔卡尼
回复

使用道具 举报

2

主题

4

帖子

2

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 12:13:10 | 显示全部楼层
我们正在做的是在天花板瓷砖中放置一个冷却系统,瓷砖是一个块,冷却是一个动态块,安装在瓷砖中并保存为一个新的wblock,上面的程序将一起计算值(解决后,我需要用更多公式对此进行调整),请参阅图纸示例。
testplafond。图纸
GKW_Totaal。图纸
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 11:34 , Processed in 0.424057 second(s), 69 queries .

© 2020-2025 乐筑天下

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