0

FATAL ERROR: Unhandled Access Violation Reading 0x0008 Exception at 1d8257a5h

Failed missing output

  • Hi . @Carol Jones, Firstly, it looks the code will get a file from parameters.FilePath. is that a local file or an accessible url? In addition, why the script is 'ActivityName....' ? or you defined a command with the same name of the Activity? Last, I'd suggest adding try catch to dump some error message in the log, which might be helpful. If none of these helps, please isolate and share a test dataset, including the .NET code project and Design Automation script. please email us at forge.help@autodesk.com if it contains confidential info. – Xiaodong Liang Jan 14 '18 at 09:46

1 Answers1

0

I finally made it work with HostApplicationServices.getRemoteFile in local AutoCAD, then migrated it to Design Automation. It is also working now. The below is the command of .NET plugin.

To have a simple test, I hard-coded the URL in the plugin. you could replace the URL with the workflow at your side (either by an json file, or input argument of Design Automation)

My demo ReadDWG the entities from the remote URL file, then wblock the entities to current drawing (HostDWG), finally save current drawing.

Hope it helps to address the problem at your side.

.NET command

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());
        } 

     }
  }
}
Xiaodong Liang
  • 2,051
  • 2
  • 9
  • 14
  • WOW!! Thanks a ton!! – Carol Jones Jan 23 '18 at 09:30
  • @CarolJones, my apology! our engineer team reminded me it is NOT a supported way to call HTTP Request (like WebClient.Download) directly within AutoCAD Design Automation. My code demo happened to work :( The way should be turn to variadic input and call acesHttpOperation within CRX plugin, but I have not made a working code that can download the remote DWG by this way. I will get back to you once getting any progress. – Xiaodong Liang Jan 25 '18 at 10:53