zdm860114 发表于 2009-5-20 18:21:00

[求助]多文档时遇到的问题,想了多天解决不了,恳请高手们帮忙

本帖最后由 作者 于 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 &amp; "\Gallery\" &amp; CurDocname &amp; ".dwg")的下面一句</p><p>Set objCurDoc = acadapp.Application.Documents.Open(App.Path &amp; "\Gallery\" &amp; CurDocname &amp; ".dwg")</p><p>到是可以,但我不需要那样的功能,我需要获得打开的CAD文档。</p><p>&nbsp;&nbsp;&nbsp; <br/>'复制到一张图纸上<br/>Public Sub CopyFromOuterDwg(CurDocname, NewDocname As String)<br/>&nbsp;' 第一张图<br/>&nbsp;&nbsp;&nbsp; Dim objCurDoc As AcadDocument<br/>&nbsp;&nbsp;&nbsp; Set objCurDoc = acadapp.Application.Documents.Item(App.Path &amp; "\Gallery\" &amp; CurDocname &amp; ".dwg")<br/>&nbsp;&nbsp;&nbsp; 'Set objCurDoc = acadapp.Application.Documents.Open(App.Path &amp; "\Gallery\" &amp; CurDocname &amp; ".dwg")<br/>' 新图形<br/>&nbsp;&nbsp;&nbsp; Dim objNewDoc As AcadDocument<br/>&nbsp;&nbsp;&nbsp; Set objCurDoc = acadapp.Application.Documents.Item(App.Path &amp; "\Gallery\" &amp; NewDocname &amp; ".dwg")<br/>&nbsp;&nbsp;&nbsp; 'Set objNewDoc = acadapp.Application.Documents.Open(App.Path &amp; "\Gallery\" &amp; NewDocname &amp; ".dwg")<br/>&nbsp;&nbsp;&nbsp; objNewDoc.Activate<br/>&nbsp;&nbsp;&nbsp; 'Set objNewDoc = acadapp.Application.ActiveDocument<br/>' 将外部图形的实体复制到当前图形<br/>&nbsp;&nbsp; Set ssetobj = CreateSelectionSet<br/>&nbsp;&nbsp; ssetobj.Select acSelectionSetAll<br/>&nbsp;&nbsp; 'ssetObj.SelectOnScreen<br/>&nbsp; acadapp.ActiveDocument.CopyObjects ssArray(ssetobj), objCurDoc.ModelSpace<br/>&nbsp; objCurDoc.Regen acAllViewports<br/>&nbsp;' 关闭打开的图形<br/>&nbsp; objNewDoc.Close<br/>End Sub</p>

雪山飞狐_lzh 发表于 2009-5-20 18:40:00

<p>如果是新建的可以试下</p><p>Acadapp.Application.Documents(Acadapp.Application.Documents.Count - 1)</p>

zdm860114 发表于 2009-5-20 23:09:00

本帖最后由 作者 于 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 &amp; "\Gallery\" &amp; NewDocname &amp; ".dwg")</p><p>VBA中是这样的一句:Set doc = Thisdrawing.Application.Documents("Drawing1.dwg")<br/>请高手帮忙,谢谢了!</p>

sailorcwx 发表于 2009-5-21 01:37:00

<p>Set doc = Acadapp.Documents("Drawing1.dwg")</p>

zdm860114 发表于 2009-5-21 09:59:00

<p>首先谢谢楼上两位的热心解答</p><p>不过我试过</p><p>Set doc = Acadapp.Documents("Drawing1.dwg")</p><p>这句还是会提示那样的错误</p><p>真不知道怎么解决,请大家用你们的智慧帮我解答下,不甚感激!</p>

雪山飞狐_lzh 发表于 2009-5-21 12:31:00

<p>当前文档先保存在一个变量里</p><p>然后用三个doc变量保存你打开的文档</p>

zdm860114 发表于 2009-5-21 12:55:00

lzh741206发表于2009-5-21 12:31:00static/image/common/back.gif当前文档先保存在一个变量里然后用三个doc变量保存你打开的文档

<p>试了下,没有成功,能给个具体点的代码么?谢谢了</p><p></p>

雪山飞狐_lzh 发表于 2009-5-21 13:09:00

<p>把你的代码贴上看看吧,VBA没有装了,:)</p><p>或者你可以试下ObjectDBX?</p>

zdm860114 发表于 2009-5-21 16:00:00

lzh741206发表于2009-5-21 13:09:00static/image/common/back.gif把你的代码贴上看看吧,VBA没有装了,:)或者你可以试下ObjectDBX?

<p>&nbsp;&nbsp;&nbsp; <br/>'打开到一张图纸上<br/>Public Sub CopyFromOuterDwg(CurDocname As String, NewDocname As String)<br/>&nbsp;' 打开第一张图<br/>&nbsp;&nbsp;&nbsp; Dim objCurDoc As AcadDocument<br/>&nbsp;&nbsp;&nbsp; Set objCurDoc = acadapp.Application.Documents(App.Path &amp; "\Gallery\" &amp; CurDocname &amp; ".dwg")<br/>' 打开一个新图形<br/>&nbsp;&nbsp;&nbsp; Dim objNewDoc As AcadDocument<br/>&nbsp;&nbsp;&nbsp; Set objCurDoc = acadapp.Application.Documents(App.Path &amp; "\Gallery\" &amp; NewDocname &amp; ".dwg")<br/>&nbsp;&nbsp;&nbsp; Set objNewDoc = acadapp.Application.ActiveDocument<br/>' 将外部图形的实体复制到当前图形<br/>&nbsp;&nbsp; Set ssetobj = CreateSelectionSet<br/>&nbsp;&nbsp; ssetobj.Select acSelectionSetAll<br/>&nbsp;&nbsp; acadapp.ActiveDocument.CopyObjects ssArray(ssetobj), objCurDoc.ModelSpace<br/>&nbsp; objCurDoc.Regen acAllViewports<br/>&nbsp;' 关闭打开的图形<br/>&nbsp; objNewDoc.Close (False)<br/>End Sub</p><p>'返回包含于选择集中每一项目的变体数,参数:一选择集<br/>Public Function ssArray(ss As AcadSelectionSet)<br/>&nbsp;&nbsp;&nbsp; Dim retVal() As AcadEntity, k As Long<br/>&nbsp;&nbsp;&nbsp; ReDim retVal(0 To ss.Count - 1)<br/>&nbsp;&nbsp;&nbsp; For k = 0 To ss.Count - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set retVal(k) = ss.Item(k)<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; 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/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; acadapp.ActiveDocument.SelectionSets(SSetName).Delete<br/>&nbsp;&nbsp;&nbsp; Set CreateSelectionSet = acadapp.ActiveDocument.SelectionSets.Add(SSetName)<br/>End Function</p>

雪山飞狐_lzh 发表于 2009-5-21 16:38:00

试下吧

   
'打开到一张图纸上
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
查看完整版本: [求助]多文档时遇到的问题,想了多天解决不了,恳请高手们帮忙