MarcoW 发表于 2022-7-6 10:00:24

给那些无聊的人一个主意

大家好,
 
想象一下,我正在处理一个附着了外部参照的图形,我需要从实际图形中剪切/复制一些内容,并将其粘贴到外部参照中。
 
此时,我使用ctrl+shift+c,选择基点和项目,并打开外部参照,以便将对象粘贴为块或不粘贴为块。正如你所猜测的那样,这很好,但是制作一个lisp怎么样?
 
在此过程中,我想到了将对象发送到外部参照。相同的步骤:选择对象和基点。
然后“将其发送到外部参照,选择外部参照,点击enter并准备就绪。
 
这不是一个请求,只是我分享的一个想法。也许你喜欢这个主意,想试试。。。

Guest kruuger 发表于 2022-7-6 10:07:12

好主意,马可。我不是一个Lisp程序的人,但也许有人。。。
克鲁格

pBe 发表于 2022-7-6 10:09:45

这将大大减少编辑外部参照文件所花费的时间。这是一个挑战,我愿意参与(不是)
是的,为什么不呢,我打赌有人会。。。。。。我想现在我会坚持“观察和学习”模式

Lee Mac 发表于 2022-7-6 10:13:30

我非常认为这是可以做到的-我已经完成了一半-它只需要修改以删除图形提示,而不是提示输入外部参照,然后检索图形路径,最后可能删除原始对象。

MarcoW 发表于 2022-7-6 10:17:29

 
哇,李代码不错!事实上,这几乎就是我的意思。你对我有什么看法吗?
对于那些可能有点“可疑”的人;我测试了代码,当然可以!
 
李,请不要修改代码(现在)。当我有时间的时候,也许我可以帮点忙。。。

Lee Mac 发表于 2022-7-6 10:20:55

 
对不起,伙计,我忍不住了
 
http://lee-mac.com/copytoxref.html
 
其中涉及的内容比我最初描述的要多一些,以说明对象相对于外部参照插入的相对位置,并进一步说明外部参照的比例/旋转/法线。
 
 

MarcoW 发表于 2022-7-6 10:25:57

李,
 
检查我对代码的添加。我在谷歌上找到了一些帮助:
 

;;-------------------=={ Copy to Drawing }==------------------;;
;;                                                            ;;
;;Enables a user to copy a SelectionSet of objects to a   ;;
;;selected drawing. Layout on which objects reside will be;;
;;created if non-existent.                                  ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
(defun c:C2DWG nil (c:CopytoDrawing))
(defun c:CopytoDrawing ( / *error* _StartUndo _EndUndo ac dbx doc dwgs dwg ss XrPath)
;; © Lee Mac 2010
(vl-load-com)
(defun *error* ( msg )
   (LM:ReleaseObject dbx) (if doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
)
(defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
)
(defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
   (vla-EndUndoMark doc)
   )
)
(setq doc (vla-get-ActiveDocument (setq ac (vlax-get-acad-object))))
(vlax-map-collection (vla-get-Documents ac)
'(lambda ( d )
   (setq dwgs (cons (cons (strcase (vla-get-fullname d)) d) dwgs))
   )
)
(if (and (setq ss(ssget (list (cons 410 (setq tab (getvar 'CTAB))))))

   ; Next, getfiled, will return the destination file including path.
   ; I turn this part off first.
          ; (setq dwg (getfiled "Select Drawing to Copy to" "" "dwg" 16))
   ; Now, how to retrieve the xref's name and path?
   ; See the SubFunction below, it returns the Xref name and path
   (GetXrefPath)
   ; Put the content of variable XrPath into the variable dwg
   (setq dwg XrPath)
   ; I remember: localise dwg and / or XrPath, see above in main function

   );_and

   (progn
   (_StartUndo doc)
   (if (setq dbx (cond ( (cdr (assoc (strcase dwg) dwgs)) )
                         ( (not (vl-catch-all-error-p
                                  (vl-catch-all-apply 'vla-open
                                    (list (setq dbx (LM:ObjectDBXDocument)) dwg)))) dbx)))
       (progn
         (LM:CopyObjects (LM:ss->vla ss) doc (vla-get-Block (cond ( (LM:Itemp (vla-get-layouts dbx) tab) )
                                                                  ( (vla-add(vla-get-layouts dbx) tab) ))))
         (vla-saveas dbx dwg)
       )
   )
   (_EndUndo doc)
   )
)
   (LM:ReleaseObject dbx)
; To make shure the right Xref is reloaded I use this, I have no better idea
; First what is NOT working, reload only the selected Xref:
; (vl-cmdf "_.xref" "_reload" dwg); WHY NOT ??
; This does work however:
(vl-cmdf "_.xref" "_reload" "*")
; Takes a little more time, that shouldn't be

(princ)
)
;;-----------------=={ ObjectDBX Document }==-----------------;;
;;                                                            ;;
;;Retrieves a version specific ObjectDBX Document object    ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments: - None -                                       ;;
;;------------------------------------------------------------;;
;;Returns:VLA ObjectDBX Document object, else nil         ;;
;;------------------------------------------------------------;;
(defun LM:ObjectDBXDocument ( / acVer )
;; © Lee Mac 2010
(vla-GetInterfaceObject (vlax-get-acad-object)
   (if (< (setq acVer (atoi (getvar "ACADVER"))) 16)
   "ObjectDBX.AxDbDocument"
   (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
   )
)
)
;;------------------=={ Release Object }==--------------------;;
;;                                                            ;;
;;Releases a VLA Object from memory via plentiful error   ;;
;;trapping                                                ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;obj - VLA Object to be released from memory               ;;
;;------------------------------------------------------------;;
;;Returns:T if Object Released, else nil                  ;;
;;------------------------------------------------------------;;
(defun LM:ReleaseObject ( obj ) (vl-load-com)
;; © Lee Mac 2010
(and obj (eq 'VLA-OBJECT (type obj)) (not (vlax-object-released-p obj))
   (not
   (vl-catch-all-error-p
       (vl-catch-all-apply
         (function vlax-release-object) (list obj)
       )
   )
   )
)
)
;;--------------------=={ Copy Objects }==--------------------;;
;;                                                            ;;
;;Applies a deep-clone copy to a list of objects            ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;lst   - List of Objects to Copy                           ;;
;;owner - Owner of Objects in List                        ;;
;;dest- Destination for Copied Objects                  ;;
;;------------------------------------------------------------;;
;;Returns:Array of Copied Objects                         ;;
;;------------------------------------------------------------;;
(defun LM:CopyObjects ( lst owner dest )
;; © Lee Mac 2010
(vla-CopyObjects owner (LM:ObjectVariant lst) dest)
)
;;-------------------=={ Object Variant }==-------------------;;
;;                                                            ;;
;;Creates a populated Object Variant                        ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;lst - list of VLA Objects to populate the Variant.      ;;
;;------------------------------------------------------------;;
;;Returns:VLA Object Variant                              ;;
;;------------------------------------------------------------;;
(defun LM:ObjectVariant ( lst )
;; © Lee Mac 2010
(LM:SafearrayVariant vlax-vbobject lst)
)
;;------------------=={ Safearray Variant }==-----------------;;
;;                                                            ;;
;;Creates a populated Safearray Variant of a specified      ;;
;;data type                                                 ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;datatype - variant type enum (eg vlax-vbDouble)         ;;
;;data   - list of static type data                     ;;
;;------------------------------------------------------------;;
;;Returns:VLA Variant Object of type specified            ;;
;;------------------------------------------------------------;;
(defun LM:SafearrayVariant ( datatype data )
;; © Lee Mac 2010
(vlax-make-variant
   (vlax-safearray-fill
   (vlax-make-safearray datatype
       (cons 0 (1- (length data)))
   )
   data
   )   
)
)
;;-----------------=={ SelectionSet -> VLA }==----------------;;
;;                                                            ;;
;;Converts a SelectionSet to a list of VLA Objects          ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;ss - Valid SelectionSet (Pickset)                         ;;
;;------------------------------------------------------------;;
;;Returns:List of VLA Objects                           ;;
;;------------------------------------------------------------;;
(defun LM:ss->vla ( ss )
;; © Lee Mac 2010
(if ss
   (
   (lambda ( i / e l )
       (while (setq e (ssname ss (setq i (1+ i))))
         (setq l (cons (vlax-ename->vla-object e) l))
       )
       l
   )
   -1
   )
)
)
;;-----------------------=={ Itemp }==------------------------;;
;;                                                            ;;
;;Retrieves the item with index 'item' if present in the    ;;
;;specified collection, else nil                            ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;Arguments:                                                ;;
;;coll - the VLA Collection Object                        ;;
;;item - the index of the item to be retrieved            ;;
;;------------------------------------------------------------;;
;;Returns:the VLA Object at the specified index, else nil ;;
;;------------------------------------------------------------;;
(defun LM:Itemp ( coll item )
;; © Lee Mac 2010
(if
   (not
   (vl-catch-all-error-p
       (setq item
         (vl-catch-all-apply
         (function vla-item) (list coll item)
         )
       )
   )
   )
   item
)
)
; My addition to retrieve the xref's path and name
(defun GetXrefPath ( / XrFile );XrPath)
(setq XrFile(car (entsel "\nSelect external reference to copy the objects to: "))
XrFile(vlax-ename->vla-object XrFile)
XrPath   (vla-get-path XrFile)
);_setq

(princ)
) ;_defun
;|«Visual LISP© Format Options»
(120 2 1 2 nil "Ende von " 100 9 0 0 0 T T nil T)
;*** DO NOT add text below the comment! ***|;


 
这是可行的,但有时UCS会出现问题。。。
我的意思是它复制了但没有达到正确的点。可能是因为外部参照插入到不同的插入点?
 
到目前为止你说什么?

Lee Mac 发表于 2022-7-6 10:27:58

 
不错,马可!似乎您非常了解代码的整体工作原理,当前修改会将对象复制到外部参照,但对象将相对于当前图形的WCS原点而不是外部参照插入的原点进行复制。我还将所有用户输入放入主程序,并将外部参照子对象馈送到选定对象(使其更像一个通用子对象)。

Glen1980 发表于 2022-7-6 10:33:31

请原谅我的模糊,但这是否已经是xref edit in place中的一个命令?在LT2010中,我可以在适当的位置打开x-ref,然后使用出现的图标,使x-ref的元素进入主图形或主图形的元素成为x-ref的一部分。
 
除非我误解了你想要什么,或者x-ref编辑在你的办公室是一个问题,否则我知道当项目开始时,你总会在你想要使用的图纸中找到一位同事。

Lee Mac 发表于 2022-7-6 10:35:12

 
我正准备接受编码挑战
页: [1] 2
查看完整版本: 给那些无聊的人一个主意