[求助]多文档时遇到的问题,想了多天解决不了,恳请高手们帮忙
本帖最后由 作者 于 2009-5-21 10:20:00 编辑 <br /><br /> <p>如题</p><p>Set doc = ThisDrawing.Application.Documents("Drawing1.dwg")</p><p>这句如果在VB中怎么表示,好像在VB中应改成</p><p>Set doc = Acadapp.Application.Documents("Drawing1.dwg")</p><p>但是会出错,希望大家不遗余力帮我解决一个困扰多时的难题</p><p>查了很多资料,并且尝试解决了好几天仍不得解</p><p>故来论坛上请高手指点一二,谢谢!!</p><p>自定义函数</p><p>函数是修改mccad大大的,可是在VB中运行就不行!提示:实时错误,对象item 的方法‘</p><p>IAcadDocuments'失败</p><p>Set objCurDoc = acadapp.Application.Documents.Item(App.Path & "\Gallery\" & CurDocname & ".dwg")的下面一句</p><p>Set objCurDoc = acadapp.Application.Documents.Open(App.Path & "\Gallery\" & CurDocname & ".dwg")</p><p>到是可以,但我不需要那样的功能,我需要获得打开的CAD文档。</p><p> <br/>'复制到一张图纸上<br/>Public Sub CopyFromOuterDwg(CurDocname, NewDocname As String)<br/> ' 第一张图<br/> Dim objCurDoc As AcadDocument<br/> Set objCurDoc = acadapp.Application.Documents.Item(App.Path & "\Gallery\" & CurDocname & ".dwg")<br/> 'Set objCurDoc = acadapp.Application.Documents.Open(App.Path & "\Gallery\" & CurDocname & ".dwg")<br/>' 新图形<br/> Dim objNewDoc As AcadDocument<br/> Set objCurDoc = acadapp.Application.Documents.Item(App.Path & "\Gallery\" & NewDocname & ".dwg")<br/> 'Set objNewDoc = acadapp.Application.Documents.Open(App.Path & "\Gallery\" & NewDocname & ".dwg")<br/> objNewDoc.Activate<br/> 'Set objNewDoc = acadapp.Application.ActiveDocument<br/>' 将外部图形的实体复制到当前图形<br/> Set ssetobj = CreateSelectionSet<br/> ssetobj.Select acSelectionSetAll<br/> 'ssetObj.SelectOnScreen<br/> acadapp.ActiveDocument.CopyObjects ssArray(ssetobj), objCurDoc.ModelSpace<br/> objCurDoc.Regen acAllViewports<br/> ' 关闭打开的图形<br/> objNewDoc.Close<br/>End Sub</p> <p>如果是新建的可以试下</p><p>Acadapp.Application.Documents(Acadapp.Application.Documents.Count - 1)</p> 本帖最后由 作者 于 2009-5-21 9:47:29 编辑 <br /><br /> <p>不是新建的,我是打开图库中的图</p><p>所以不知道该怎么解决</p><p>VBA中就能用,在VB中咋就不能用了呢</p><p>我的想法是这样的</p><p>先打开图库中的3个图,分别操作后,放到一张图上,也就是放到一个文档上</p><p>就是在这句时不能实现</p><p>Set objCurDoc = acadapp.Application.Documents(App.Path & "\Gallery\" & NewDocname & ".dwg")</p><p>VBA中是这样的一句:Set doc = Thisdrawing.Application.Documents("Drawing1.dwg")<br/>请高手帮忙,谢谢了!</p> <p>Set doc = Acadapp.Documents("Drawing1.dwg")</p> <p>首先谢谢楼上两位的热心解答</p><p>不过我试过</p><p>Set doc = Acadapp.Documents("Drawing1.dwg")</p><p>这句还是会提示那样的错误</p><p>真不知道怎么解决,请大家用你们的智慧帮我解答下,不甚感激!</p> <p>当前文档先保存在一个变量里</p><p>然后用三个doc变量保存你打开的文档</p> lzh741206发表于2009-5-21 12:31:00static/image/common/back.gif当前文档先保存在一个变量里然后用三个doc变量保存你打开的文档<p>试了下,没有成功,能给个具体点的代码么?谢谢了</p><p></p> <p>把你的代码贴上看看吧,VBA没有装了,:)</p><p>或者你可以试下ObjectDBX?</p> lzh741206发表于2009-5-21 13:09:00static/image/common/back.gif把你的代码贴上看看吧,VBA没有装了,:)或者你可以试下ObjectDBX?
<p> <br/>'打开到一张图纸上<br/>Public Sub CopyFromOuterDwg(CurDocname As String, NewDocname As String)<br/> ' 打开第一张图<br/> Dim objCurDoc As AcadDocument<br/> Set objCurDoc = acadapp.Application.Documents(App.Path & "\Gallery\" & CurDocname & ".dwg")<br/>' 打开一个新图形<br/> Dim objNewDoc As AcadDocument<br/> Set objCurDoc = acadapp.Application.Documents(App.Path & "\Gallery\" & NewDocname & ".dwg")<br/> Set objNewDoc = acadapp.Application.ActiveDocument<br/>' 将外部图形的实体复制到当前图形<br/> Set ssetobj = CreateSelectionSet<br/> ssetobj.Select acSelectionSetAll<br/> acadapp.ActiveDocument.CopyObjects ssArray(ssetobj), objCurDoc.ModelSpace<br/> objCurDoc.Regen acAllViewports<br/> ' 关闭打开的图形<br/> objNewDoc.Close (False)<br/>End Sub</p><p>'返回包含于选择集中每一项目的变体数,参数:一选择集<br/>Public Function ssArray(ss As AcadSelectionSet)<br/> Dim retVal() As AcadEntity, k As Long<br/> ReDim retVal(0 To ss.Count - 1)<br/> For k = 0 To ss.Count - 1<br/> Set retVal(k) = ss.Item(k)<br/> Next<br/> ssArray = retVal<br/>End Function</p><p>'建立选择集<br/>'示例:acadapp.activedocument.ModelSpace.AddRegion ssArray(mySS)<br/>Public Function CreateSelectionSet(Optional ByVal SSetName As String) As AcadSelectionSet<br/> On Error Resume Next<br/> acadapp.ActiveDocument.SelectionSets(SSetName).Delete<br/> Set CreateSelectionSet = acadapp.ActiveDocument.SelectionSets.Add(SSetName)<br/>End Function</p> 试下吧
'打开到一张图纸上
Public Sub CopyFromOuterDwg(CurDocname As String, NewDocname As String)
' 打开第一张图
Dim objCurDoc As AcadDocument
Set objCurDoc = acadapp.Application.Documents(App.Path & "\Gallery\" & CurDocname & ".dwg")
' 打开一个新图形
Dim objNewDoc As AcadDocument
Set objNewDoc = acadapp.Application.Documents(App.Path & "\Gallery\" & NewDocname & ".dwg")
' 将外部图形的实体复制到当前图形
Set ssetobj = CreateSelectionSet(objNewDoc, "test")
ssetobj.Select acSelectionSetAll
objNewDoc.CopyObjects ssArray(ssetobj), objCurDoc.ModelSpace
objCurDoc.Regen acAllViewports
' 关闭打开的图形
objNewDoc.Close (False)
End Sub
'返回包含于选择集中每一项目的变体数,参数:一选择集
Public Function ssArray(ss As AcadSelectionSet)
Dim retVal() As AcadEntity, k As Long
ReDim retVal(0 To ss.Count - 1)
For k = 0 To ss.Count - 1
Set retVal(k) = ss.Item(k)
Next
ssArray = retVal
End Function
'建立选择集
Public Function CreateSelectionSet(ByVal Doc As AcadDocument, ByVal SSetName As String) As AcadSelectionSet
On Error Resume Next
Doc.SelectionSets(SSetName).Delete
Set CreateSelectionSet = Doc.SelectionSets.Add(SSetName)
End Function
页:
[1]
2