Code Red > .NET

Error in new drawing

(1/2) > >>

mohnston:
I get this error when I try to open a drawing I just created.


If I answer NO the file is opened. If I Audit the file it is clean. If I run Recover on the file it is clean.
The template file I use to create the new drawing is clean as well.

Here is the code I'm using to create the file:

--- Code: ---            Document odoc;
            if (File.Exists(myFile) == false)
            {
                // create a file
                odoc = acadApp.DocumentManager.Add(myBlankTemplateFile);
                Database db = odoc.Database;
                db.SaveAs(myFile, DwgVersion.AC1015);
                db.CloseInput(true);
                odoc.CloseAndDiscard();
            }
            odoc = acadApp.DocumentManager.Open(myFile, false);

--- End code ---

The error happens when the line
odoc = acadApp.DocumentManager.Open(myFile, false);
is executed but ONLY if the file gets created.
If the file exists and the creation structure is bypassed there is NO ERROR.

Perhaps I am not creating the drawing file correctly or not completing the creation process.

TonyT:
Mark -  I see you removed the call to Dispose() from
what you posted on the Autodesk newsgroup.

Have you read the ObjectARX docs for CloseInput()?


--- Quote from: mohnston on April 25, 2007, 12:51:26 PM ---I get this error when I try to open a drawing I just created.


If I answer NO the file is opened. If I Audit the file it is clean. If I run Recover on the file it is clean.
The template file I use to create the new drawing is clean as well.

Here is the code I'm using to create the file:

--- Code: ---            Document odoc;
            if (File.Exists(myFile) == false)
            {
                // create a file
                odoc = acadApp.DocumentManager.Add(myBlankTemplateFile);
                Database db = odoc.Database;
                db.SaveAs(myFile, DwgVersion.AC1015);
                db.CloseInput(true);
                odoc.CloseAndDiscard();
            }
            odoc = acadApp.DocumentManager.Open(myFile, false);

--- End code ---

The error happens when the line
odoc = acadApp.DocumentManager.Open(myFile, false);
is executed but ONLY if the file gets created.
If the file exists and the creation structure is bypassed there is NO ERROR.

Perhaps I am not creating the drawing file correctly or not completing the creation process.

--- End quote ---

mohnston:

--- Quote from: TonyT on April 25, 2007, 02:41:29 PM ---Mark -  I see you removed the call to Dispose() from
what you posted on the Autodesk newsgroup.

Have you read the ObjectARX docs for CloseInput()?


--- End quote ---
Tony,
You are right, I removed the Dispose. I have tried several different ways but with the same results.
Jerry put me on to the DwgVersion that I was specifying (AC1015). He confirmed that he got the same error when specifying that version. I changed that to Current and the problem disappeared.
I think it's a bug in the API.
If anyone else would like to confirm that would be nice.


--- Code: ---                Document adoc = acadApp.DocumentManager.Add(theTemplateFilePath);
                Database db = adoc.Database;
                db.SaveAs(theNewFilePath, DwgVersion.AC1015);
                adoc.CloseAndDiscard();

--- End code ---

vs...


--- Code: ---                Document adoc = acadApp.DocumentManager.Add(theTemplateFilePath);
                Database db = adoc.Database;
                db.SaveAs(theNewFilePath, DwgVersion.Current);
                adoc.CloseAndDiscard();

--- End code ---

mohnston:

--- Quote from: TonyT on April 25, 2007, 02:41:29 PM ---Mark -  . . .

Have you read the ObjectARX docs for CloseInput()?


--- End quote ---

Tony - I looked at that and it appears that my odoc.CloseAndDiscard() line was unnecessary because the db.CloseInput(true) just before it closed the drawing file.

I also noticed this comment:
"Note This function is intended for AutoCAD internal use. If used in ObjectARX applications, it may have undesirable results."

Does this mean that I shouldn't be using CloseInput?


               

Glenn R:
Correct. CloseAndDiscard is what you want to use.
Also, is there any particular reason you are putting the template into the editor and immediately closing, instead of creating a new dbase in memory from your template and then saving it away?

Navigation

[0] Message Index

[#] Next page

Go to full version