乐筑天下

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

[编程交流] 例行Lisp

[复制链接]

3

主题

17

帖子

14

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 15:02:05 | 显示全部楼层 |阅读模式
你好!你们好!我再次请求帮助!!我非常感谢那些花时间和精力帮助别人的人。
 
好吧,这里有一个想做的事。
 
我想创建一个调用comand的路由,所以我将运行这个例程并调用,比如说“ATTEXP2XL”,运行它完成,然后调用另一个命令,比如说“aenext”,以进入下一个绘图。再重复一遍,直到项目经理看完所有的图纸。
 
顺便说一句,在运行lisp“attexp2xl”后,您必须选择对象。如何修改它以选择块名而不选择它。
 
再次感谢您的帮助!!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:15:17 | 显示全部楼层
使用LISP时,该函数将在两个图形之间切换时终止,因此您可能需要使用一些VBA或脚本来完成所需的操作。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:19:01 | 显示全部楼层
选择块名为“BLOCKNAME”的块
 
  1. (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 "BLOCKNAME")
  2.                          (if (getvar "CTAB")
  3.                              (cons 410 (getvar "CTAB"))
  4.                              (cons 67 (- 1 (getvar "TILEMODE")))))))
回复

使用道具 举报

3

主题

17

帖子

14

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 15:29:15 | 显示全部楼层
李,谢谢你的重播!
 
我可以用它从块的属性值中提取信息吗?以及如何在CAD中使用vba?
 
再次感谢!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:38:40 | 显示全部楼层
不,发布的代码将只创建具有该块名称的块的选择集。
 
你想要实现什么?我可以帮助学习LISP,但我对VBA知之甚少。
回复

使用道具 举报

3

主题

17

帖子

14

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 15:43:03 | 显示全部楼层
我试图做的是使用一个名为“attexp2xl”的Lisp,它将块属性值提取到excel中。当我运行它时,它会要求我选择对象=“具有属性的块”,它会将块中的值提取到excel中,如果有多个块,只要它们具有相同的块名称,就会提取它们。现在,我必须用几幅画来做。打开图形运行lisp并选择块,保存关闭并打开下一个图形。
 
我正在使用autocad electric 2009和项目管理器,该项目管理器允许我绘制图形,只要图形在项目managar中,a就可以从一个图形浏览到另一个图形。因此,有一个comand“aenext”允许我转到下一个绘图并保存我正在工作的绘图。
 
我希望这能帮助你理解我在做什么。
 
再次感谢你的帮助!!
 
 
干杯
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:49:04 | 显示全部楼层
如果您发布了attexp2xl,我可以修改它,让您自动选择块-但不确定aenext,从未遇到过这种情况。很抱歉
回复

使用道具 举报

3

主题

17

帖子

14

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 15:57:45 | 显示全部楼层
这是Lisp程序,我从这个论坛上得到的。其他人张贴了它,效果很好。但如果你可以根据我的需要修改,那就更好了。
 
非常感谢。
 
密码
attexp2xl。lsp
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 16:08:00 | 显示全部楼层
试一试。。。但未经测试。。。
 
  1. (vl-load-com)
  2. (defun mip-conv-to-str    (dat)
  3. (if dat
  4.    (vl-princ-to-string dat)
  5.    ""))
  6. (defun get-all-atts  (obj)
  7. (if (and obj
  8.       (eq :vlax-true (vla-get-HasAttributes obj))
  9.       (vlax-property-available-p obj 'Hasattributes))
  10.    (vl-catch-all-apply
  11.      (function    (lambda    ()
  12.          (mapcar (function (lambda (x)
  13.                      (cons (vla-get-TagString x)
  14.                        (vla-get-TextString x))))
  15.              (append (vlax-invoke obj 'Getattributes)
  16.                  (vlax-invoke obj 'Getconstantattributes)
  17.                  )))))))
  18. ;|================== XLS ========================================
  19. * Purpose: Export of the list of data punto_datos in Excell
  20. *             It is exported to a new leaf of the current book.
  21.              If the book is not present, it is created
  22. * Arguments:
  23.              punto_datos - The list of lists of data (LIST)
  24.                            ((Value1 Value2 ... VlalueN)(Value1 Value2 ... VlalueN)...)
  25.                            Each list of a kind (Value1 Value2... VlalueN) enters the name in
  26.                            a separate line in corresponding columns (Value1-A Value2-B and .ò.ä.)
  27.                  header -  The list (LIST) headings or nil a kind (" Signature A " " Signature B "...)
  28.                            If header nil, is accepted ("X" "Y" "Z")
  29.                 Colhide -  The list of alphabetic names of columns to hide or nil - to not hide ("A" "C" "D") - to hide columns A, C, D
  30.                 Name_list - The name of a new leaf of the active book or nil - is not present
  31. * Return: nil
  32. * Usage
  33. (xls '((1.1 1.2 1.3 1.4)(2.1 2.2 2.3 2.4)(3.1 3.2 3.3 3.4)) '("Col1" "Col2" "Col3"  "Col4") '("B") "test")   |;
  34. (vl-load-com)
  35. (defun xls  (punto_datos    header       Colhide      Name_list     /        *aplexcel*     *books-colection*
  36.         Currsep        *excell-cells* *new-book*      *sheet#1*     *sheet-collection*           col
  37.         iz_listo        row           cell          cols)
  38. (defun Letter     (N / Res TMP)
  39.    (setq Res "")
  40.    (while (> N 0)
  41.      (setq TMP    (rem N 26)
  42.        TMP    (if (zerop TMP)
  43.          (setq    N   (1- N)
  44.            TMP 26)
  45.          TMP)
  46.        Res    (strcat (chr (+ 64 TMP)) Res)
  47.        N    (/ N 26)))
  48.    Res)
  49. (if (null Name_list)
  50.    (setq Name_list ""))
  51. (setq *AplExcel* (vlax-get-or-create-object "Excel.Application"))
  52. (if (setq *New-Book* (vlax-get-property *AplExcel* "ActiveWorkbook"))
  53.    (setq *Books-Colection*  (vlax-get-property *AplExcel* "Workbooks")
  54.      *Sheet-Collection* (vlax-get-property *New-Book* "Sheets")
  55.      *Sheet#1*         (vlax-invoke-method *Sheet-Collection* "Add"))
  56.    (setq *Books-Colection*  (vlax-get-property *AplExcel* "Workbooks")
  57.      *New-Book*         (vlax-invoke-method *Books-Colection* "Add")
  58.      *Sheet-Collection* (vlax-get-property *New-Book* "Sheets")
  59.      *Sheet#1*         (vlax-get-property *Sheet-Collection* "Item" 1)))
  60. (setq *excell-cells* (vlax-get-property *Sheet#1* "Cells"))
  61. (setq    Name_list (if (= Name_list "")
  62.            (vl-filename-base (getvar "DWGNAME"))
  63.            (strcat (vl-filename-base (getvar "DWGNAME")) "&" Name_list))
  64.    col      0
  65.    cols      nil)
  66. (vlax-for sh *Sheet-Collection* (setq cols (cons (strcase (vlax-get-property sh 'Name)) cols)))
  67. (setq row Name_list)
  68. (while (member (strcase row) cols)
  69.    (setq row (strcat Name_list " (" (itoa (setq col (1+ col))) ")")))
  70. (setq Name_list row)
  71. (vlax-put-property *Sheet#1* 'Name Name_list)
  72. (setq Currsep (vlax-get-property *AplExcel* "UseSystemSeparators"))
  73. (vlax-put-property *AplExcel* "UseSystemSeparators" :vlax-false) ;_êå èñïîëüçîâêòü ñèñòåìêûå óñòêêîâêè
  74. (vlax-put-property *AplExcel* "DecimalSeparator" ".") ;_ðêçäåëèòåëü äðîáêîé è öåëîé ÷êñòè
  75. (vlax-put-property *AplExcel* "ThousandsSeparator" " ") ;_ðêçäåëèòåëü òûñÿ÷åé
  76. (vla-put-visible *AplExcel* :vlax-true)
  77. (setq    row 1
  78.    col 1)
  79. (if (null header)
  80.    (setq header '("X" "Y" "Z")))
  81. (repeat (length header)
  82.    (vlax-put-property
  83.      *excell-cells*
  84.      "Item"
  85.      row
  86.      col
  87.      (vl-princ-to-string (nth (1- col) header)))
  88.    (setq col (1+ col)))
  89. (setq    row 2
  90.    col 1)
  91. (repeat (length punto_datos)
  92.    (setq iz_listo (car punto_datos))
  93.    (repeat (length iz_listo)
  94.      (vlax-put-property *excell-cells* "Item" row col (vl-princ-to-string (car iz_listo)))
  95.      (setq iz_listo (cdr iz_listo)
  96.        col         (1+ col)))
  97.    (setq punto_datos (cdr punto_datos))
  98.    (setq col 1
  99.      row (1+ row)))
  100. (setq    col (1+ (length header))
  101.    row (1+ row))
  102. (setq    cell (vlax-variant-value
  103.           (vlax-invoke-method
  104.         *Sheet#1*
  105.         "Evaluate"
  106.         (strcat "A1:" (letter col) (itoa row))))) ;_ end of setq
  107. (setq cols (vlax-get-property cell 'Columns))
  108. (vlax-invoke-method cols 'Autofit)
  109. (vlax-release-object cols)
  110. (vlax-release-object cell)
  111. (foreach item     ColHide
  112.    (if    (numberp item)
  113.      (setq item (letter item)))
  114.    (setq cell (vlax-variant-value
  115.         (vlax-invoke-method
  116.           *Sheet#1*
  117.           "Evaluate"
  118.           (strcat item "1:" item "1"))))
  119.    (setq cols (vlax-get-property cell 'Columns))
  120.    (vlax-put-property cols 'hidden 1)
  121.    (vlax-release-object cols)
  122.    (vlax-release-object cell))
  123. (vlax-put-property *AplExcel* "UseSystemSeparators" Currsep)
  124. (mapcar 'vlax-release-object
  125.      (list    *excell-cells* *Sheet#1* *Sheet-Collection* *New-Book* *Books-Colection* *AplExcel*))
  126. (setq *AplExcel* nil)
  127. (gc)
  128. (gc)
  129. (princ))
  130. (defun C:ATTEXP2XL  (/ blk pat head ss datalist att_list)
  131. (if (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 66 1)(if (getvar "CTAB")
  132.          (cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE")))))))
  133.    (progn
  134.      (foreach item  (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  135.    (setq att_list (get-all-atts item))
  136.    (if (null head)
  137.      (setq head (mapcar 'car att_list)))
  138.    (setq datalist (append datalist (list (mapcar 'cdr att_list))))
  139.    )
  140.      (xls datalist head nil nil)
  141.      )
  142.    )
  143. (princ)
  144. )
  145. ;|=============== Comand AREAS ================================================
  146. Send the Layer, the area, length, color, a hyperlink in corresponding columns Excel.
  147. See also _HYPERLINKOPTIONS |;
  148. (defun c:AREAS    (/ selset *error* retLst lst i UrlDes are)
  149. (defun *error* (msg) (princ msg) (princ)) ;_ end of defun
  150. (vl-load-com)
  151. (if (setq selset (ssget '((0 . "*POLYLINE"))))
  152.    (progn (setq i 1)
  153.       (foreach item  (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex selset))))
  154.         (if (not (zerop (vla-get-Count (vla-get-Hyperlinks item))))
  155.           (VL-CATCH-ALL-APPLY
  156.         '(lambda () (setq UrlDes (vla-get-URLDescription (vla-item (vla-get-Hyperlinks item) 0)))))
  157.           (setq UrlDes ""))
  158.         (setq lst (list
  159.             (strcat "'" (vla-get-layer item)) ;|Layer"|;
  160.             (rtos (setq are (vla-get-area item)) 2 12) ;|Area|;
  161.             (rtos (vla-get-Length item) 2 12) ;|Length|;
  162.             (vla-get-color item) ;|Color|;
  163.             (if (= UrlDes "")
  164.               ""
  165.               (strcat "'" UrlDes)) ;|Hyperlink|;
  166.             ))
  167.         (setq retLst (append retLst (list lst)))) ;_foreach
  168.       (xls retlst '("Layer" "Area" "Length" "Color" "Hyperlink") nil "from AREAS")))
  169. (princ))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 21:19 , Processed in 0.436406 second(s), 81 queries .

© 2020-2025 乐筑天下

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