明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1578|回复: 3

[求助]如何拷贝一个文档里的对象到另一个文档里?

[复制链接]
发表于 2009-8-27 00:08:00 | 显示全部楼层 |阅读模式

开了两个document对象:doc1,doc2,如何拷贝doc1里的对象(比如一个块,或者直线)到doc2.请高手指点啊。

 楼主| 发表于 2009-8-27 00:40:00 | 显示全部楼层

在已经用cad打开两个已经保存过的dwg文件的前提下,运行如下代码:

Sub a()
Dim lobj As AcadLine, lobj2 As AcadLine
Dim doc1 As AcadDocument, doc2 As AcadDocument
Dim spo(2) As Double, epo(2) As Double

spo(0) = 0: spo(1) = 0: spo(2) = 0
spo(0) = 5: spo(1) = 5: spo(2) = 0
Set doc1 = ThisDrawing.Application.Documents(0)
Set doc2 = ThisDrawing.Application.Documents(1)
ThisDrawing.Application.ActiveDocument = doc1
Set lobj = ThisDrawing.ModelSpace.AddLine(spo, epo)
ThisDrawing.Application.ActiveDocument = doc2
Set lobj2 = lobj.Copy

End Sub

doc2没有直线,这是为什么呢?当然了,我也可以自己在doc2里用这个语句来实现Set lobj = ThisDrawing.ModelSpace.AddLine(spo, epo)
,但是我想知道从doc1拷贝到doc2,要用什么方法,请高手指点啊。

发表于 2009-8-27 05:38:00 | 显示全部楼层

Sub a()
Dim lobj As AcadLine, lobj2 As AcadLine
Dim doc1 As AcadDocument, doc2 As AcadDocument
Dim spo(2) As Double, epo(2) As Double

spo(0) = 0: spo(1) = 0: spo(2) = 0
spo(0) = 5: spo(1) = 5: spo(2) = 0
Set doc1 = ThisDrawing.Application.Documents(0)
Set doc2 = ThisDrawing.Application.Documents(1)
'ThisDrawing.Application.ActiveDocument = doc1
'Set lobj = ThisDrawing.ModelSpace.AddLine(spo, epo)

Set lobj = doc1.ModelSpace.AddLine(spo, epo)
'ThisDrawing.Application.ActiveDocument = doc2
'Set lobj2 = lobj.Copy
Dim Objs(0) As Object, Objs2 As Variant
Set Objs(0) = lobj
Objs2 = doc1.CopyObjects(Objs, doc2.ModelSpace)
Set lobj2 = Objs2(0)

End Sub

 楼主| 发表于 2009-8-27 12:43:00 | 显示全部楼层

非常感谢woaishuijia,经君一点,胜阅“F1”!

高!

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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