Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Just before printing/saving I would like to save the smallest view scale on all sheets. This is done to circumvent the "As indicated" scale text in the titleblock once you add a legend to a sheet. We just want to display the scale of the view, not the legend. In case of multiple views the smallest scale.
I'm trying to modify all sheets on catching these events by overriding a shared parameter. I can read the existing value, but not set a new one.
I tried with/without a transaction with no difference. Do these events allow modifications of the document?
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class SheetScaleManager : IExternalApplication
{
public Result OnStartup(UIControlledApplication uiApp)
{
uiApp.ControlledApplication.DocumentPrinting += new EventHandler<DocumentPrintingEventArgs>(AppDocumentPrinting);
uiApp.ControlledApplication.DocumentSaving += new EventHandler<DocumentSavingEventArgs>(AppDocumentSaving);
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
application.ControlledApplication.DocumentPrinting -= new EventHandler<DocumentPrintingEventArgs>(AppDocumentPrinting);
application.ControlledApplication.DocumentSaving-= new EventHandler<DocumentSavingEventArgs>(AppDocumentSaving);
Autodesk.Revit.UI.Result retResult = Result.Succeeded;
return retResult;
}
public void AppDocumentSaving(object sender, Autodesk.Revit.DB.Events.DocumentSavingEventArgs args)
{
ManageSheetScale(sender, args.Document);
}
public void AppDocumentPrinting(object sender, Autodesk.Revit.DB.Events.DocumentPrintingEventArgs args)
{
ManageSheetScale(sender, args.Document);
}
public void ManageSheetScale(object sender, Document doc)
{
/*
Application app = sender as Application;
UIApplication uiApp = new UIApplication(app);
Document doc = uiApp.ActiveUIDocument.Document;
*/
// Traverse all sheets
FilteredElementCollector col = new FilteredElementCollector(doc);
col.OfCategory(BuiltInCategory.OST_Sheets);
col.OfClass(typeof(ViewSheet));
Transaction trans = new Transaction(doc);
trans.Start("test");
foreach (ViewSheet S in col)
{
// Base scale string value
int MaxScale = 0;
// Get all views placed on this sheet.
ICollection<ElementId> Views = new List<ElementId>();
Views = S.GetAllPlacedViews();
// Traverse all these views and get the smallest scale...
foreach (ElementId Eid in Views)
{
View V = doc.GetElement(Eid) as View;
MaxScale = Math.Max(V.Scale, MaxScale);
}
// Update the scale
string strScale = "";
Parameter P = S.LookupParameter("NLRS_C_tekening_schaal");
if (P != null)
{
if (MaxScale > 0)
{
strScale = MaxScale.ToString();
}
string oldScale = P.AsString();
if (oldScale != strScale)
{
//P.Set(strScale);
P.SetValueString(strScale);
}
}
}
trans.Commit();
doc.Regenerate();
}
}
Solved! Go to Solution.