AutoCAD crashes when starting from Revit API

AutoCAD crashes when starting from Revit API

Anonymous
Not applicable
502 Views
4 Replies
Message 1 of 5

AutoCAD crashes when starting from Revit API

Anonymous
Not applicable

I have a simple Revit addin setup where the users selects a linked dwg and the addins opens tha dwg in autocad to edit. However whenever I start AutoCAD from within the Revit addin I get the error "Unhandled Exception C0000005 (Access Violation Reading 0x0008) at address CADE4A58h".

 

Even this simple code gives me the error:

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

namespace ClassLibrary1
{
    [TransactionAttribute(TransactionMode.Manual), RegenerationAttribute(RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            System.Diagnostics.Process.Start(@"C:\test.dwg");
         
            return Result.Succeeded;
        }
    }
}

Just to be clear. If I double click the DWG file in windows explorer the file opens just fine without error. If I create a console application outside of the Revit API with just the process start command, the DWG opens just fine. IE

using System;
using System.Diagnostics;

namespace startautocad
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start(@"C:\test.dwg");
        }
    }
}

Any idea why I get the error in the Revit addin?

0 Likes
503 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

Dear Mwilson1,

 

Thank you for the interesting question.

 

No idea whatsoever.

 

However, you could try an alternative approach:

 

Use the AutoCAD COM Interop functionality to start up AutoCAD, load the DWG, and either display or hide the user interface, as you prefer:

 

http://thebuildingcoder.typepad.com/blog/2013/04/launching-autocad-within-a-revit-add-in.html

 

I hope this helps.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5

stever66
Advisor
Advisor

I really don't have a clue, but lots of possibilities come to mind:

windows associtivity, autocad license, autocad startup arguments, user logon, network issue.

 

Unless you have already tried this, why not try substituting a more basic program instead of autocad and see if that works.  Like opening a simple text document. 

 

Also, you might try some of the overloads for this command, listed here:

 

https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(v=vs.110).aspx

 

For example, you might try specifying the name of the program to run.

 

Message 4 of 5

Anonymous
Not applicable

Thank you for the suggestion. I was able to run

Process.Start(@"c:\test.txt");
Process.Start(@"c:\test.pdf");

Successfully. The text file opened in notepad and the pdf in Bluebeam.

 

I don't know if it helps, but when I open a DWG with the code above, I'm able to work in the drawing for a second or two. Usually just enough to zoom around, before it crashes. However if I do nothing it still crashes.

 

Also as a note, when I open a DWG in AutoCAD with the Visual Studio debugger running on the Revit addin, AutoCAD crashes completly without an error message. It's only if I run outside of visual studio do I get the error above.

 

I'm trying to make this addin as generic as possible for the office, because we have all different flavors of AutoCAD installed, between 2010 and 2016. 

0 Likes
Message 5 of 5

stever66
Advisor
Advisor

For what its worth, I can put:

 

System.Diagnostics.Process.Start(@"C:\test.dwg");

 

in a Sharp Develop Macro (inside Revit), and it starts autocad and opens the file just fine.   It takes it longer than if I just click the Autocad icon itself, but it does the same thing if I just double click a file in explorer. 

 

Jeremy's suggestion might be your best bet.