Hi,
I'm trying to freeze the layer of a selected item in every other viewport of every layouts.
This code seems to work in the active layout but not in all other layouts.
Any ideas?
How do I get only the viewports in the layout and not the layout itself?
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Colors;
[assembly: CommandClass(typeof(RSNNGrundbeanspruchung.Commands))]
namespace RSNNGrundbeanspruchung
{
public class Commands
{
[CommandMethod("AFLayerfrierenTest")]
public static void AFFrierenTest()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = HostApplicationServices.WorkingDatabase;
var ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nObjekt zeigen: ");
peo.SetRejectMessage("\nKein gültiges Objekt gewählt. Objekt zeigen: ");
peo.AddAllowedClass(typeof(Entity), false);
do
{
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
ObjectId objId = per.ObjectId;
using (var tr = db.TransactionManager.StartTransaction())
{
Entity ent = (Entity)tr.GetObject(objId, OpenMode.ForRead);
LayerTable Layers = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
LayerTableRecord Layer = (LayerTableRecord)tr.GetObject(ent.LayerId, OpenMode.ForWrite);
peo.Message = string.Format("\nLayer: \"{0}\" wird in anderen Fenstern ausgeschaltet.\nObjekt zeigen: ", Layer.Name);
// Freeze "Test" layer in all viewports
ObjectId[] ids = new ObjectId[1] { ent.LayerId };
DBDictionary layoutDict = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
foreach (DBDictionaryEntry entry in layoutDict)
{
if (entry.Key != "Model")
{
Layout lay = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
foreach (ObjectId vpId in lay.GetViewports())
{
Viewport vp = (Viewport)tr.GetObject(vpId, OpenMode.ForWrite);
if (ed.CurrentViewportObjectId != vpId)
vp.FreezeLayersInViewport(ids.GetEnumerator());
}
}
}
tr.Commit();
}
} while (true);
}
}
}