乐筑天下

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

[编程交流] 需要帮助提取属性

[复制链接]

10

主题

45

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
50
发表于 2022-7-6 11:40:52 | 显示全部楼层 |阅读模式
大家好,
 
我目前正在编写一个Lisp,需要一些帮助。在这里的情况下,我有3个不同的模板,从一个客户是不同的图纸尺寸。每种尺寸的图纸空间中都有不同的图形边框(属性块)。我想做的是根据使用的图形模板在Lisp中做出决定。我想出的最好办法是“弄清楚”图纸中的标题栏。为此,我提出了在绘图中列出块或列出属性值的方法。然而,我一直无法找到任何地方如何找到这些信息,以便我可以根据这些信息做出决定。如有任何建议,我们将不胜感激。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:46:36 | 显示全部楼层
这将检索图形中所有属性插入的列表:
 
  1. (defun c:blklist (/ ss i bname bnameLst)
  2. (if (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 66 1)
  3.                (if (getvar "CTAB")
  4.                  (cons 410 (getvar "CTAB"))
  5.                  (cons 67 (- 1 (getvar "TILEMODE")))))))
  6.    (progn
  7.    (setq i (sslength ss))
  8.    (while (not (minusp (setq i (1- i))))
  9.      (setq bname (cdr (assoc 2 (entget (ssname ss i))))
  10.        bnameLst (cons bname bnameLst))))
  11.    (princ "\n<!> No Attributed Blocks Found. <!>"))
  12. (princ))

 
(未经测试,书写速度快!)
回复

使用道具 举报

10

主题

45

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
50
发表于 2022-7-6 11:48:19 | 显示全部楼层
这应该行得通,我很感激。有没有办法从属性中提取值。假设标题栏中有一个属性,用于指定它是“D”大小、“E”大小还是“a”大小的图形。其中,属性标记为“大小”,标题栏中的值分别为“D”、“E”或“A”。是否有方法提取该值,以便根据该值确定大小、比例等。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:53:32 | 显示全部楼层
这将生成属性值为Size的所有块的关联列表:
 
  1. (defun c:AttLst (/ ss eLst bEnt aEnt aEntLst aVal blkLst)
  2. (vl-load-com)
  3. (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 66 1)
  4.                (if (getvar "CTAB")
  5.                  (cons 410 (getvar "CTAB"))
  6.                  (cons 67 (- 1 (getvar "TILEMODE")))))))
  7.    (progn
  8.      (setq eLst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  9.      (foreach e eLst
  10.    (setq bEnt (cdr (assoc 2 (entget e)))
  11.          aEnt (entnext e))
  12.    (while (= "ATTRIB" (cdr (assoc 0 (setq aEntLst (entget aEnt)))))
  13.      (if (= (cdr (assoc 2 aEntLst)) "SIZE")
  14.        (progn
  15.          (setq aVal (cdr (assoc 1 aEntLst))
  16.            blkLst (cons (cons bEnt aVal) blkLst))))
  17.      (setq aEnt (entnext aEnt)))))
  18.    (princ "\n<!> No Attributed Blocks Found <!>"))
  19. (alert (vl-princ-to-string blkLst))
  20. (princ))
回复

使用道具 举报

10

主题

45

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
50
发表于 2022-7-6 11:53:47 | 显示全部楼层
太棒了!再次感谢。如果有一天你觉得无聊,并且你不介意帮忙,我会非常感谢你解释一下这到底是怎么回事。我的意思是,完成我试图完成的任务很好,但仅供将来参考,以便我理解它,也便于我学习。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:58:59 | 显示全部楼层
没问题,你想让我逐行检查吗?
回复

使用道具 举报

10

主题

45

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
50
发表于 2022-7-6 12:00:56 | 显示全部楼层
如果你不介意的话。我对AutoLisp有点陌生。我理解它的工作原理,但贯穿整个过程将非常有益。
 
提前谢谢。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:05:44 | 显示全部楼层
毫无疑问,我很乐意帮助任何想更好地理解LISP的人:
 
  1. (defun c:AttLst    (/ ss eLst bEnt aEnt aEntLst aVal blkLst) ; [b][color=Red]Define the function, localise the variables[/color][/b]
  2. (vl-load-com) ; [b][color=Red]Load the Visual LISP console [i](allows vl-... commands)[/i][/color][/b]
  3. (if ; [b][color=Red]If there exists a selection set such that:[/color][/b]
  4.    (setq ss (ssget "X" ; [b][color=Red][i]"X" [/i]meaning search [i]entire database[/i] for entities with:[/color][/b]
  5.              (list (cons 0 "INSERT") ; [b][color=Red]type: INSERT [i](Blocks, XRefs)[/i][/color][/b]
  6.                (cons 66 1) ; [b][color=Red]Attributed[/color][/b]
  7.                (if    (getvar "CTAB") ; [b][color=Red]If there is a variable [i]"CTAB"[/i] (newer releases - determines Model Space/Paper Space[/color][/b]
  8.                  (cons 410 (getvar "CTAB")) ; [b][color=Red]Then filter by the CTAB variable[/color][/b]
  9.                  (cons 67 (- 1 (getvar "TILEMODE"))) ; [b][color=Red]Otherwise use TILEMODE variable to filter.[/color][/b]
  10.                ) ; [b][color=Red]end if[/color][/b]
  11.              ) ;[b][color=Red] end list [Filter List][/color][/b]
  12.           ) ;[b][color=Red] end Selection set aquirement [ssget][/color][/b]
  13.      ) ; [b][color=Red]end Variable Setting [selection set stored in variable "ss"][/color][/b]
  14.    (progn ; [b][color=Red]Wrap the following code for use in the IF statement:[/color][/b]
  15.      (setq eLst ; [b][color=Red]Store the following list of entity names to variable "eLst"[/color][/b]
  16.         (vl-remove-if 'listp ; [b][color=Red]Remove from the list if the item is a List[/color][/b]
  17.           (mapcar 'cadr ; [b][color=Red]Produce a list of entity names (and possible coord values) from[/color][/b]
  18.               (ssnamex ss) ;[b][color=Red] Information provided by "ssnamex" about the Selection Set[/color][/b]
  19.               ) ; [b][color=Red]end Mapcar[/color][/b]
  20.           ) ;[b][color=Red] end vl-remove-if[/color][/b]
  21.        ) ; [b][color=Red]end variable setting[/color][/b]
  22.      (foreach e eLst ; [b][color=Red]For Each item (e) in the eLst (entity name list):[/color][/b]
  23.    (setq bEnt (cdr (assoc 2 (entget e))) ; [b][color=Red]Retrieve the Block Name [store to "bEnt"][/color][/b]
  24.          aEnt (entnext e) ; [b][color=Red]Retrieve the Attribute Entity Name [store to aEnt][/color][/b]
  25.    ) ; [b][color=Red]end Variable setting[/color][/b]
  26.    (while (= "ATTRIB" (cdr (assoc 0 (setq aEntLst (entget aEnt))))) ; [b][color=Red]While the Entity Type is "ATTRIB"[ute][/color][/b]
  27.      (if (= (cdr (assoc 2 aEntLst)) "SIZE") ; [b][color=Red]If the ATTRIBute name is "SIZE"[/color][/b]
  28.        (progn ; [b][color=Red]wrap the following for use with the IF[/color][/b]
  29.          (setq aVal   (cdr (assoc 1 aEntLst)) ; [b][color=Red]Store the ATTRIBute value [to aVal][/color][/b]
  30.            blkLst (cons
  31.                 (cons bEnt aVal) ; [b][color=Red]Create an Associative list (dotted pair) of Block Name and Att. Value.[/color][/b]
  32.                 blkLst) ; [b][color=Red]Connect this to the main list[/color][/b]
  33.          ) ; [b][color=Red]End Variable Setting[/color][/b]
  34.        ) ; [b][color=Red]end Progn (code wrapper)[/color][/b]
  35.      ) ;[b] [color=Red]end IF[/color][/b]
  36.      (setq aEnt (entnext aEnt)) ; [b][color=Red]Move onto next Attribute in Block[/color][/b]
  37.    ) ; [b][color=Red]End While[/color][/b]
  38.      ) ; [b][color=Red]End Foreach[/color][/b]
  39.    ) ; [color=Red][b]End Progn[/b][/color]
  40.    (princ "\n<!> No Attributed Blocks Found <!>") ;[b][color=Red] If No Selection Set, then No Attributed Blocks Found in Drawing.[/color][/b]
  41. ) ; [b][color=Red]End IF[/color][/b]
  42. (alert (vl-princ-to-string blkLst)) ;[b][color=Red] Convert the Associative List to a String and Alert it in a Dialog Box to view result.[/color][/b]
  43. (princ) ; [b][color=Red]Exit Cleanly[/color][color=Red] - [suppress last function return][/color][/b]
  44. ) ; [b][color=Red]End Function[/color][/b]

 
以上内容应该可以帮助您更清楚地理解程序背后的过程,我已经对代码进行了格式化,使其更清晰、更简洁,并对每一行进行了注释和解释。
 
阅读愉快!
 
干杯
 

 
如果您有什么需要进一步解释的,请随时询问
 
希望这有帮助
回复

使用道具 举报

10

主题

45

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
50
发表于 2022-7-6 12:06:15 | 显示全部楼层
嘿,非常感谢你这么做。我真的很感激。另外,您对更详细地学习AutoLisp的参考资料(书籍等)有什么建议吗。我有一些非常基本的参考资料,但我想知道你是否有任何进一步深入研究这个主题的建议。
 
再次提前感谢。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 12:09:32 | 显示全部楼层
显然,ACAD Visual LISP编辑器中的开发人员指南是一个很好的参考(只需在ACAD命令提示符下键入“vlide”)。
 
我建议:
AfraLISP公司
 
杰弗里·桑德斯
 
AutoLISP的ABC
 
 
但我相信还有更多的资源。
 
这些应该可以让你走了
 
干杯
 
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 02:21 , Processed in 0.511366 second(s), 72 queries .

© 2020-2025 乐筑天下

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