- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I have managed to write C# which sets Dimension suffix's and colour style depending on the value of the Dimension.
https://forums.autodesk.com/t5/revit-api-forum/code-crit/m-p/9625232#M48334
I am now wanting those overrides to update if a dimension value changes. I have followed this post primarily (the ribbons and buttons are off in a different .CS and the external command is the only bit which is definitely working!)
https://thebuildingcoder.typepad.com/blog/2010/08/structural-dynamic-model-update-sample.html
But when I couldn't get it to work, I looked around and tried suggestions in this post...
Also
https://boostyourbim.wordpress.com/2013/07/13/live-link-between-parameters-in-model-detail-families/
So I've now hit a bit of a wall! It runs with no errors, but nothing happens! Any suggestions gratefully received.
Cheers,
Mark
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.Attributes;
namespace BrickDims
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class UpdateBrickDims : IExternalApplication
{
/// <summary>
/// On shutdown, unregister the updater
/// </summary>
///
public Result OnShutdown(UIControlledApplication a)
{
BrickDimUpdater updater = new BrickDimUpdater(a.ActiveAddInId);
UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId());
return Result.Succeeded;
}
/// <summary>
/// On start up, add UI buttons, register
/// the updater and add triggers
/// </summary>
public Result OnStartup(UIControlledApplication a)
{
BrickDimUpdater updater = new BrickDimUpdater(a.ActiveAddInId);
// Register the updater in the singleton
// UpdateRegistry class
UpdaterRegistry.RegisterUpdater(updater);
// Set the filter
//ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
//ElementOwnerViewFilter filterView = new ElementOwnerViewFilter(doc.ActiveView.Id);
//ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Dimensions);
//LogicalAndFilter filter = new LogicalAndFilter(filterView, filterClass);
// Add trigger
//UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeAny());
if (!UpdaterRegistry.IsUpdaterRegistered(updater.GetUpdaterId()))
{
UpdaterRegistry.RegisterUpdater(updater, true);
ElementCategoryFilter f = new ElementCategoryFilter(BuiltInCategory.OST_Dimensions);
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), f, Element.GetChangeTypeAny());
}
return Result.Succeeded;
}
}
public class BrickDimUpdater : IUpdater
{
public static bool m_updateActive = false;
AddInId addinID = null;
UpdaterId updaterID = null;
public BrickDimUpdater(AddInId id)
{
addinID = id;
// UpdaterId that is used to register and
// unregister updaters and triggers
updaterID = new UpdaterId(addinID, new Guid(
"63CDBB88-5CC4-4ac3-AD24-52DD435AAB25"));
Console.WriteLine("Standard Numeric Format Specifiers3");
}
public int caseswitch = 1;
/// <summary>
/// Colour Code Dimensions
/// </summary>
public void Execute(UpdaterData data)
{
TaskDialog.Show("case 2", "Check");
if (m_updateActive == false) { return; }
// Get access to document object
Document doc = data.GetDocument();
UIDocument uidoc = new UIDocument(doc);
//using (Transaction t = new Transaction(doc, "Update Dim"))
//{
// t.Start();
try
{
TaskDialog.Show("case 2", "Check");
switch (caseswitch)
{
case 1:
// Loop through all the modified elements
ICollection<ElementId> modifiedCollection = data.GetModifiedElementIds();
foreach (ElementId elemId in modifiedCollection)
{
Dimension dim = doc.GetElement(elemId) as Dimension;
DimClrChecker.DimClrChngSuffix(dim, uidoc);
TaskDialog.Show("case 2", "Check");
}
caseswitch = 2;
break;
case 2:
TaskDialog.Show("case 2", "SampleUpdater");
caseswitch = 1;
break;
}
}
catch (Exception ex)
{
TaskDialog.Show("Exception", ex.Message);
}
//t.Commit();
//}
}
/// <summary>
/// Set the priority
/// </summary>
public ChangePriority GetChangePriority()
{
return ChangePriority.Annotations;
}
/// <summary>
/// Return the updater Id
/// </summary>
public UpdaterId GetUpdaterId()
{
return updaterID;
}
/// <summary>
/// Return the auxiliary string
/// </summary>
public string GetAdditionalInformation()
{
return "Automatically update dimension overrides";
}
/// <summary>
/// Return the updater name
/// </summary>
public string GetUpdaterName()
{
return "Dimension Override Updater";
}
}
[Transaction(TransactionMode.ReadOnly)]
[Regeneration(RegenerationOption.Manual)]
public class UIDynamicModelUpdateOff : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
BrickDimUpdater.m_updateActive = false;
return Result.Succeeded;
}
}
[Transaction(TransactionMode.ReadOnly)]
[Regeneration(RegenerationOption.Manual)]
public class UIDynamicModelUpdateOn : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
BrickDimUpdater.m_updateActive = true;
return Result.Succeeded;
}
}
}
Solved! Go to Solution.