Documents.Open fails, while ActiveDocument succeeds

Documents.Open fails, while ActiveDocument succeeds

oransen
Collaborator Collaborator
689 Views
2 Replies
Message 1 of 3

Documents.Open fails, while ActiveDocument succeeds

oransen
Collaborator
Collaborator

I'm at a loss as to why this is, here is the code, I've missed something important I imagine:

 

        {
            // Open AutoCAD and get it as a variable in C#...
            AcadApplication AcadApp;
            AcadApp = new AcadApplication();

            // Make sure the AutoCAD windows are visible
            // (But note that making it invisible probably speeds up processing.)
            AcadApp.Application.Visible = true;

            AcadDocument AcadDoc;
#if false
            // Get the active document, which in this case is the default empty document which
            // This uses the default document AutoCAD starts with, and works
            AcadDoc = AcadApp.ActiveDocument;
#else
            // This opens a document, but any attempt to use it fails
            AcadDoc = AcadApp.Documents.Open(@"D:\Temp\CSHARP.DWG");
#endif
            AcadDoc.Layers.Add("TestLayer");

            // Model space is actually where most of the entities (LINE,CIRCLE,POINT etc) in an AutoCAD DWG file live.
            var ModelSpace = AcadDoc.ModelSpace;
     }

 

See the stuff around "#if false"

 

The error message is (translated from Italian) the "called has rejected the caller's function call"

 

 

0 Likes
690 Views
2 Replies
Replies (2)
Message 2 of 3

hak_vz
Advisor
Advisor

Post your request in .NET forum

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 3

oransen
Collaborator
Collaborator

Yes, it is a bit confusing, there is an explicit VBA forum but no C# forum.

0 Likes