Daniel,
Very cool. Thanks for sharing.
The new function works with some of my routines but I have one that I can't get it work with.
[CommandMethod("layoutfreeze")]
static public void FreezeLayerInAllOtherViewPorts()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectIdCollection layList = new ObjectIdCollection();
ObjectIdCollection vpList = new ObjectIdCollection();
PromptEntityOptions opts = new PromptEntityOptions("\nSelect Object whose layer will be frozen in all Other Viewports: ");
opts.AllowNone = true;
opts.AllowObjectOnLockedLayer = true;
//Select the object on-screen
PromptEntityResult res = ed.GetEntity(opts);
if (res.Status == PromptStatus.OK)
{
ObjectId ObjID = res.ObjectId;
ObjectId currVPortID = ed.CurrentViewportObjectId;
try
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity ent = (Entity)trans.GetObject(ObjID, OpenMode.ForRead, false);
Viewport vpEnt = (Viewport)trans.GetObject(currVPortID, OpenMode.ForWrite);
ViewportTable vpTbl = (ViewportTable)trans.GetObject(db.ViewportTableId, OpenMode.ForRead);
ObjectId layerId = ent.LayerId;
layList.Add(layerId);
ObjectId layoutDictID = db.LayoutDictionaryId;
DBDictionary layoutDict = (DBDictionary)trans.GetObject(layoutDictID, OpenMode.ForRead);
foreach(DBDictionaryEntry LayoutDictEntry in layoutDict)
{
Layout testLayout = (Layout)trans.GetObject(LayoutDictEntry.Value, OpenMode.ForWrite);
ObjectIdCollection LayoutVPs = testLayout.GetViewports();
foreach (ObjectId testVpEntID in LayoutVPs)
{
Viewport testVpEnt = (Viewport)trans.GetObject(testVpEntID, OpenMode.ForWrite);
testVpEnt.FreezeLayersInViewport(layList.GetEnumerator());
//test it here
// RegenLayers(layList, 0);
}
}
//thaw the layer in the current viewport
vpEnt.ThawLayersInViewport(layList.GetEnumerator());
trans.Commit();
}//using
//Test the new function here
RegenLayers(layList, 0);
}//end try
catch (System.Exception ex)
{
ed.WriteMessage("\nError Freezing Layers: " + ex.Message);
}
}// if
}//FreezeLayerInAllOtherViewPorts
This little function freezes the layers correctly, but the I still must close and re-open the drawing to make the changes apparent.
(The code currently freezes the layer in the layout itsself (paperspace), which is not exactly the intent. I will tackle that next)
I have tried the RegenLayers in several places both inside and outside the transaction but still no glory.
Any ideas?
Thanks again for sharing.