It may help make your code be a bit more readable,
if you eliminated the namespace reference, by either
putting the WorkingDatabase class in your project's
own workspace, or adding a using directive at the
top of the code file:
using CaddZone.AutoCAD.DatabaseServices;
or whatever namespace you put WorkingDatabase in.
Then, you only need to use the class name, not the
fully qualified namespace.class name.
Yes, while the working database is switched to your
DBX database, you should only do what you need
(namely make the change to the text/attributes) and
that's all.
Definitely do not try to save the database while it
is the working database.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
"T.Willey" wrote in message news:5315565@discussion.autodesk.com...
So If I understand you correctly (I'm trying) I should change my code to
this: (I'm changing the database of the dbxDoc with two of the functions.
UpdateRevBlock and UpdateCloudLayer)
foreach (string Str in DwgList) {
AxDbDocument dbxDoc = new AxDbDocument();
bool ShouldSave = false;
dbxDoc.Open (Str, null);
Database db = Database.FromAcadDatabase (dbxDoc.Database);
if (HasLayer (db, "Cloud-UNKNOWN")) {
string Rev = (GetHighestRev(db));
if (Rev != "") {
using (CaddZone.DatabaseServices.WorkingDatabase wdb = new
CaddZone.DatabaseServices.WorkingDatabase (db)) {
UpdateRevBlock (db, Rev);
UpdateCloudLayer (db, "Cloud-UNKNOWN", "Cloud-" + Rev);
ShouldSave = true;
//MessageBox.Show ("Right before save.");
}
}
}
if (ShouldSave == true) {
db.RetainOriginalThumbnailBitmap = true;
//DocEd.WriteMessage ("\n Saving file {0}", dbxDoc.Name);
dbxDoc.SaveAs (dbxDoc.Name, Type.Missing);
}
else {
//DocEd.WriteMessage ("\n ++ Not saving file {0}", dbxDoc.Name);
}
Marshal.ReleaseComObject (dbxDoc);
}
Another general question is: Since I should print to the comamnd line of the
current drawing (document), I read (I think) that you need to know the size
of an array you use? If this is true, how would one write a code where the
number is not know, or is that wrong? If I can make an array, without know
the size, and be able to add to it, then I would make an array for each
Saved/Not-Saved, and print that to the command line once the code is done
using the database of the dbxDoc.
Thanks for all the tips here and on theswamp Tony, greatly appreciated.
--
Tim
"A blind man lets nothing block his vision."
"Tony Tanzillo" wrote in message
news:5315014@discussion.autodesk.com...
It's hard to see what's what without some formatting
and indentatation, sorry.
However, even without looking closely, I see that you're
using the WorkingDatabase class I posted on theswamp,
but you're using it an a dangerous way. What you need
to do is always try to minimize the scope of the switch,
and limit it to only when you absolutely need it (which
is when you actually update the text/attributes).
So, assuming that your UpdateRevBlock() function is
where that happens:
using CaddZone.AutoCAD.DatabaseServices
using( WorkingDatabase wdb = new WorkingDatabase(yourdb))
{
// here, do only what you need while
// the working database is switched,
// and nothing more.
UpdateRevBlock(db, rev);
} // previous working database is restored here
IOW, never leave the working database set to the
external database any longer than needed, or you will
risk crashing AutoCAD.
Also, do not do _anything_ in the current drawing that's
open in the AutoCAD editor, while the working database
is set to the external database.
Another good habit is to avoid is re-using the same
AxDbDocument (although I think that internally it will
not re-use the same AcDbDatabase, but I prefer to
play it safe), so:
foreach( string filename in your-list-of-dwg files)
{
AxDbDocument doc = new AxDbDocument();
doc.Open(filename);
// work with the open doc here...
Marshal.ReleaseComObject(doc);
}
The important thing to remember in the above is
that for each call to "new AxDbDocument();" there
is one call to ReleaseComObject(). If that is not
followed, the dwg files will not be closed.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
"T.Willey" wrote in message
news:5314654@discussion.autodesk.com...
Oops, to quick. I release the dbxDoc to soon. I moved it to after the
foreach statement.
[code]
public void UpdateRevStuff() {
Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor DocEd = Doc.Editor;
Autodesk.AutoCAD.Windows.OpenFileDialog Dia = new
Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to update Cloud
layer", "", "dwg", "",
Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
Dia.ShowDialog();
string[] DwgList = Dia.GetFilenames();
AxDbDocument dbxDoc = new AxDbDocument();
foreach (string Str in DwgList) {
bool ShouldSave = false;
dbxDoc.Open (Str, null);
Database db = Database.FromAcadDatabase (dbxDoc.Database);
using (CaddZone.DatabaseServices.WorkingDatabase wdb = new
CaddZone.DatabaseServices.WorkingDatabase (db)) {
if (HasLayer (db, "Cloud-UNKNOWN")) {
string Rev = (GetHighestRev(db));
if (Rev != "") {
UpdateRevBlock (db, Rev);
UpdateCloudLayer (db, "Cloud-UNKNOWN", "Cloud-" + Rev);
ShouldSave = true;
//MessageBox.Show ("Right before save.");
}
}
}
if (ShouldSave == true) {
DocEd.WriteMessage ("Saving file {0}", dbxDoc.Name);
dbxDoc.SaveAs (dbxDoc.Name, Type.Missing);
}
else {
DocEd.WriteMessage ("++ Not saving file {0}", dbxDoc.Name);
}
}
Marshal.ReleaseComObject (dbxDoc);
}
[/code]
--
Tim
"A blind man lets nothing block his vision."
"T.Willey" wrote in message
news:5314678@discussion.autodesk.com...
Alexander Rivilis solved this problem on theswamp.org site
[quote]
I think problem not in second parameter of dbxDoc.SaveAs() function. Problem
is that this drawing is now current (e.g. WorkingDatabase).
Try to dbxDoc.SaveAs() after using (WorkingDatabase ...) block.
[/quote]
Along with what Tony posted here, it worked like it should. Thanks again
Tony!
[code]
public void UpdateRevStuff() {
Document Doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor DocEd = Doc.Editor;
//using (DocumentLock docLock =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDo
cument.LockDocument()) {
Autodesk.AutoCAD.Windows.OpenFileDialog Dia = new
Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to update Cloud
layer", "", "dwg", "",
Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
Dia.ShowDialog();
string[] DwgList = Dia.GetFilenames();
AxDbDocument dbxDoc = new AxDbDocument();
foreach (string Str in DwgList) {
dbxDoc.Open (Str, null);
Database db = Database.FromAcadDatabase (dbxDoc.Database);
using (CaddZone.DatabaseServices.WorkingDatabase wdb = new
CaddZone.DatabaseServices.WorkingDatabase (db)) {
if (HasLayer (db, "Cloud-UNKNOWN")) {
string Rev = (GetHighestRev(db));
if (Rev != "") {
UpdateRevBlock (db, Rev);
UpdateCloudLayer (db, "Cloud-UNKNOWN", "Cloud-" + Rev);
MessageBox.Show ("Right before save.");
//dbxDoc.SaveAs (dbxDoc.Name);
//Marshal.ReleaseComObject (dbxDoc);
}
}
}
dbxDoc.SaveAs (dbxDoc.Name, Type.Missing);
Marshal.ReleaseComObject (dbxDoc);
}
//}
}
[/code]
--
Tim
"A blind man lets nothing block his vision."
"T.Willey" wrote in message
news:5314169@discussion.autodesk.com...
Does anyone know how to? I have tried so many different ways, and have
crashed each time. The Save method doesn't work either.
Thanks in advance.
--
Tim
"A blind man lets nothing block his vision."