.NET

.NET

Reply
Valued Contributor
RamanSBV
Posts: 88
Registered: ‎02-28-2012
Message 1 of 4 (236 Views)

Can i close the inactive drawing file using c#?

236 Views, 3 Replies
03-04-2013 03:15 AM

Hi,

 

I need to close drawing file which is inactive. Please guide me how i can achive same.

 

Regards,

Raman

*Expert Elite*
norman.yuan
Posts: 1,063
Registered: ‎04-27-2009
Message 2 of 4 (210 Views)

Re: Can i close the inactive drawing file using c#?

03-04-2013 12:28 PM in reply to: RamanSBV

Yes, you can close drawing which is not current active drawing (not Application.DocumentManager.MdiActiveDocument) easily.

 

Here is sample code:

 

public class MyCommands
{
    [CommandMethod("CloseTest")]
    public static void CloseNonActiveDrawing()
    {
        Document dwg = Application.DocumentManager.MdiActiveDocument;
        Editor ed = dwg.Editor;

        foreach (Document doc in Application.DocumentManager)
        {
            if (doc.Name != dwg.Name)
            {
                string fName=System.IO.Path.GetFileName(doc.Name);
                doc.CloseAndDiscard();
                ed.WriteMessage("\nDrawing \"{0}\" has been closed!", fName);
                break;
            }
        }
    }
}

 

 

 

Valued Contributor
RamanSBV
Posts: 88
Registered: ‎02-28-2012
Message 3 of 4 (201 Views)

Re: Can i close the inactive drawing file using c#?

03-04-2013 08:51 PM in reply to: norman.yuan

Hi,

 

Thanks for your respose on this issue.

 

If i use above code to close the drawing file, all changes are going away.

 

I want to save the changes with close.

 

Please guide me

 

Regards,

Raman

Moderator
Alexander.Rivilis
Posts: 1,452
Registered: ‎04-09-2008
Message 4 of 4 (188 Views)

Re: Can i close the inactive drawing file using c#?

03-05-2013 04:08 AM in reply to: RamanSBV

Try to change:

doc.CloseAndDiscard();

 with:

doc.CloseAndSave(doc.Name);

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.