Clearing out my RTC API Wishlist Inbox… (do you have more wishes? RTCEUR is coming in 3 months)
Nicklas asks
Is it possible to create a macro that resets keynote when a family is duplicated?
The code and video below shows how Dynamic Model Update can be used to clear the Keynote parameter’s value any time a new Element Type is added to the file. But the problem with this is that it does not distinguish the different ways that a new Element Type can be added.
You can duplicate a type (the scenario that Nicklas wants to capture) but it also triggers when you load a family (a scenario that probably should not clear the keynote values for the just loaded families). The solution to this might include subscribing to the DocumentChanged event and using the GetTransactionNames Method to differentiate between a Duplicate and Load Family.
public void addTrigger()
{
Application app = this.Application;
MyUpdater udpater = new MyUpdater(app.ActiveAddInId);
UpdaterRegistry.RegisterUpdater(udpater, true);
UpdaterRegistry.AddTrigger(udpater.GetUpdaterId(),
new ElementClassFilter(typeof(ElementType)), Element.GetChangeTypeElementAddition());
}
public class MyUpdater : IUpdater
{
static AddInId m_appId;
static UpdaterId m_updaterId;
public MyUpdater(AddInId id)
{
m_appId = id;
m_updaterId = new UpdaterId(m_appId, new Guid("FB1BA6B2-4C06-42d4-97C1-D1B4EB593EFA"));
}
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
try
{
foreach (ElementId id in data.GetAddedElementIds())
{
ElementType etype = doc.GetElement(id) as ElementType;
if (etype == null)
continue;
Parameter p = etype.get_Parameter(BuiltInParameter.KEYNOTE_PARAM);
if (p == null)
continue;
p.Set("");
}
}
catch (Exception ex)
{
string s = ex.Message;
TaskDialog td = new TaskDialog("MyUpdater Exception");
td.MainInstruction = ex.Message;
td.MainContent = ex.StackTrace;
td.Show();
}
}
public string GetAdditionalInformation() { return ""; }
public ChangePriority GetChangePriority() { return ChangePriority.FloorsRoofsStructuralWalls; }
public UpdaterId GetUpdaterId() { return m_updaterId; }
public string GetUpdaterName() { return "MyUpdater"; }
}
[…] Read more […]
Can triggers be enabled or disabled via the API? I can see a way to remove or add triggers. I can enable or disable the updater bur not triggers.
UpdaterRegistry.RemoveAllTriggers and UpdaterRegistry.RemoveDocumentTriggers is what the API offers in this area
Hi
This blog is so nice, you have opened a hole new world in revit for me. Thank you.
Revit macro are new for me and i tried to use this one but i keep getting erros.
cs0118 is a ‘namespace’ but is used like a ‘type’
I am i doing a rookie mistake?
Hi,
Glad you are enjoying this blog. If you’d like to learn more about the API, please consider my online course at https://bitly.com/revitapi
For your specific question, it may be that you need to add some using statements at the top of the macro file. See https://boostyourbim.wordpress.com/2012/12/23/using-statements/ for more info
Harry