TheSwamp
Code Red => .NET => Topic started by: T.Willey 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.
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)
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
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
catch (Autodesk.AutoCAD.Runtime.Exception aex) {
CannotOpenAr[CannotOpenCnt] = Str + "\n " + aex.ToString();
++CannotOpenCnt;
}
catch {
CannotOpenAr[CannotOpenCnt] = Str + "\n " + e.ToString();
++CannotOpenCnt;
}
-
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....
-
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
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. (http://www.theswamp.org/index.php?topic=12257.msg151595#msg151595)
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.
-
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:
if (db != HostApplicationServices.WorkingDatabase) {
HostApplicationServices.WorkingDatabase = db;
-
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 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:
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.
-
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.
-
I think I get it. Thanks again Glenn.
-
You're welcome.
Cheers,
Glenn.