明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1707|回复: 2

获取所有文档出错?

[复制链接]
发表于 2012-6-26 16:06 | 显示全部楼层 |阅读模式
本帖最后由 cdinten 于 2012-6-26 16:07 编辑

直接上代码:
  1.       
  2. ///  <summary>      
  3. /// 获取所有打开的文档      
  4. ///  <summary>  
  5. [CommandMethod("GetAllDrawings", CommandFlags.Session)]
  6. public static Document[] GetAllDrawings()      
  7. {
  8.             try
  9.             {
  10.                 DocumentCollection DocColl = Application.DocumentManager;
  11.                 Document[] docArr = null;
  12.                 DocColl.CopyTo(docArr, 0);
  13.                 return docArr;
  14.             }
  15.             catch (System.Exception exc)
  16.             {
  17.                 Application.ShowAlertDialog(exc.Message);
  18.             }
  19.             return null;
  20.         }

不知道是怎么回事?是不是ACAD的API中实现CopyTo有问题啊?另外获取活动文档数目的属性 Application.DocumentManager.Count也有问题,我使用的是AutoCAD2008。
发表于 2012-6-26 17:44 | 显示全部楼层
CommandMethod的函数有返回值?
发表于 2014-11-28 12:58 | 显示全部楼层
    <CommandMethod("GetAllDrawings")> Public Sub GetAllDrawings()
        Dim DocColl As DocumentCollection = Application.DocumentManager
        Dim docArr() As Document
        Dim i As Integer = 0
        Dim ent As Document
        ReDim docArr(DocColl.Count - 1)
        For Each ent In DocColl
            docArr(i) = ent
            i = i + 1
        Next
    End Sub
我是这样做的,能获取所有的文档
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-24 00:43 , Processed in 0.232340 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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