[CommandMethod("CloneLayout")]
public static void CloneLayout()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Reference the Layout Manager
LayoutManager acLayoutMgr = LayoutManager.Current;
// Create the new layout with default settings
int npoz = acLayoutMgr.LayoutCount;
string newLayoutName = "test1";
acLayoutMgr.CloneLayout("tempLayout", newLayoutName, npoz);
//
acDoc.Editor.WriteMessage("\nstep1: ");
// Получаешь ObjectId __исходного__ Layout, а не копии и дальше работаешь с ним?
// Тогда зачем ты клонировал исходный Layout???
ObjectId newLayoutID = acLayoutMgr.GetLayoutId("tempLayout");
acDoc.Editor.WriteMessage("\nstep2: ");
Layout acLayout = acTrans.GetObject(newLayoutID, OpenMode.ForRead) as Layout;
acDoc.Editor.WriteMessage("\nstep3: ");
ObjectIdCollection wViewports = acLayout.GetViewports();
//////////////////////////////////////////////////////////////////////////
// Если еще нет ни одного Viewport у Layout,
// то нужно его инициализировать
//////////////////////////////////////////////////////////////////////////
if (wViewports.Count == 0) {
acLayout.UpgradeOpen();
acLayout.Initialize();
acLayout.DowngradeOpen();
wViewports = acLayout.GetViewports();
}
//////////////////////////////////////////////////////////////////////////
acDoc.Editor.WriteMessage("\nstep4: ");
Viewport wVP = acTrans.GetObject(wViewports[0], OpenMode.ForRead) as Viewport;
acDoc.Editor.WriteMessage("\nCenterPoint: " + wVP.CenterPoint.ToString());
// Save the changes made
acTrans.Commit();
}
}