TheSwamp
Code Red => .NET => Topic started by: bchapman on February 08, 2013, 10:50:13 PM
-
Just finished this. Seems convoluted... is there a better solution?
namespace BCLOCKVP
{
public class BCCLOCKVIEWPORTS
{
[CommandMethod("BCC:LOCKVP")]
static public void BCCLOCKVP()
{
Document curDoc = Application.DocumentManager.MdiActiveDocument;
Database docdb = curDoc.Database;
ObjectIdCollection BCCVIEWPORTS = docdb.GetViewports(true);
LayoutManager lm = LayoutManager.Current;
Editor ed = curDoc.Editor;
using (Transaction ts = curDoc.TransactionManager.StartTransaction())
{
DBDictionary layoutDict = docdb.LayoutDictionaryId.GetObject(OpenMode.ForRead) as DBDictionary;
foreach (DBDictionaryEntry de in layoutDict)
{
Layout layout = de.Value.GetObject(OpenMode.ForRead) as Layout;
string layoutName = layout.LayoutName;
lm.CurrentLayout = layoutName;
ObjectIdCollection vpIdCol = layout.GetViewports();
foreach (ObjectId vpId in vpIdCol)
{
Viewport vp = vpId.GetObject(OpenMode.ForWrite) as Viewport;
vp.Locked = true;
ed.WriteMessage("VP {0} is Locked", layoutName);
}
}
ts.Commit();
}
}
}
}
-
None? Apparently I'm pro after a week :p bahahahahahah
Just finished this. Seems convoluted... is there a better solution?
namespace BCLOCKVP
{
public class BCCLOCKVIEWPORTS
{
[CommandMethod("BCC:LOCKVP")]
static public void BCCLOCKVP()
{
Document curDoc = Application.DocumentManager.MdiActiveDocument;
Database docdb = curDoc.Database;
ObjectIdCollection BCCVIEWPORTS = docdb.GetViewports(true);
LayoutManager lm = LayoutManager.Current;
Editor ed = curDoc.Editor;
using (Transaction ts = curDoc.TransactionManager.StartTransaction())
{
DBDictionary layoutDict = docdb.LayoutDictionaryId.GetObject(OpenMode.ForRead) as DBDictionary;
foreach (DBDictionaryEntry de in layoutDict)
{
Layout layout = de.Value.GetObject(OpenMode.ForRead) as Layout;
string layoutName = layout.LayoutName;
lm.CurrentLayout = layoutName;
ObjectIdCollection vpIdCol = layout.GetViewports();
foreach (ObjectId vpId in vpIdCol)
{
Viewport vp = vpId.GetObject(OpenMode.ForWrite) as Viewport;
vp.Locked = true;
ed.WriteMessage("VP {0} is Locked", layoutName);
}
}
ts.Commit();
}
}
}
}
-
Any reason for not just enumerating through ObjectIds from
ObjectIdCollection BCCVIEWPORTS = docdb.GetViewports(true);
Also the argument passed for GetViewports
Input flag indicating whether to return paperspace viewports associated with layouts
In your situation you would want it to be false, and using this method you might to initialize uninitialized viewports.
-
Thanks! No reason... I didn't know how to siphon through all the layouts to get the viewports... so I cut that piece from an unrelated program out there... don't remember what it was.
is this what you were recommending?
// locks viewports
namespace BCLOCKVP
{
public class BCCLOCKVIEWPORTS
{
[CommandMethod("BCC:LOCKVP")]
static public void BCCLOCKVP()
{
Document curDoc = Application.DocumentManager.MdiActiveDocument;
Database docdb = curDoc.Database;
ObjectIdCollection BCCVIEWPORTS = docdb.GetViewports(true);
using (Transaction ts = curDoc.TransactionManager.StartTransaction())
{
foreach (ObjectId de in BCCVIEWPORTS)
{
Viewport vp = de.GetObject(OpenMode.ForWrite) as Viewport;
vp.Locked = true;
}
ts.Commit();
}
}
}
}
-
By the way this forum needs a + system to give kudos to peeps like you.
Any reason for not just enumerating through ObjectIds from
ObjectIdCollection BCCVIEWPORTS = docdb.GetViewports(true);
Also the argument passed for GetViewports
Input flag indicating whether to return paperspace viewports associated with layouts
In your situation you would want it to be false, and using this method you might to initialize uninitialized viewports.