VLA Copyobjects
自从AUGI把他们的网站搞砸了,我失去了以前所有帖子的访问权限,我想我会尝试加入这里。我之前发布了一个关于使用VLA Copyobjects的问题。我有一个例程,用用户提供的后缀创建一个新层,然后它接受任何选定对象,获取其层名称,添加后缀,然后将选定对象放在新层上,然后冻结它们。我不知道代码来自哪里,所以我不知道我应该发布它。我要做的是让程序创建对象的副本,并将其放置在新层上,而不是原始层上。我找到了VLA Copyobjects函数,但似乎无法使其工作。有没有人有什么好的例子,或者甚至可能有什么已经做到了这一点?
提前谢谢。 欢迎来到CADWGILL
vla CopyObjects更适合在数据库之间复制,而不是在同一个数据库中复制对象-为此,我将使用vla copy。
我稍后将发布一个示例 谢谢你的欢迎。
这是有道理的,如果我能记住我的另一条线索,我想这也是有人建议的。Peter Jamtgaard确实发布了一个使用vla CopyObjects的示例,但正如我所说,我失去了对它的所有访问权限。我期待你的榜样。 我认为另一种更优雅的方法是使用CopyObjects将所有对象复制到ObjectDBX文档,将层后缀添加到所有层,然后将它们复制回工作文档中。。。 远远超过我的头。尽管我已经编写了几年代码,但我现在才开始更加深入地研究Vlisp。AutoCAD的新帮助系统无法帮助实现这一过渡。
真的-我尝试了AutoCAD 2011的帮助,但根本无法继续。。。 我发现我自己打开了chm的帮助,从他们发布的修复,并试图从那里去。另一个问题是,vla函数的上下文启用帮助从未起作用,它总是返回一个页面未找到错误。你可能认为Autodesk现在已经解决了这个问题。也许明年。。。 尝试了CopyObjects方法:
(defun c:CopytoLayerSuffix ( / *error* doc spc l s dbx var )
(vl-load-com)
;; © Lee Mac 2010
(defun *error* ( msg )
(if dbx (vlax-release-object dbx))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)
)
(LM:ActiveSpace 'doc 'spc)
(if (setq l (LM:ss->vla (ssget "_:L" (list (cons 410 (getvar 'CTAB))))))
(progn
(setq s (getstring t "\nSpecify Layer Suffix: "))
(setq dbx (LM:ObjectDBXDocument)
var (vla-CopyObjects doc (LM:ObjectVariant l) (vla-get-ModelSpace dbx))
)
(vlax-for l (vla-get-Layers dbx)
(vl-catch-all-apply '(lambda ( la ) (vla-put-name la (strcat (vla-get-name la) s))) (list l))
)
(setq var (vla-CopyObjects dbx var spc))
(vlax-release-object dbx)
(
(lambda ( ss )
(mapcar '(lambda ( o ) (ssadd (vlax-vla-object->ename o) ss))
(vlax-safearray->list
(vlax-variant-value var)
)
)
(sssetfirst nil ss)
)
(ssadd)
)
)
)
(princ)
)
;;-------------------=={ 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
)
)
)
;;-----------------=={ 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))
)
)
)
;;-----------------=={ 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
)
)
)
;;--------------------=={ ActiveSpace }==---------------------;;
;; ;;
;;Retrieves pointers to the Active Document and Space ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;;Arguments: ;;
;;*doc - quoted symbol (other than *doc) ;;
;;*spc - quoted symbol (other than *spc) ;;
;;------------------------------------------------------------;;
(defun LM:ActiveSpace ( *doc *spc )
;; © Lee Mac 2010
(set *spc
(vlax-get-property
(set *doc
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
(if (= 1 (getvar 'CVPORT)) 'PaperSpace 'ModelSpace)
)
)
)
确切地说,该功能在2010年*有时*有效,但它引用了VBA文章,但在2011年,没有任何VBA文档,有效的VL帮助就消失了。 更新了上述内容以显示结果选择集。
页:
[1]
2