Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to loop through all layouts in the drawing and get viewports' custom scale that are under them. I am able to get the value but confused with the output I am getting. There are two rows in my extract that tells me two scales of the viewport. I created 3 viewports in Layout1 and 1 viewport in Layout2. But I am not sure why there is an extra viewport showing up with scale as 1 in both layout 1 & 2 (see line 3 and 11 in the picture). I am filtering the model space viewport in my code.
public static void GetLayouts(Transaction tr, Database db, BlockTable bt, string dataOutputPath, string dwgName)
{
StringBuilder csvLayoutList = new StringBuilder();
csvLayoutList.AppendLine("HeaderToBeEditedLater");
//Open the Layout dictionary
DBDictionary layoutDict = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
//Iterate through each layout
foreach (DBDictionaryEntry layoutentry in layoutDict)
{
ObjectId layoutId = layoutentry.Value;
Layout layout = tr.GetObject(layoutId, OpenMode.ForRead) as Layout;
if (layout.LayoutName.Equals("Model", StringComparison.OrdinalIgnoreCase))
{
continue;
}
//csvLayoutList.AppendLine(layout.LayoutName);
BlockTableRecord layoutbtr = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId layoutentId in layoutbtr)
{
AcadEntity layent = tr.GetObject(layoutentId, OpenMode.ForRead) as AcadEntity;
if (layent != null && layent is Viewport)
{
Viewport viewport = layent as Viewport;
csvLayoutList.AppendLine(layout.LayoutName);
csvLayoutList.AppendLine($"Viewport Scale: {viewport.CustomScale}");
}
}
}
File.WriteAllText(dataOutputPath + "\\LayoutList.csv", csvLayoutList.ToString());
}
Solved! Go to Solution.