Crazyhoof 发表于 2009-8-27 00:08:00

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

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

Crazyhoof 发表于 2009-8-27 00:40:00

<p>在已经用cad打开两个已经保存过的dwg文件的前提下,运行如下代码:</p><p>Sub a()<br/>Dim lobj As AcadLine, lobj2 As AcadLine<br/>Dim doc1 As AcadDocument, doc2 As AcadDocument<br/>Dim spo(2) As Double, epo(2) As Double</p><p>spo(0) = 0: spo(1) = 0: spo(2) = 0<br/>spo(0) = 5: spo(1) = 5: spo(2) = 0<br/>Set doc1 = ThisDrawing.Application.Documents(0)<br/>Set doc2 = ThisDrawing.Application.Documents(1)<br/>ThisDrawing.Application.ActiveDocument = doc1<br/>Set lobj = ThisDrawing.ModelSpace.AddLine(spo, epo)<br/>ThisDrawing.Application.ActiveDocument = doc2<br/>Set lobj2 = lobj.Copy</p><p>End Sub<br/></p><p>doc2没有直线,这是为什么呢?当然了,我也可以自己在doc2里用这个语句来实现Set lobj = ThisDrawing.ModelSpace.AddLine(spo, epo)<br/>,但是我想知道从doc1拷贝到doc2,要用什么方法,请高手指点啊。</p>

woaishuijia 发表于 2009-8-27 05:38:00

<p>Sub a()<br/>Dim lobj As AcadLine, lobj2 As AcadLine<br/>Dim doc1 As AcadDocument, doc2 As AcadDocument<br/>Dim spo(2) As Double, epo(2) As Double</p><p>spo(0) = 0: spo(1) = 0: spo(2) = 0<br/>spo(0) = 5: spo(1) = 5: spo(2) = 0<br/>Set doc1 = ThisDrawing.Application.Documents(0)<br/>Set doc2 = ThisDrawing.Application.Documents(1)<br/><font color="#00ff00">'ThisDrawing.Application.ActiveDocument = doc1<br/>'Set lobj = ThisDrawing.ModelSpace.AddLine(spo, epo)</font><br/><font color="#ff0000">Set lobj = doc1.ModelSpace.AddLine(spo, epo)<br/></font><font color="#00ff00">'ThisDrawing.Application.ActiveDocument = doc2<br/>'Set lobj2 = lobj.Copy<br/></font><font color="#ff0000">Dim Objs(0) As Object, Objs2 As Variant<br/>Set Objs(0) = lobj<br/>Objs2 = doc1.CopyObjects(Objs, doc2.ModelSpace)<br/>Set lobj2 = Objs2(0)</font></p><p>End Sub</p>

Crazyhoof 发表于 2009-8-27 12:43:00

<p>非常感谢<strong><font face="Verdana" color="#61b713">woaishuijia,<font color="#000000">经君一点,胜阅“F1”!</font></font></strong></p><p><strong><font face="Verdana">高!</font></strong></p><p><strong><font face="Verdana" color="#61b713"></font></strong></p>
页: [1]
查看完整版本: [求助]如何拷贝一个文档里的对象到另一个文档里?