CopyObjects方法在多个图形之间传递数据时注意:用拥有要复制实体的文档来调用
下面的代码用于将当前图形中的对象复制到其他打开的图形:<BR>Public Sub CopyFromOuterDwg()<BR> ' 判断图形是否存在<BR> If Len(Dir("C:\test.dwg")) = 0 Then<BR> MsgBox "指定的图形不存在!", vbCritical<BR> Exit Sub<BR> End If<BR> <BR> Dim objCurDoc As AcadDocument<BR> Set objCurDoc = ThisDrawing.Application.ActiveDocument<BR> <BR> ' 打开一个新图形<BR> Dim objNewDoc As AcadDocument<BR> Set objNewDoc = ThisDrawing.Application.Documents.Open("C:\test.dwg")<BR> <BR> ' 将原来的图形设置为当前图形<BR> 'ThisDrawing.Application.ActiveDocument = objCurDoc' 将外部图形的实体复制到当前图形<BR> Dim objCollection(0 To 1) As Object<BR> Set objCollection(0) = objNewDoc.ModelSpace.Item(0)<BR> Set objCollection(1) = objNewDoc.ModelSpace.Item(1)<BR> objNewDoc.CopyObjects objCollection, objCurDoc.ModelSpace<BR> <BR> ' 关闭打开的图形<BR> objNewDoc.Close<BR>End Sub
接下来的代码用于将其他打开的图形中的对象复制到当前图形(不可用):<BR>Public Sub CopyFromOuterDwg()<BR> ' 判断图形是否存在<BR> If Len(Dir("C:\test.dwg")) = 0 Then<BR> MsgBox "指定的图形不存在!", vbCritical<BR> Exit Sub<BR> End If<BR> <BR> Dim objCurDoc As AcadDocument<BR> Set objCurDoc = ThisDrawing.Application.ActiveDocument<BR> <BR> ' 打开一个新图形<BR> Dim objNewDoc As AcadDocument<BR> Set objNewDoc = ThisDrawing.Application.Documents.Open("C:\test.dwg")<BR> <BR> ' 将原来的图形设置为当前图形<BR> ThisDrawing.Application.ActiveDocument = objCurDoc
' 将外部图形的实体复制到当前图形<BR> Dim objCollection(0 To 1) As Object<BR> Set objCollection(0) = objNewDoc.ModelSpace.Item(0)<BR> Set objCollection(1) = objNewDoc.ModelSpace.Item(1)<BR> 'objNewDoc.CopyObjects objCollection, objCurDoc.ModelSpace<BR> ThisDrawing.CopyObjects objCollection, objCurDoc.ModelSpace<BR> <BR> ' 关闭打开的图形<BR> objNewDoc.Close<BR>End Sub
页:
[1]