您好,
我正在尝试在每个布局的每个其他视口中冻结选定项的图层
此代码似乎适用于活动布局,但不适用于所有其他布局
如何仅获取布局中的视口,而不获取布局本身
- 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);
- }
- }
- }
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |