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

Is it possible to determine if a non-active drawing is new?

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
494 Views, 6 Replies

Is it possible to determine if a non-active drawing is new?

After doing a bit of searching on this forum, I learned that you can use the DWGTITLED system variable to determine if a drawing is new or has been previously saved. My current understanding is that you can only use this system variable to check whether the current active document is new or not.

Is it possible to check if a non-active document is new?
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

I haven't tried this, so can't say if it will work, or not:

Try setting the HostApplicationServices.WorkingDatabase to the database of the
document you want to check, then get the value of DWGTITLED, and finally, make
sure to restore the previous value of WorkingDatabase to what it was before you
changed it.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6399782@discussion.autodesk.com...
After doing a bit of searching on this forum, I learned that you can use the
DWGTITLED system variable to determine if a drawing is new or has been
previously saved. My current understanding is that you can only use this system
variable to check whether the current active document is new or not.

Is it possible to check if a non-active document is new?
Message 3 of 7
Anonymous
in reply to: Anonymous

Tony,

Thanks for the response. I gave this a shot, but unfortunately it still seemed to retain the value of the DWGTITLED variable based on the active document. Below is the sample code I used. For my test, I had 2 documents open in AutoCAD: 1 new and 1 previously saved.

{code}
// get the first inactive document found in the collection
var docs = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Cast();
var doc = docs.FirstOrDefault(d => !d.IsActive);

var originalDb = HostApplicationServices.WorkingDatabase;
var dwgTitledOrig = Application.GetSystemVariable("DWGTITLED");
MessageBox.Show("Original DWGTITLED = " + dwgTitledOrig);

HostApplicationServices.WorkingDatabase = doc.Database;
var dwgTitledChanged = Application.GetSystemVariable("DWGTITLED");
MessageBox.Show("DWGTITLED after changing working DB = " + dwgTitledChanged);

HostApplicationServices.WorkingDatabase = originalDb;
var dwgTitledRestored = Application.GetSystemVariable("DWGTITLED");
MessageBox.Show("DWGTITLED after restoring original DB = " + dwgTitledRestored);
{code}

One thing I noticed is that for a new document, the Document.Name and Database.Filename properties are different. Would it be possible to determine if a document is "new" based on these two properties not being equal or are there other situations where this could also be the case?
Message 4 of 7
jejamesNC
in reply to: Anonymous

Changing 'Active' documents from within a command, the command should have a Session commandflag set...

[CommandMethod("dwgCheck",CommandFlags.Session)]

Also, setting the HostApplicationServices workingdatabase does not make the document Active, that is done with MDIActiveDocument...

Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = doc;


-james
Message 5 of 7
Anonymous
in reply to: Anonymous

I think you might have not understood the OP's problem.

He's trying to determine the status of a non-active document
without making it the active document.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6400692@discussion.autodesk.com...
Changing 'Active' documents from within a command, the command should have a
Session commandflag set...

[CommandMethod("dwgCheck",CommandFlags.Session)]

Also, setting the HostApplicationServices workingdatabase does not make the
document Active, that is done with MDIActiveDocument...

Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
= doc;


-james
Message 6 of 7
Anonymous
in reply to: Anonymous

I was afraid of that.

You can't reliably use the fact that the database filename
and the document Name properties are not the same, because
that might be the case if you are editing a template file.

You can P/Invoke this API that's exported from acad.exe:

bool acedIsNamedDrawing( AcApDocument* pDoc )

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6400638@discussion.autodesk.com...
Tony,

Thanks for the response. I gave this a shot, but unfortunately it still seemed
to retain the value of the DWGTITLED variable based on the active document.
Below is the sample code I used. For my test, I had 2 documents open in AutoCAD:
1 new and 1 previously saved.

{code}
// get the first inactive document found in the collection
var docs =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Cast();
var doc = docs.FirstOrDefault(d => !d.IsActive);

var originalDb = HostApplicationServices.WorkingDatabase;
var dwgTitledOrig = Application.GetSystemVariable("DWGTITLED");
MessageBox.Show("Original DWGTITLED = " + dwgTitledOrig);

HostApplicationServices.WorkingDatabase = doc.Database;
var dwgTitledChanged = Application.GetSystemVariable("DWGTITLED");
MessageBox.Show("DWGTITLED after changing working DB = " + dwgTitledChanged);

HostApplicationServices.WorkingDatabase = originalDb;
var dwgTitledRestored = Application.GetSystemVariable("DWGTITLED");
MessageBox.Show("DWGTITLED after restoring original DB = " + dwgTitledRestored);
{code}

One thing I noticed is that for a new document, the Document.Name and
Database.Filename properties are different. Would it be possible to determine if
a document is "new" based on these two properties not being equal or are there
other situations where this could also be the case?
Message 7 of 7
Anonymous
in reply to: Anonymous

Thanks Tony! It's good to know that there is at least a way to solve the problem.

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