Author Topic: SaveAs on database won't work  (Read 4320 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
SaveAs on database won't work
« on: October 04, 2006, 12:52:45 PM »
Can anyone tell me why this won't work?
It will show all the message boxes except '4d' and '5'.
Thanks in advance.
Code: [Select]
try {
using (Database db = new Database (false, true)) {
      db.ReadDwgFile (Str, System.IO.FileShare.Read, true, null);
        if (db != HostApplicationServices.WorkingDatabase) {
      HostApplicationServices.WorkingDatabase = db;
      }
BlockReference TtlBlk = GetTitleBlock (db);
      MessageBox.Show ("4");
if (TtlBlk != null) {
      MessageBox.Show ("4a");
ReorderRevision (db, TtlBlk, DiaInfo);
      MessageBox.Show ("4b");
      ShouldSave = true;
}
  }
    if (ShouldSave == true) {
        db.RetainOriginalThumbnailBitmap = true;
      MessageBox.Show ("4c");
db.SaveAs (Str, DwgVersion.Current);
      MessageBox.Show ("4d");
      }
else {
NoTtlBlkAr[NoTtlBlkCnt] = Str;
++NoTtlBlkCnt;
}
MessageBox.Show ("5");
}
Edit: Also tried (didn't work either)
Code: [Select]
try {
using (Database db = new Database (false, true)) {
      db.ReadDwgFile (Str, System.IO.FileShare.Read, true, null);
        if (db != HostApplicationServices.WorkingDatabase) {
      HostApplicationServices.WorkingDatabase = db;
      }
BlockReference TtlBlk = GetTitleBlock (db);
      MessageBox.Show ("4");
if (TtlBlk != null) {
      MessageBox.Show ("4a");
ReorderRevision (db, TtlBlk, DiaInfo);
      MessageBox.Show ("4b");
      ShouldSave = true;
}
            if (ShouldSave == true) {
                db.RetainOriginalThumbnailBitmap = true;
              MessageBox.Show ("4c");
        db.SaveAs (Str, DwgVersion.Current);
              MessageBox.Show ("4d");
          }
        else {
        NoTtlBlkAr[NoTtlBlkCnt] = Str;
        ++NoTtlBlkCnt;
        }
        MessageBox.Show ("5");
  }
}
Edit:  Error message at the command line
Quote
Could not open drawing: C:\Willey-Temp\test\12-2697-1731-5_003.dwg
   System.EventArgs
 Could not open drawing: C:\Willey-Temp\test\12-2697-1731-5_004.dwg
   System.EventArgs
 Could not open drawing: C:\Willey-Temp\test\12-2697-1731-5_007.dwg
   System.EventArgs
Where the catch code looks like
Code: [Select]
catch (Autodesk.AutoCAD.Runtime.Exception aex) {
      CannotOpenAr[CannotOpenCnt] = Str + "\n   " + aex.ToString();
      ++CannotOpenCnt;
}
catch {
      CannotOpenAr[CannotOpenCnt] = Str + "\n   " + e.ToString();
      ++CannotOpenCnt;
     
}
« Last Edit: October 04, 2006, 03:01:17 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: SaveAs on database won't work
« Reply #1 on: October 04, 2006, 04:44:24 PM »
Why on earth are setting the dbase you just constructed to the workingdatabase?

If your intent is to do some modifications, then you don't need to...

Also, I've had readDwg fail when acad is set to use .net 2.0 and i've created a 1.1 dll....

T.Willey

  • Needs a day job
  • Posts: 5251
Re: SaveAs on database won't work
« Reply #2 on: October 04, 2006, 05:12:26 PM »
Why on earth are setting the dbase you just constructed to the workingdatabase?

If your intent is to do some modifications, then you don't need to...
I thought I had to make a new database, and then use
Code: [Select]
db.ReadDwgFile (Str, System.IO.FileShare.Read, true, null);
where Str = valid drawing path, to open and edit that database.  If I'm wrong, which it looks like I am, how else am I supposed to do it?  I got the idea from you here.

Also, I've had readDwg fail when acad is set to use .net 2.0 and i've created a 1.1 dll....
How can I check this?  I'm coding in .Net 1.1 right now.  I don't have .Net 2.0 on my drive either, so I'm guessing I'm coding in the right framework.

Thanks for the your help.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: SaveAs on database won't work
« Reply #3 on: October 04, 2006, 06:50:06 PM »
Quote
I thought I had to make a new database, and then use

Code:
db.ReadDwgFile (Str, System.IO.FileShare.Read, true, null);
where Str = valid drawing path, to open and edit that database.


Yes, that's correct, but from what I've seen, you DEFINATELY don't need this:

Code: [Select]
if (db != HostApplicationServices.WorkingDatabase) {
      HostApplicationServices.WorkingDatabase = db;

Glenn R

  • Guest
Re: SaveAs on database won't work
« Reply #4 on: October 04, 2006, 06:54:58 PM »
As far as the .NET 2.0 thing goes, if you have a look in your Acad install directory, you will find a file named 'acad.exe.config'.
If the .net config file for Acad - it's just xml. Open it up and you will see some comments on how to edit it. By default, Acad will always use the latest runtime installed, but you can force it to use a specific version...1.1 for instance.

Hope this helps.

Cheers,
Glenn.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: SaveAs on database won't work
« Reply #5 on: October 04, 2006, 07:16:26 PM »
Quote
I thought I had to make a new database, and then use

Code:
db.ReadDwgFile (Str, System.IO.FileShare.Read, true, null);
where Str = valid drawing path, to open and edit that database.


Yes, that's correct, but from what I've seen, you DEFINATELY don't need this:

Code: [Select]
if (db != HostApplicationServices.WorkingDatabase) {
      HostApplicationServices.WorkingDatabase = db;

This one seems to have been the problem.  Thanks again Glenn.  It is very much appreciated.  Do you know why it wouldn't work with that part in the code?  Just looking to understand why.

As far as the .NET 2.0 thing goes, if you have a look in your Acad install directory, you will find a file named 'acad.exe.config'.
If the .net config file for Acad - it's just xml. Open it up and you will see some comments on how to edit it. By default, Acad will always use the latest runtime installed, but you can force it to use a specific version...1.1 for instance.

Hope this helps.

Cheers,
Glenn.
I also set this to work with the framework I have, but it still wouldn't work unless I changed the code the way you said in the previous post.
« Last Edit: October 04, 2006, 07:17:35 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: SaveAs on database won't work
« Reply #6 on: October 04, 2006, 08:23:39 PM »
There are very few reasons why you would ever need to set the workingdatabase to anything other than what Acad sets it to (I've never had to).

A document (ie dwg file that you can see in the editor) has a database associated with it. What you're doing is creating a new dbase in memory, then telling autocad that the current document's dbase is not what it needs but is now your new one...can lead to disasters.

A document must have a database, but a database doesn't necessarily need a document if you get my meaning.

Cheers,
Glenn.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: SaveAs on database won't work
« Reply #7 on: October 04, 2006, 08:49:35 PM »
I think I get it.  Thanks again Glenn.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: SaveAs on database won't work
« Reply #8 on: October 04, 2006, 08:51:30 PM »
You're welcome.

Cheers,
Glenn.