Author Topic: Error in new drawing  (Read 4082 times)

0 Members and 1 Guest are viewing this topic.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Error in new drawing
« 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: [Select]
            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);

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.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

TonyT

  • Guest
Re: Error in new drawing
« Reply #1 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()?

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: [Select]
            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);

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.
« Last Edit: April 25, 2007, 02:54:26 PM by TonyT »

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Error in new drawing
« Reply #2 on: April 25, 2007, 04:57:10 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()?

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: [Select]
                Document adoc = acadApp.DocumentManager.Add(theTemplateFilePath);
                Database db = adoc.Database;
                db.SaveAs(theNewFilePath, DwgVersion.AC1015);
                adoc.CloseAndDiscard();

vs...

Code: [Select]
                Document adoc = acadApp.DocumentManager.Add(theTemplateFilePath);
                Database db = adoc.Database;
                db.SaveAs(theNewFilePath, DwgVersion.Current);
                adoc.CloseAndDiscard();
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Error in new drawing
« Reply #3 on: April 26, 2007, 11:43:09 AM »
Mark -  . . .

Have you read the ObjectARX docs for CloseInput()?


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?


               
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Glenn R

  • Guest
Re: Error in new drawing
« Reply #4 on: April 26, 2007, 05:50:55 PM »
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?

TonyT

  • Guest
Re: Error in new drawing
« Reply #5 on: April 26, 2007, 07:12:26 PM »
Hi Glenn,

Unless he's doing something to the new drawing before saving it,
there's no point to any of this, because what it amounts to is little
more than copying a file.

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?

TonyT

  • Guest
Re: Error in new drawing
« Reply #6 on: April 26, 2007, 07:16:21 PM »
Don't believe everything you read in the docs, some of it is as
old as the hills and even Autodesk's sample code uses functions
that are marked as 'for internal use only'.

CloseInput simply forces the entire drawing file to be read, and
optionally closes the file.  However, you should never call it on
a Database that's open in the editor.

Mark -  . . .

Have you read the ObjectARX docs for CloseInput()?


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

  • Guest
Re: Error in new drawing
« Reply #7 on: April 26, 2007, 07:17:20 PM »
Heh...<smacks head> Of course. Reminds me of a saying about forest's and trees...

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Error in new drawing
« Reply #8 on: April 26, 2007, 07:43:51 PM »
Yeah  :oops:

Code: [Select]
            if (File.Exists(myFile) == false)
            {
                // create a file
                File.Copy(myBlankFilePath, myFile);
            }
            Document odoc = acadApp.DocumentManager.Open(myFile, false);

Once again I was making it much harder than it had to be.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions