AccessViolationException when trying to open Database using RealDWG

AccessViolationException when trying to open Database using RealDWG

Anonymous
Not applicable
905 Views
3 Replies
Message 1 of 4

AccessViolationException when trying to open Database using RealDWG

Anonymous
Not applicable

Hi,

 

I am trying to create a standalone console application for reading DWG file database using RealDWG.

I have referenced the DLL called "acdbmgd.dll" located in "C:\Program Files\Autodesk\RealDWG 2018".

 

However, when running this minimal example

 

 

using Autodesk.AutoCAD.DatabaseServices;
...

class Program { static void Main(string[] args) { using (var db = new Database(false, true)) { ... } } }

I get AccessViolationException from the expression

 

var db = new Database(false, true)

 

 

What could be causing this? I have read that one needs to have AutoCAD running when executing external software like this, but that does not apply when using RealDWG, right?

 

Best regards,

Elias Furenhed

0 Likes
Accepted solutions (1)
906 Views
3 Replies
Replies (3)
Message 2 of 4

BKSpurgeon
Collaborator
Collaborator

(sorry just realised my solution is wrong)

 

 

nevertheless perhaps this might help you:

 

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=770257

 

also check out the DevTV recording to get a "hello world" example up and running:

 

 

http://download.autodesk.com/media/adn/DevTV-Introduction-to-RealDWG-Programming.zip

0 Likes
Message 3 of 4

moogalm
Autodesk Support
Autodesk Support
Accepted solution

First please go through the RealDWG examples available with SDK.

 

For this you need to implement HostApplicationServices.

 

The minimal sample would be, this a pseudo code.

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;

namespace MinimalSample
{
    class DWGHost : HostApplicationServices
    {
        public override string FindFile(string fileName, Database database, FindFileHint hint)
        {
            return fileName;
        }

        public override void FatalError(string message)
        {
            System.Windows.Forms.MessageBox.Show(message);
        }

    }
	 class Program
    {
	static void Main(string[] args)
        {
            Autodesk.AutoCAD.Runtime.RuntimeSystem.Initialize(new DWGHost(), 1033);

            Database mDatabase = new Database(false, false);
            mDatabase.ReadDwgFile( args[0], FileOpenMode.OpenForReadAndAllShare, true, "");

            using (Transaction oTransaction = mDatabase.TransactionManager.StartTransaction())
            {
                try
                {
                   //process
                }
                catch (System.Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.Message);
                }
            }
        }
	}
	}
Message 4 of 4

Anonymous
Not applicable

Thanks, I got it working using the sample code above.

 

Elias

0 Likes