Message 1 of 3
Documents.Open fails, while ActiveDocument succeeds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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"