若要复制多个对象,请使用该方法或创建要与该方法一起使用的对象数组。CopyObjectsCopy 若要复制选择集中的对象,请循环访问选择集并将对象保存到数组中。遍历数组,单独复制每个对象,并将新创建的对象收集到第二个数组中。 若要将多个对象复制到其他图形,请使用该方法并将 Owner 参数设置为图形的模型空间。CopyObjects 复制两个 Circle 对象本示例创建两个对象,并使用该方法复制圆圈。CircleCopyObjects Sub Ch4_CopyCircleObjects() Dim DOC1 As AcadDocument Dim circleObj1 As AcadCircle Dim circleObj2 As AcadCircle Dim circleObj1Copy As AcadCircle Dim circleObj2Copy As AcadCircle Dim centerPoint(0 To 2) As Double Dim radius1 As Double Dim radius2 As Double Dim radius1Copy As Double Dim 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 = ThisDrawing.Application.Documents.Add ' Add two circles to the drawing Set circleObj1 = DOC1.ModelSpace.AddCircle(centerPoint, radius1) Set circleObj2 = DOC1.ModelSpace.AddCircle(centerPoint, radius2) ZoomAll ' 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 circleObj1Copy.Color = acRed circleObj2Copy.Radius = radius2Copy circleObj2Copy.Color = acRed ZoomAll End Sub 将对象复制到其他图形本示例创建对象,然后使用该方法将圆复制到新图形中。CircleCopyObjects Sub Ch4_Copy_to_New_Drawing() Dim DOC0 As AcadDocument Dim circleObj1 As AcadCircle, circleObj2 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# ' Add two circles to the current drawing Set circleObj1 = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius1) Set circleObj2 = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius2) ThisDrawing.Application.ZoomAll ' Save pointer to the current drawing Set DOC0 = ThisDrawing.Application.ActiveDocument ' Copy objects ' ' First put the objects to be copied into a form compatible ' with CopyObjects Set objCollection(0) = circleObj1 Set objCollection(1) = circleObj2 ' Create a new drawing and point to its model space Dim Doc1MSpace As AcadModelSpace Dim DOC1 As AcadDocument Set DOC1 = Documents.Add Set Doc1MSpace = DOC1.ModelSpace ' Copy the objects into the model space of the new drawing. A ' collection of the new (copied) objects is returned. retObjects = DOC0.CopyObjects(objCollection, Doc1MSpace) Dim circleObj1Copy As AcadCircle, circleObj2Copy As AcadCircle ' Get the newly created object collection and apply new ' properties to the copies. Set circleObj1Copy = retObjects(0) Set circleObj2Copy = retObjects(1) circleObj1Copy.radius = radius1Copy circleObj1Copy.Color = acRed circleObj2Copy.radius = radius2Copy circleObj2Copy.Color = acRed ThisDrawing.Application.ZoomAll MsgBox "Circles copied." End Sub 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:46
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.