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

Can i close the inactive drawing file using c#?

3 REPLIES 3
Reply
Message 1 of 4
RamanSBV
627 Views, 3 Replies

Can i close the inactive drawing file using c#?

Hi,

 

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

 

Regards,

Raman

3 REPLIES 3
Message 2 of 4
norman.yuan
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;
            }
        }
    }
}

 

 

 

Message 3 of 4
RamanSBV
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

Message 4 of 4

Try to change:

doc.CloseAndDiscard();

 with:

doc.CloseAndSave(doc.Name);

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

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