Note: the answer, which the OP accepted as "solution" I posted here yesterday disappeared. This missing post things has happened at least twice to my posts, which come with attached Autodesk screen cast. I guess it is a bug in the new forum software. I could not find any link to report this, thus put note here. In order to make this thread complete, I re-post my reply as "accepted solution" here again.
<Re-Post>
The reason of not getting responds might be that very few people who visit these forums use Advanced Steel and do programming with it. I do not use it, thus, hesitate to reply on something I am not sure I know.
However, since I do know Advance Steel is simply an AutoCAD vertical, similar to other ones (Map3D, Electrical, Plant3D...), and your code only deal with regular AutoCAD classes (Application, Document), so your issue/code should be testable.
I am not sure why do have multiple drawing with the same path/name open. if Document.Name is the same, which means the SAME drawing is opened in the same AutoCAD session multiple times, and only the first opened one could be read/write-able, and the rests are all opened as read-only.
Anyway, I have no problem the close all opened drawings except for the active drawing (MdiActiveDocument), be the other drawing the same drawing opened as read-only or not, with following code. Note, since you want to key current active drawing and close all other drawings (not active), so, the command method does not need to have CommandFlags.Session (i.e. with or without that flag set, the code all works).
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(CloseOpenedDwgs.Commands))]
namespace CloseOpenedDwgs
{
public class Commands
{
/// <summary>
/// This command close/discard all opened drawings in AutoCAD except
/// current active drawing
/// </summary>
[CommandMethod("CloseDwgs")]
public static void RunCommand()
{
var dwg = CadApp.DocumentManager.MdiActiveDocument;
foreach (Document d in CadApp.DocumentManager)
{
if (d.UnmanagedObject!=dwg.UnmanagedObject)
{
d.CloseAndDiscard();
}
}
}
}
}
The following screencast shows how the code works: