【问题标题】:autodesk design automation欧特克设计自动化
【发布时间】:2018-06-20 19:31:26
【问题描述】:

致命错误:未处理的访问冲突在 1d8257a5h 读取 0x0008 异常

失败的缺失输出

【问题讨论】:

  • 嗨。 @Carol Jones,首先,它看起来代码将从parameters.FilePath 中获取一个文件。那是本地文件还是可访问的网址?另外,为什么脚本是 'ActivityName....' ?或者你定义了一个与Activity同名的命令?最后,我建议添加 try catch 以在日志中转储一些错误消息,这可能会有所帮助。如果这些都没有帮助,请隔离并共享一个测试数据集,包括 .NET 代码项目和设计自动化脚本。如果其中包含机密信息,请发送电子邮件至 forge.help@autodesk.com。

标签: automation autocad autodesk-forge


【解决方案1】:

我终于让它在本地 AutoCAD 中与 HostApplicationServices.getRemoteFile 一起工作,然后将其迁移到 Design Automation。它现在也在工作。下面是.NET插件的命令。

为了进行简单的测试,我在插件中硬编码了 URL。您可以将 URL 替换为您身边的工作流(通过 json 文件或 Design Automation 的输入参数)

我的演示 ReadDWG 从远程 URL 文件中读取实体,然后将实体 wblock 到当前图形(HostDWG),最后保存当前图形。

希望它有助于解决您身边的问题。

.NET 命令

namespace PackageNetPlugin
{   
    class DumpDwgHostApp: HostApplicationServices
    {
        public override string FindFile(string fileName, 
                                    Database database,
                                     FindFileHint hint)
        {
            throw new NotImplementedException();
        }

        public override string GetRemoteFile(Uri url, 
                                             bool ignoreCache)
        {
             //return base.GetRemoteFile(url, ignoreCache);

             Database db = 
             Autodesk.AutoCAD.ApplicationServices.Application.
                        DocumentManager.MdiActiveDocument.Database;

             string localPath = string.Empty; 
             if (ignoreCache)
             {
                 localPath = 
                    Autodesk.AutoCAD.ApplicationServices.Application.
                         GetSystemVariable("STARTINFOLDER") as string; 

                string filename = 
                    System.IO.Path.GetFileName(url.LocalPath);
                 localPath += filename;
                using (var client = new WebClient())
                {
                    client.DownloadFile(url, localPath);
                 }
            }  

            return localPath;
        }

        public override bool IsUrl(string filePath)
       {
            Uri uriResult;
            bool result = Uri.TryCreate(filePath, 
                          UriKind.Absolute, out uriResult)
                     && (uriResult.Scheme == Uri.UriSchemeHttp || 
                         uriResult.Scheme == Uri.UriSchemeHttps);

            return result;
        } 
 }

public class Class1
{  
    [CommandMethod("MyPluginCommand")]
    public void MyPluginCommand()
    {
        try { 
            string drawingPath = 
  @"https://s3-us-west-2.amazonaws.com/xiaodong-test-da/remoteurl.dwg";

            DumpDwgHostApp oDDA = new DumpDwgHostApp();
            string localFileStr = "";
            if (oDDA.IsUrl(drawingPath)){ 
                localFileStr = oDDA.GetRemoteFile(
                   new Uri(drawingPath), true);

            }

            if(!string.IsNullOrEmpty(localFileStr))
            {
                //source drawing from drawingPath
                Database source_db = new Database(false, true);
                source_db.ReadDwgFile(localFileStr, 
                      FileOpenMode.OpenTryForReadShare, false, null); 

                ObjectIdCollection sourceIds =
                           new ObjectIdCollection();
                using (Transaction tr = 
                    source_db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = 
                       (BlockTableRecord)tr.GetObject(
                SymbolUtilityServices.GetBlockModelSpaceId(source_db), 
                                                    OpenMode.ForRead);
                    foreach (ObjectId id in btr)
                    {
                        sourceIds.Add(id);
                    }
                    tr.Commit();
                }

                //current drawing (main drawing working with workitem)
                Document current_doc =
                 Autodesk.AutoCAD.ApplicationServices.Application.
                         DocumentManager.MdiActiveDocument;
                Database current_db = current_doc.Database;  
                Editor ed = current_doc.Editor;   

                //copy the objects in source db to current db
                using (Transaction tr = 
                    current_doc.TransactionManager.StartTransaction())
                {
                    IdMapping mapping = new IdMapping();
                    source_db.WblockCloneObjects(sourceIds, 
        SymbolUtilityServices.GetBlockModelSpaceId(current_db), 
        mapping, DuplicateRecordCloning.Replace, false);
                    tr.Commit();
                }

            }

        }
        catch(Autodesk.AutoCAD.Runtime.Exception ex)
        {
            Autodesk.AutoCAD.ApplicationServices.Application.
DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString());
        } 

     }
  }
}

【讨论】:

  • 哇!!非常感谢!
  • @CarolJones,我很抱歉!我们的工程师团队提醒我,在 AutoCAD 设计自动化中直接调用 HTTP 请求(如 WebClient.Download)不是受支持的方式。我的代码演示恰好可以工作:( 方法应该是在 CRX 插件中使用可变参数输入并调用 acesHttpOperation,但我还没有制作可以通过这种方式下载远程 DWG 的工作代码。一旦有任何我会回复你进展。
猜你喜欢
  • 2018-07-25
  • 2018-05-15
  • 2021-01-06
  • 2021-06-29
  • 2017-09-08
  • 1970-01-01
  • 2020-09-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多