如何在 AutoCAD 中将此列表限制为仅纸质 space 布局?
How do I limit this list to only paper space layouts in AutoCAD?
这是一个在命令行中显示布局列表的简单命令window:
public void TestVP()
{
try
{
_AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument;
_AcDb.Database acCurDb = acDoc.Database;
_AcEd.Editor editor = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
using (_AcDb.Transaction acTrans = _AcDb.HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
_AcDb.BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable;
foreach(_AcDb.ObjectId id in acBlkTbl)
{
_AcDb.BlockTableRecord btRecord = (_AcDb.BlockTableRecord)acTrans.GetObject(id, _AcDb.OpenMode.ForRead);
if(btRecord.IsLayout)
{
_AcDb.Layout acLayout = (_AcDb.Layout)acTrans.GetObject(btRecord.LayoutId, _AcDb.OpenMode.ForRead);
editor.WriteMessage(acLayout.LayoutName + "\n");
}
}
acTrans.Commit();
}
}
catch (System.Exception ex)
{
_AcAp.Application.ShowAlertDialog(
string.Format("\nError: {0}\nStacktrace: {1}", ex.Message, ex.StackTrace));
}
}
目前它还包括模型布局。我不想这样。如何将布局列表限制为 paper space 布局?
即使我像这样使用 LayoutManager
这样做:
using (_AcDb.Transaction acTrans = _AcDb.HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
_AcDb.DBDictionary layoutDic = acTrans.GetObject(acCurDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;
foreach(_AcDb.DBDictionaryEntry entry in layoutDic)
{
_AcDb.ObjectId layoutId = entry.Value;
_AcDb.Layout layout = acTrans.GetObject(layoutId, _AcDb.OpenMode.ForRead) as _AcDb.Layout;
editor.WriteMessage(String.Format("{0}--> {1}", Environment.NewLine, layout.LayoutName));
}
acTrans.Commit();
}
我仍然得到:
Active Layout is : Model Number of Layouts is : 3
--> Layout1
--> Layout2
--> Model
我不想针对“模型”的布局名称进行测试。
这是我想出的:
public void TestVP()
{
try
{
_AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument;
_AcDb.Database acCurDb = acDoc.Database;
_AcEd.Editor editor = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
_AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current;
editor.WriteMessage(String.Format("{0}Active Layout is : {1}", Environment.NewLine, layoutMgr.CurrentLayout));
editor.WriteMessage(String.Format("{0}Number of Layouts is : {1}", Environment.NewLine, layoutMgr.LayoutCount));
using (_AcDb.Transaction acTrans = _AcDb.HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
_AcDb.BlockTable bt = acCurDb.BlockTableId.GetObject(_AcDb.OpenMode.ForRead) as _AcDb.BlockTable;
_AcDb.BlockTableRecord ms = acTrans.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead) as _AcDb.BlockTableRecord;
_AcDb.DBDictionary layoutDic = acTrans.GetObject(acCurDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;
foreach(_AcDb.DBDictionaryEntry entry in layoutDic)
{
_AcDb.ObjectId layoutId = entry.Value;
_AcDb.Layout layout = acTrans.GetObject(layoutId, _AcDb.OpenMode.ForRead) as _AcDb.Layout;
editor.WriteMessage(String.Format("{0}--> {1}", Environment.NewLine, layout.LayoutName));
_AcDb.BlockTableRecord layoutBlkTbl = acTrans.GetObject(layout.BlockTableRecordId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTableRecord;
if(layoutBlkTbl.Id != ms.Id)
editor.WriteMessage(" (PaperSpace)");
}
acTrans.Commit();
}
}
catch (System.Exception ex)
{
_AcAp.Application.ShowAlertDialog(
string.Format("\nError: {0}\nStacktrace: {1}", ex.Message, ex.StackTrace));
}
}
我得到的输出是:
Active Layout is : Model
Number of Layouts is : 3
--> Layout1 (PaperSpace)
--> Layout2 (PaperSpace)
--> Model
我只是将 Layout 的 Id
与 Model Space object Id
。可能有更简单的方法。但至少我现在可以将我的列表限制为纸质 space 布局。
这是一个在命令行中显示布局列表的简单命令window:
public void TestVP()
{
try
{
_AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument;
_AcDb.Database acCurDb = acDoc.Database;
_AcEd.Editor editor = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
using (_AcDb.Transaction acTrans = _AcDb.HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
_AcDb.BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable;
foreach(_AcDb.ObjectId id in acBlkTbl)
{
_AcDb.BlockTableRecord btRecord = (_AcDb.BlockTableRecord)acTrans.GetObject(id, _AcDb.OpenMode.ForRead);
if(btRecord.IsLayout)
{
_AcDb.Layout acLayout = (_AcDb.Layout)acTrans.GetObject(btRecord.LayoutId, _AcDb.OpenMode.ForRead);
editor.WriteMessage(acLayout.LayoutName + "\n");
}
}
acTrans.Commit();
}
}
catch (System.Exception ex)
{
_AcAp.Application.ShowAlertDialog(
string.Format("\nError: {0}\nStacktrace: {1}", ex.Message, ex.StackTrace));
}
}
目前它还包括模型布局。我不想这样。如何将布局列表限制为 paper space 布局?
即使我像这样使用 LayoutManager
这样做:
using (_AcDb.Transaction acTrans = _AcDb.HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
_AcDb.DBDictionary layoutDic = acTrans.GetObject(acCurDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;
foreach(_AcDb.DBDictionaryEntry entry in layoutDic)
{
_AcDb.ObjectId layoutId = entry.Value;
_AcDb.Layout layout = acTrans.GetObject(layoutId, _AcDb.OpenMode.ForRead) as _AcDb.Layout;
editor.WriteMessage(String.Format("{0}--> {1}", Environment.NewLine, layout.LayoutName));
}
acTrans.Commit();
}
我仍然得到:
Active Layout is : Model Number of Layouts is : 3 --> Layout1 --> Layout2 --> Model
我不想针对“模型”的布局名称进行测试。
这是我想出的:
public void TestVP()
{
try
{
_AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument;
_AcDb.Database acCurDb = acDoc.Database;
_AcEd.Editor editor = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
_AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current;
editor.WriteMessage(String.Format("{0}Active Layout is : {1}", Environment.NewLine, layoutMgr.CurrentLayout));
editor.WriteMessage(String.Format("{0}Number of Layouts is : {1}", Environment.NewLine, layoutMgr.LayoutCount));
using (_AcDb.Transaction acTrans = _AcDb.HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
{
_AcDb.BlockTable bt = acCurDb.BlockTableId.GetObject(_AcDb.OpenMode.ForRead) as _AcDb.BlockTable;
_AcDb.BlockTableRecord ms = acTrans.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead) as _AcDb.BlockTableRecord;
_AcDb.DBDictionary layoutDic = acTrans.GetObject(acCurDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;
foreach(_AcDb.DBDictionaryEntry entry in layoutDic)
{
_AcDb.ObjectId layoutId = entry.Value;
_AcDb.Layout layout = acTrans.GetObject(layoutId, _AcDb.OpenMode.ForRead) as _AcDb.Layout;
editor.WriteMessage(String.Format("{0}--> {1}", Environment.NewLine, layout.LayoutName));
_AcDb.BlockTableRecord layoutBlkTbl = acTrans.GetObject(layout.BlockTableRecordId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTableRecord;
if(layoutBlkTbl.Id != ms.Id)
editor.WriteMessage(" (PaperSpace)");
}
acTrans.Commit();
}
}
catch (System.Exception ex)
{
_AcAp.Application.ShowAlertDialog(
string.Format("\nError: {0}\nStacktrace: {1}", ex.Message, ex.StackTrace));
}
}
我得到的输出是:
Active Layout is : Model Number of Layouts is : 3 --> Layout1 (PaperSpace) --> Layout2 (PaperSpace) --> Model
我只是将 Layout 的 Id
与 Model Space object Id
。可能有更简单的方法。但至少我现在可以将我的列表限制为纸质 space 布局。