乐筑天下

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

[编程交流] 从其他图纸插入块

[复制链接]

28

主题

76

帖子

48

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-6 10:10:44 | 显示全部楼层 |阅读模式
大家好,
我想用这个lisp来插入块,但我想用另一种方式——我想在我的工具栏上做一个图标,你的lisp和dcl一起工作。我不需要这个dcl,我想做一个宏。。。你能帮我吗?这就是我说的例行公事。。。
谢谢
 
 
 
 
 
  1. ;;----------------------=={ Copy Block }==--------------------;;
  2. ;;                                                            ;;
  3. ;;  Copies the specified block definition from the specified  ;;
  4. ;;  filename to the ActiveDocument using a deep clone         ;;
  5. ;;  operation (Method inspired by Tony Tanzillo)              ;;
  6. ;;------------------------------------------------------------;;
  7. ;;  Author: Lee McDonnell, 2010                               ;;
  8. ;;                                                            ;;
  9. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  10. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  11. ;;------------------------------------------------------------;;
  12. ;;  Arguments:                                                ;;
  13. ;;  block    - string specifying block name to copy           ;;
  14. ;;  filename - filename of drawing from which to copy block   ;;
  15. ;;------------------------------------------------------------;;
  16. ;;  Returns: Block definition in ActiveDocument, else nil     ;;
  17. ;;------------------------------------------------------------;;
  18. (defun LM:CopyBlock ( block filename / acapp acdoc acblk acdocs dbxDoc item )
  19. (vl-load-com)
  20. ;; © Lee Mac 2010
  21. (setq acapp (vlax-get-acad-object)
  22.        acdoc (vla-get-ActiveDocument acapp)
  23.        acblk (vla-get-Blocks acdoc))
  24. (vlax-map-collection (vla-get-Documents acapp)
  25.    (function
  26.      (lambda ( doc )
  27.        (setq acdocs
  28.          (cons
  29.            (cons (strcase (vla-get-fullname doc)) doc) acdocs
  30.          )
  31.        )
  32.      )
  33.    )
  34. )
  35. (if
  36.    (and
  37.      (not (LM:Itemp acblk block))
  38.      (setq filename (findfile filename))
  39.      (not (eq filename (vla-get-fullname acdoc)))
  40.      (or
  41.        (setq dbxDoc (cdr (assoc (strcase filename) acdocs)))
  42.        (progn
  43.          (setq dbxDoc (LM:ObjectDBXDocument))
  44.          (not
  45.            (vl-catch-all-error-p
  46.              (vl-catch-all-apply 'vla-open (list dbxDoc filename))
  47.            )
  48.          )
  49.        )
  50.      )
  51.      (setq item (LM:Itemp (vla-get-Blocks dbxDoc) block))
  52.    )
  53.    (vla-CopyObjects dbxDoc
  54.      (vlax-make-variant
  55.        (vlax-safearray-fill
  56.          (vlax-make-safearray vlax-vbObject '(0 . 0)) (list item)
  57.        )
  58.      )
  59.      acblk
  60.    )
  61. )
  62. (and dbxDoc (vlax-release-object dbxDoc))
  63. (LM:Itemp acblk block)
  64. )
  65. ;;-----------------=={ ObjectDBX Document }==-----------------;;
  66. ;;                                                            ;;
  67. ;;  Retrieves a version specific ObjectDBX Document object    ;;
  68. ;;------------------------------------------------------------;;
  69. ;;  Author: Lee McDonnell, 2010                               ;;
  70. ;;                                                            ;;
  71. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  72. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  73. ;;------------------------------------------------------------;;
  74. ;;  Arguments: - None -                                       ;;
  75. ;;------------------------------------------------------------;;
  76. ;;  Returns:  VLA ObjectDBX Document object, else nil         ;;
  77. ;;------------------------------------------------------------;;
  78. (defun LM:ObjectDBXDocument ( / acVer )
  79. ;; © Lee Mac 2010
  80. (vla-GetInterfaceObject (vlax-get-acad-object)
  81.    (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
  82.      "ObjectDBX.AxDbDocument"
  83.      (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
  84.    )
  85. )
  86. )
  87. ;;-----------------------=={ Itemp }==------------------------;;
  88. ;;                                                            ;;
  89. ;;  Retrieves the item with index 'item' if present in the    ;;
  90. ;;  specified collection, else nil                            ;;
  91. ;;------------------------------------------------------------;;
  92. ;;  Author: Lee McDonnell, 2010                               ;;
  93. ;;                                                            ;;
  94. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  95. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  96. ;;------------------------------------------------------------;;
  97. ;;  Arguments:                                                ;;
  98. ;;  coll - the VLA Collection Object                          ;;
  99. ;;  item - the index of the item to be retrieved              ;;
  100. ;;------------------------------------------------------------;;
  101. ;;  Returns:  the VLA Object at the specified index, else nil ;;
  102. ;;------------------------------------------------------------;;
  103. (defun LM:Itemp ( coll item )
  104. ;; © Lee Mac 2010
  105. (if
  106.    (not
  107.      (vl-catch-all-error-p
  108.        (setq item
  109.          (vl-catch-all-apply
  110.            (function vla-item) (list coll item)
  111.          )
  112.        )
  113.      )
  114.    )
  115.    item
  116. )
  117. )
  118. ;;  Test Function
  119. (defun c:instbl ( / *error* doc blk dwg pt norm )
  120. (vl-load-com)
  121. ;; © Lee Mac 2010
  122. (defun *error* ( msg )
  123.    (and dbxDoc (vlax-release-object dbxDoc))
  124.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  125.        (princ (strcat "\n** Error: " msg " **")))
  126.    (princ)
  127. )
  128. (if (and
  129.        (setq blk (getstring t "\nSpecify Name of Block to Copy: "))
  130.        (setq dwg (getfiled "Select Drawing to Copy From" "" "dwg" 16))
  131.        (LM:CopyBlock blk dwg)
  132.        (setq pt  (getpoint "\nPick Point for Block: "))
  133.      )
  134.    (progn
  135.      (setq norm (trans '(0. 0. 1.) 1 0 t))
  136.      (vla-insertBlock
  137.        (if
  138.          (or
  139.            (eq AcModelSpace
  140.              (vla-get-ActiveSpace
  141.                (setq doc
  142.                  (vla-get-ActiveDocument
  143.                    (vlax-get-acad-object)
  144.                  )
  145.                )
  146.              )
  147.            )
  148.            (eq :vlax-true (vla-get-MSpace doc))
  149.          )
  150.          (vla-get-ModelSpace doc)
  151.          (vla-get-PaperSpace doc)
  152.        )
  153.        (vlax-3D-point (trans pt 1 0)) blk 1. 1. 1.
  154.        (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t))
  155.      )
  156.    )
  157. )
  158. (princ)
  159. )

insblk2.lsp
insblk2.dcl
回复

使用道具 举报

8

主题

159

帖子

153

银币

初来乍到

Rank: 1

铜币
40
发表于 2022-7-6 10:58:36 | 显示全部楼层
工具选项板对此很好(不需要lisp)?
克鲁格
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:19:25 | 显示全部楼层
嗨,弗洛波,
 
我正在为我的网站更新代码,应该很快就会出现。
 
编辑:此处:http://lee-mac.com/copyblockfromdrawing.html--尽管此版本使用对话框。
 
同时,您可以使用宏调用代码,因此:
 
  1. ^C^C(LM:CopyBlock "BlockName" "C:\\MyDrawing.dwg")
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 20:52 , Processed in 0.424545 second(s), 58 queries .

© 2020-2025 乐筑天下

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