TheSwamp
Code Red => .NET => Topic started by: alexborodulin11 on August 25, 2011, 09:08:27 PM
-
Why after iterating through all drawings with closing each document similar to code shown below, one drawing is still on the screen. How to iterate and close all drawings?
Dim docs As DocumentCollection
Dim doc As Document
docs = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
For Each doc In docs
'do things,
'then
'doc.CloseAndDiscard() or
'doc.CloseAndSave(doc.Name)
Next
-
Try with this:
http://through-the-interface.typepad.com/through_the_interface/2007/03/closing_all_ope.html
-
Welcome to the Swamp!!!
Are you in Application execution context?-----Session command flag
This works fine for me
<CommandMethod("CloseAllDrawings", CommandFlags.Session)> _
Public Sub CloseAllDrawings()
Dim docs As DocumentCollection = Application.DocumentManager
For Each doc As Document In docs
doc.CloseAndDiscard()
Next
End Sub
This will leave one the current document open.
It executes in the 'document context'
<CommandMethod("CloseAllDrawingsWithoutSession")> _
Public Sub CloseAllDrawingsWithoutSession()
Dim docs As DocumentCollection = Application.DocumentManager
For Each doc As Document In docs
Try
doc.CloseAndDiscard()
Catch ex As System.Exception
End Try
Next
End Sub
If I remember correctly since it executes in 'document context' it is locked automatically not allowing it to close
-
the same result: current drawing is still open
-
Works for me
// (C) kdub
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(CloseAllDocuments.MyCommands))]
namespace CloseAllDocuments
{
public class MyCommands
{
[CommandMethod("CloseAllDrawings", CommandFlags.Modal | CommandFlags.Session)]
public void CloseAllDrawings()
{
DocumentCollection docs = Application.DocumentManager;
foreach (Document doc in docs)
{
doc.CloseAndDiscard();
}
}
}
}
-
Jeff:
Adding
CommandFlags.Session
solved the problem
Thank you!
Alex