.NET

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

Can i close the inactive drawing file using c#?

220 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: 965
Registered: ‎04-27-2009
Message 2 of 4 (194 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: 86
Registered: ‎02-28-2012
Message 3 of 4 (185 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,398
Registered: ‎04-09-2008
Message 4 of 4 (172 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community