明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1330|回复: 5

[源码] 求改块基点源码

[复制链接]
发表于 2015-7-23 16:03 | 显示全部楼层 |阅读模式
5明经币
求像贱人工具  求改块基点源码....


最佳答案

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2015-7-23 16:03 | 显示全部楼层

  1. ;; -- Retains Insertion Point --
  2. (defun c:CBI  nil (ChangeBlockInsertion nil))

  3. ;; -- Retains Block Position --
  4. (defun c:CBIR nil (ChangeBlockInsertion   t))

  5. ;;------------------------------------------------------------;;
  6. ;;                     Local Functions                        ;;
  7. ;;------------------------------------------------------------;;

  8. (defun ChangeBlockInsertion

  9.   ( retainposition / *error* _StartUndo _EndUndo acblk acdoc blk bn cmd lst mat p1 p2 pt vec )
  10.   
  11.   (defun *error* ( msg )
  12.     (if acdoc (_EndUndo acdoc))
  13.     (if cmd   (setvar 'CMDECHO cmd))
  14.     (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  15.         (princ (strcat "\n** Error: " msg " **")))
  16.     (princ)
  17.   )

  18.   (defun _StartUndo ( doc ) (_EndUndo doc)
  19.     (vla-StartUndoMark doc)
  20.   )

  21.   (defun _EndUndo ( doc )
  22.     (if (= 8 (logand 8 (getvar 'UNDOCTL)))
  23.       (vla-EndUndoMark doc)
  24.     )
  25.   )

  26.   (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
  27.         acblk (vla-get-blocks acdoc)
  28.         cmd   (getvar 'CMDECHO)
  29.   )
  30.   (setvar 'CMDECHO 0)

  31.   (if
  32.     (and
  33.       (setq blk
  34.         (car
  35.           (LM:Selectif "\nSelect Block: "
  36.            '(lambda ( x ) (eq "INSERT" (cdr (assoc 0 (entget (car x)))))) entsel nil
  37.           )
  38.         )
  39.       )
  40.       (setq pt (getpoint "\nSpecify New Base Point: "))
  41.     )
  42.     (progn
  43.       (_StartUndo acdoc)

  44.       (setq lst (entget blk) mat (LM:Ref->Def blk))
  45.       (setq vec
  46.         (mxv (car mat)
  47.           (mapcar '- (trans pt 1 0) (trans (cdr (assoc 10 lst)) blk 0))
  48.         )
  49.       )
  50.       (setq p1 (vlax-3D-point vec)
  51.             p2 (vlax-3D-point '(0. 0. 0.))
  52.       )
  53.       (vlax-for obj (vla-item acblk (setq bn (cdr (assoc 2 lst)))) (vla-Move obj p1 p2))

  54.       (if retainposition
  55.         (vlax-for block acblk
  56.           (if (eq :vlax-false (vla-get-isXref block))
  57.             (vlax-for obj block
  58.               (if
  59.                 (and
  60.                   (eq "AcDbBlockReference" (vla-get-objectname obj))
  61.                   (eq bn (vla-get-name obj))
  62.                 )
  63.                 (vla-move obj p2 (vlax-3D-point (mxv (car (LM:Def->Ref (vlax-vla-object->ename obj))) vec)))
  64.               )
  65.             )
  66.           )
  67.         )
  68.       )
  69.       (if (= 1 (cdr (assoc 66 lst)))
  70.         (vl-cmdf "_.attsync" "_N" (cdr (assoc 2 lst)))
  71.       )
  72.       (vla-regen acdoc acAllViewports)
  73.       (_EndUndo acdoc)
  74.     )
  75.   )
  76.   (setvar 'CMDECHO cmd)
  77.   (princ)
  78. )

  79. ;;---------------=={ Block Ref -> Block Def }==---------------;;
  80. ;;                                                            ;;
  81. ;;  Returns the Transformation Matrix and Translation Vector  ;;
  82. ;;  for transforming Block Reference Geometry to the Block    ;;
  83. ;;  Definiton.                                                ;;
  84. ;;------------------------------------------------------------;;
  85. ;;  Author: Lee Mac, Copyright  2011 - www.lee-mac.com       ;;
  86. ;;------------------------------------------------------------;;
  87. ;;  Arguments:                                                ;;
  88. ;;  e - Block Reference Entity                                ;;
  89. ;;------------------------------------------------------------;;
  90. ;;  Returns:  List of 3x3 Transformation Matrix, Vector       ;;
  91. ;;------------------------------------------------------------;;

  92. (defun LM:Ref->Def ( e / _dxf a l n )

  93.   (defun _dxf ( x l ) (cdr (assoc x l)))

  94.   (setq l (entget e) a (- (_dxf 50 l)) n (_dxf 210 l))
  95.   (
  96.     (lambda ( m )
  97.       (list m
  98.         (mapcar '- (_dxf 10 (tblsearch "BLOCK" (_dxf 2 l)))
  99.           (mxv m
  100.             (trans (_dxf 10 l) n 0)
  101.           )
  102.         )
  103.       )
  104.     )
  105.     (mxm
  106.       (list
  107.         (list (/ 1. (_dxf 41 l)) 0. 0.)
  108.         (list 0. (/ 1. (_dxf 42 l)) 0.)
  109.         (list 0. 0. (/ 1. (_dxf 43 l)))
  110.       )
  111.       (mxm
  112.         (list
  113.           (list (cos a) (sin (- a)) 0.)
  114.           (list (sin a) (cos a)     0.)
  115.           (list    0.        0.     1.)
  116.         )
  117.         (mapcar '(lambda ( e ) (trans e n 0 t))
  118.          '(
  119.             (1. 0. 0.)
  120.             (0. 1. 0.)
  121.             (0. 0. 1.)
  122.           )
  123.         )
  124.       )
  125.     )
  126.   )
  127. )

  128. ;;---------------=={ Block Def -> Block Ref }==---------------;;
  129. ;;                                                            ;;
  130. ;;  Returns the Transformation Matrix and Translation Vector  ;;
  131. ;;  for transforming Block Definition Geometry to a Block     ;;
  132. ;;  Reference.                                                ;;
  133. ;;------------------------------------------------------------;;
  134. ;;  Author: Lee Mac, Copyright  2011 - www.lee-mac.com       ;;
  135. ;;------------------------------------------------------------;;
  136. ;;  Arguments:                                                ;;
  137. ;;  e - Block Reference Entity                                ;;
  138. ;;------------------------------------------------------------;;
  139. ;;  Returns:  List of 3x3 Transformation Matrix, Vector       ;;
  140. ;;------------------------------------------------------------;;

  141. (defun LM:Def->Ref ( e / _dxf a l n )

  142.   (defun _dxf ( x l ) (cdr (assoc x l)))

  143.   (setq l (entget e) a (_dxf 50 l) n (_dxf 210 l))
  144.   (
  145.     (lambda ( m )
  146.       (list m
  147.         (mapcar '- (trans (_dxf 10 l) n 0)
  148.           (mxv m
  149.             (_dxf 10 (tblsearch "BLOCK" (_dxf 2 l)))
  150.           )
  151.         )
  152.       )
  153.     )
  154.     (mxm
  155.       (mapcar '(lambda ( e ) (trans e 0 n t))
  156.        '(
  157.           (1. 0. 0.)
  158.           (0. 1. 0.)
  159.           (0. 0. 1.)
  160.         )
  161.       )
  162.       (mxm
  163.         (list
  164.           (list (cos a) (sin (- a)) 0.)
  165.           (list (sin a) (cos a)     0.)
  166.           (list    0.        0.     1.)
  167.         )
  168.         (list
  169.           (list (_dxf 41 l) 0. 0.)
  170.           (list 0. (_dxf 42 l) 0.)
  171.           (list 0. 0. (_dxf 43 l))
  172.         )
  173.       )
  174.     )
  175.   )
  176. )

  177. ;;---------------------=={ Select if }==----------------------;;
  178. ;;                                                            ;;
  179. ;;  Provides continuous selection prompts until either a      ;;
  180. ;;  predicate function is validated or a keyword is supplied. ;;
  181. ;;------------------------------------------------------------;;
  182. ;;  Author: Lee Mac, Copyright  2011 - www.lee-mac.com       ;;
  183. ;;------------------------------------------------------------;;
  184. ;;  Arguments:                                                ;;
  185. ;;  msg  - prompt string                                      ;;
  186. ;;  pred - optional predicate function [selection list arg]   ;;
  187. ;;  func - selection function to invoke                       ;;
  188. ;;  keyw - optional initget argument list                     ;;
  189. ;;------------------------------------------------------------;;
  190. ;;  Returns:  Entity selection list, keyword, or nil          ;;
  191. ;;------------------------------------------------------------;;

  192. (defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred))  
  193.   (while
  194.     (progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg))
  195.       (cond
  196.         ( (= 7 (getvar 'ERRNO))
  197.           (princ "\nMissed, Try again.")
  198.         )
  199.         ( (eq 'STR (type sel))
  200.           nil
  201.         )
  202.         ( (vl-consp sel)
  203.           (if (and pred (not (pred sel)))
  204.             (princ "\nInvalid Object Selected.")
  205.           )
  206.         )
  207.       )
  208.     )
  209.   )
  210.   sel
  211. )

  212. ;; Matrix x Vector  ~  Vladimir Nesterovsky
  213. (defun mxv ( mat vec )
  214.   (mapcar '(lambda ( row ) (apply '+ (mapcar '* row vec))) mat)
  215. )

  216. ;; Matrix x Matrix  ~  Vladimir Nesterovsky
  217. (defun mxm ( m q )
  218.   (mapcar (function (lambda ( r ) (mxv (trp q) r))) m)
  219. )

  220. ;; Matrix Transpose  ~  Doug Wilson
  221. (defun trp ( m )
  222.   (apply 'mapcar (cons 'list m))
  223. )

  224. (vl-load-com) (princ)

  225. ;;------------------------------------------------------------;;
  226. ;;                         End of File                        ;;
  227. ;;------------------------------------------------------------;;
回复

使用道具 举报

发表于 2015-7-23 16:48 | 显示全部楼层
回复

使用道具 举报

发表于 2015-7-23 17:04 | 显示全部楼层
(setq ref (ssget ":E:S" '((0 . "INSERT"))))
(setq ent (ssname ref 0))
(setq edata (entget ent))
(setq name (cdr (assoc 2 edata)))
(setq inpt (vlax-3d-point (cdr (assoc 10 edata))))
(setq newpt (vlax-3d-point (getpoint)))
(setq blk (vla-item (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) 'ActiveDocument)
                              'Blocks
                    )
                    name
          )
)
(vlax-for item blk
  (vla-move item newpt inpt)
)
(vla-move (vlax-ename->vla-object ent) inpt newpt)
(entupd ent)
回复

使用道具 举报

 楼主| 发表于 2015-7-23 23:32 | 显示全部楼层
fan_zh 发表于 2015-7-23 16:03

可以用 谢谢了.
回复

使用道具 举报

 楼主| 发表于 2015-7-23 23:32 | 显示全部楼层
lucas_3333 发表于 2015-7-23 16:48
都钻石会员了,还不会用搜索.
http://bbs.mjtd.com/thread-168587-1-1.html
http://bbs.mjtd.com/fo ...

太久没来...搜了一个小时没搜到 好用的....
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-26 04:34 , Processed in 0.309731 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表