.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ObjectDBX and SaveAs

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
431 Views, 8 Replies

ObjectDBX and SaveAs

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."
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

It's hard to guess what you might be doing wrong
(or whether you've just hit a bug), without seeing
code.

Can you post it?

This simple test works for me:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Interop.Common;

namespace DBXTest
{
public static class Class1
{
[CommandMethod( "DBX" )]
public static void dbx()
{
AxDbDocument doc = new AxDbDocumentClass();
object center = new double[] { 0.0, 0.0, 0.0 };
doc.ModelSpace.AddCircle( center, 1.0 );
doc.SaveAs( "D:\\TEST.DWG", Type.Missing );
Marshal.ReleaseComObject( doc );
}
}
}


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"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."
Message 3 of 9
Anonymous
in reply to: Anonymous

Here is the code. I tried with what you suggested, and it still errors. I
will see the message box, and then it crashes. If you want all the
sub-routines, I can post those also.

using System;

using System.Collections;

using System.Runtime.InteropServices;

using System.Windows.Forms;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Interop.Common;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;


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, Type.Missing);

Marshal.ReleaseComObject (dbxDoc);


}

}

}

}

//}

}


--

Tim
"A blind man lets nothing block his vision."


"Tony Tanzillo" wrote in message
news:5314209@discussion.autodesk.com...
It's hard to guess what you might be doing wrong
(or whether you've just hit a bug), without seeing
code.

Can you post it?

This simple test works for me:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Interop.Common;

namespace DBXTest
{
public static class Class1
{
[CommandMethod( "DBX" )]
public static void dbx()
{
AxDbDocument doc = new AxDbDocumentClass();
object center = new double[] { 0.0, 0.0, 0.0 };
doc.ModelSpace.AddCircle( center, 1.0 );
doc.SaveAs( "D:\\TEST.DWG", Type.Missing );
Marshal.ReleaseComObject( doc );
}
}
}


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"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."
Message 4 of 9
Anonymous
in reply to: Anonymous

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."
Message 5 of 9
Anonymous
in reply to: Anonymous

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."
Message 6 of 9
Anonymous
in reply to: Anonymous

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."
Message 7 of 9
Anonymous
in reply to: Anonymous

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."
Message 8 of 9
Anonymous
in reply to: Anonymous

The way I did it, is I set the lenght of two string arrays, to the length of
the array returned by the open dialog. Then I add to them, one for saved,
one for not saved. After the code has finished running through all the
drawings, it then prints those two arrays to the current drawings command
line, but it makes sure that the items in the array are not null before it
prints them to the command line.

Is this a good way to do it? Or is there a better one?

Thanks.

--

Tim
"A blind man lets nothing block his vision."


"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."
Message 9 of 9
Anonymous
in reply to: Anonymous

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."

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost