CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

CopyObjects Method (ActiveX)

2023-1-4 11:15| 发布者: admin| 查看: 624| 评论: 0|来自: AutoCAD

摘要: 复制多个对象(深度克隆)。

复制多个对象(深度克隆)。

支持的平台:仅窗口

签名

工 务 局:

RetVal = object.CopyObjects(Objects [, Owner] [, IDPairs])
对象

类型:数据库文档

此方法适用的对象。

对象

访问:仅输入

类型:变体(对象数组))

要复制的主要对象的数组。所有对象必须具有相同的所有者,并且所有者必须属于调用此方法的数据库或文档。

所有者

访问:仅输入;自选

类型:变体(单个对象)

复制对象的新所有者。如果未指定所有者,则将使用与数组中的对象相同的所有者创建对象。Objects

IDPairs

访问:输入输出;自选

类型:变体(对象数组)IDPair

有关复制和翻译过程中发生的情况的信息。

  • 输入:空变体。
  • 输出:对象数组。IDPair

返回值(RetVal)

类型:变体(对象数组)

新创建的重复对象的数组。此数组中仅返回主对象。有关操作期间发生的情况的详细信息,或主对象拥有的对象列表,也已复制,请参阅IDPairs参数。CopyObjects

言论

要将对象复制到另一个打开的图形,请将Owner参数设置为其他图形的模型空间。

在操作过程中,还将复制Objects参数中主要对象拥有或引用的对象。CopyObjects

注意:不能在循环访问集合的同时执行此方法。迭代将为只读操作打开工作空间,而此方法将尝试执行读写操作。在调用此方法之前完成任何迭代。

例子

工 务 局:

Sub Example_CopyObjects()
    ' This example creates a Circle object and uses the CopyObjects
    ' method to make a copy of the new Circle.

    Dim DOC1 As AcadDocument
    Dim circleObj1 As AcadCircle, circleObj2 As AcadCircle
    Dim circleObj1Copy As AcadCircle, circleObj2Copy As AcadCircle
    Dim centerPoint(0 To 2) As Double
    Dim radius1 As Double, radius2 As Double
    Dim radius1Copy As Double, radius2Copy As Double
    Dim objCollection(0 To 1) As Object
    Dim retObjects As Variant
    
    ' Define the Circle object
    centerPoint(0) = 0: centerPoint(1) = 0: centerPoint(2) = 0
    radius1 = 5#: radius2 = 7#
    radius1Copy = 1#: radius2Copy = 2#
    
    ' Create a new drawing
    Set DOC1 = Documents.Add
    
    ' Add two circles to the drawing
    Set circleObj1 = DOC1.ModelSpace.AddCircle(centerPoint, radius1)
    Set circleObj2 = DOC1.ModelSpace.AddCircle(centerPoint, radius2)
    ThisDrawing.Application.ZoomAll
    
    ' Copy objects
    '
    ' First put the objects to be copied into a form compatible with CopyObjects
    Set objCollection(0) = circleObj1
    Set objCollection(1) = circleObj2
    
    ' Copy object and get back a collection of the new objects (copies)
    retObjects = DOC1.CopyObjects(objCollection)
    
    ' Get newly created object and apply new properties to the copies
    Set circleObj1Copy = retObjects(0)
    Set circleObj2Copy = retObjects(1)
    
    circleObj1Copy.radius = radius1Copy
    circleObj2Copy.radius = radius2Copy
        
    ThisDrawing.Application.ZoomAll
    
    MsgBox "Circles copied."
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_CopyObjects()
    ;; This example creates a Circle object and uses the CopyObjects
    ;; method to make a copy of the new Circle.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    ;; Load the ObjectDBX library
    (if (= acLibImport nil)
	       (progn
	           (vlax-import-type-library :tlb-filename "C:\\Program Files\\Common Files\\Autodesk Shared\\axdb24enu.tlb"
	                                     :methods-prefix "acdbm-"
	                                     :properties-prefix "acdbp-"
	                                     :constants-prefix "acdbc-"
	           )
            (setq acLibImport T)
        )
    )

    ;; Create a reference to the ObjectDBX object
    (setq acdbObj (vlax-create-object "ObjectDBX.AxDbDocument.24"))

    ;; Open an external drawing file
    (acdbm-open acdbObj (findfile ".\\Sample\\VBA\\Tower.dwg"))

    ;; Add two circles to the drawing
    (setq objCollection (vlax-make-safearray vlax-vbObject (cons 0 (- (vla-get-Count (vla-get-ModelSpace acdbObj)) 1)))
	  count 0)

    ;; Copy objects
    (vlax-for eachObj (vla-get-ModelSpace acdbObj)
        (vlax-safearray-put-element objCollection count eachObj)
        (setq count (1+ count))
    )
     
    ;; Copy object and get back a collection of the new objects (copies)
    (setq retObjects (vla-CopyObjects acdbObj objCollection (vla-get-ModelSpace (vla-get-Database doc))))
    
    (vla-ZoomAll acadObj)
    
    (alert "Model space objects copied.")

    ;; Close the in memory drawing
    (vlax-release-object acdbObj)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部