明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1681|回复: 0

[已解决]QueryInterface IID_IAcadBaseObject 失败 如何解决??

[复制链接]
发表于 2008-6-6 16:37:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-6-6 17:06:57 编辑

下面这段代码是CAD2006VBA参考上的例子,我做了部分修改。
这段代码在一台电脑上运行能正常,但到另一台电脑上却在此语句
   retObjects = DOC1.CopyObjects(objCollection, DOC2)

处报错:QueryInterface IID_IAcadBaseObject 失败
请教此错误是如何产生的?应该如何解决?
  1. Sub Example_CopyObjects()
  2.     ' This example creates a Circle object and uses the CopyObjects
  3.     ' method to make a copy of the new Circle.
  4.     Dim DOC1 As AcadDocument
  5.     Dim DOC2 As AcadDocument
  6.     Dim circleObj1 As AcadCircle, circleObj2 As AcadCircle
  7.     Dim circleObj1Copy As AcadCircle, circleObj2Copy As AcadCircle
  8.     Dim centerPoint(0 To 2) As Double
  9.     Dim radius1 As Double, radius2 As Double
  10.     Dim radius1Copy As Double, radius2Copy As Double
  11.     Dim objCollection(0 To 1) As Object
  12.     Dim retObjects As Variant
  13.    
  14.     ' Define the Circle object
  15.     centerPoint(0) = 0: centerPoint(1) = 0: centerPoint(2) = 0
  16.     radius1 = 5#: radius2 = 7#
  17.     radius1Copy = 1#: radius2Copy = 2#
  18.    
  19.     ' Create a new drawing
  20.     Set DOC2 = Documents(0)
  21.     Set DOC1 = Documents.Add
  22.    
  23.     ' Add two circles to the drawing
  24.     Set circleObj1 = DOC1.ModelSpace.AddCircle(centerPoint, radius1)
  25.     Set circleObj2 = DOC1.ModelSpace.AddCircle(centerPoint, radius2)
  26.     ThisDrawing.Application.ZoomAll
  27.    
  28.     ' Copy objects
  29.     '
  30.     ' First put the objects to be copied into a form compatible with CopyObjects
  31.     Set objCollection(0) = circleObj1
  32.     Set objCollection(1) = circleObj2
  33.    
  34.     ' Copy object and get back a collection of the new objects (copies)
  35.     retObjects = DOC1.CopyObjects(objCollection, DOC2)
  36.    
  37.     ' Get newly created object and apply new properties to the copies
  38.     Set circleObj1Copy = retObjects(0)
  39.     Set circleObj2Copy = retObjects(1)
  40.    
  41.     circleObj1Copy.Radius = radius1Copy
  42.     circleObj2Copy.Radius = radius2Copy
  43.         
  44.     ThisDrawing.Application.ZoomAll
  45.    
  46. '    MsgBox "Circles copied."
  47. End Sub
不好意思,是我粗心大意,把代码打漏了,应该是这样就对了: retObjects = DOC1.CopyObjects(objCollection, DOC2.ModelSpace)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 08:23 , Processed in 0.168565 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表