IUpdater wont trigger

IUpdater wont trigger

jsnowHJVYV
Contributor Contributor
540 Views
10 Replies
Message 1 of 11

IUpdater wont trigger

jsnowHJVYV
Contributor
Contributor

I am trying to make this parameter share the same value as the length and I can not get it to trigger or work I'm not sure what the problem is. Any help would be appreciated.

 

 

 

 

 

 

namespace iUpdater3._0
{
class RegRoomTracker : IExternalApplication
{
RoomTracker updater = null;

public Result OnStartup(UIControlledApplication uiapp)
{
AddInId addinId = uiapp.ActiveAddInId;
updater = new RoomTracker(addinId);
updater.RegisterUpdater();
updater.AddTrigger();
return Result.Succeeded;
}

public Result OnShutdown(UIControlledApplication uiapp)
{
UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId());
return Result.Succeeded;
}
}

class RoomTracker : IUpdater
{
private UpdaterId updaterid;

internal RoomTracker(AddInId addinId)
{
updaterid = new UpdaterId(addinId, new Guid("5CCFA69E-03F3-46D6-875D-5BB6FEF59190"));
}

internal void RegisterUpdater()
{
if (!UpdaterRegistry.IsUpdaterRegistered(updaterid))
UpdaterRegistry.RegisterUpdater(this, true);
}

internal void AddTrigger()
{

UpdaterRegistry.AddTrigger(updaterid, new ElementCategoryFilter(BuiltInCategory.OST_Conduit), Element.GetChangeTypeElementAddition());

}

#region IUpdater Members
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Conduit);
foreach (Element element in collector)
{
Parameter length = element.LookupParameter("length");
Parameter ce_length = element.LookupParameter("_CE_LENGTH");
if (length != null && ce_length != null)
{
double double_length = length.AsDouble();
ce_length.Set(double_length);
}
}
}

public UpdaterId GetUpdaterId()
{
return updaterid;
}

public ChangePriority GetChangePriority()
{
return ChangePriority.Annotations;
}

public string GetUpdaterName()
{
return "SchemaUpdater";
}

public string GetAdditionalInformation()
{
return "";
}
}
}
#endregion

0 Likes
541 Views
10 Replies
Replies (10)
Message 2 of 11

RPTHOMAS108
Mentor
Mentor

Make sure you have the right category.

Make sure you have the right trigger i.e. are you only wanting this to trigger when you add an element? 

Not sure Element.LookupParameter would do a case insensitive match and there is no built-in parameter starting with lowercase. Best not to use LookupParameter in the majority of cases.

You may be better off adding a trigger to check for the parameter change of 'Length' based on it's built-in id (Element.GetChangeTypeParameter(New ElementId(BuiltInParameter...))).

 

0 Likes
Message 3 of 11

jsnowHJVYV
Contributor
Contributor
Yes I am wanting this to trigger once I place an element.
0 Likes
Message 4 of 11

jsnowHJVYV
Contributor
Contributor
I had modified it to this and it is still not triggering, any more ideas?





namespace iUpdater3._0
{
class RegRoomTracker : IExternalApplication
{
RoomTracker updater = null;

public Result OnStartup(UIControlledApplication uiapp)
{
AddInId addinId = uiapp.ActiveAddInId;
updater = new RoomTracker(addinId);
updater.RegisterUpdater();
updater.AddTrigger();
return Result.Succeeded;
}

public Result OnShutdown(UIControlledApplication uiapp)
{
UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId());
return Result.Succeeded;
}
}

class RoomTracker : IUpdater
{
private UpdaterId updaterid;

internal RoomTracker(AddInId addinId)
{
updaterid = new UpdaterId(addinId, new Guid("4c27c349-9581-44ae-9ada-1234675e5e60"));
}

internal void RegisterUpdater()
{
if (!UpdaterRegistry.IsUpdaterRegistered(updaterid))
UpdaterRegistry.RegisterUpdater(this, true);
}

internal void AddTrigger()
{

UpdaterRegistry.AddTrigger(updaterid, new ElementCategoryFilter(BuiltInCategory.OST_Conduit), Element.GetChangeTypeElementAddition());
UpdaterRegistry.AddTrigger(updaterid, new ElementCategoryFilter(BuiltInCategory.OST_Conduit), Element.GetChangeTypeParameter(new ElementId(BuiltInParameter.CURVE_ELEM_LENGTH)));

}

#region IUpdater Members
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Conduit);
foreach (Element element in collector)
{
Parameter length = element.LookupParameter("Length");
Parameter ce_length = element.LookupParameter("_CE_LENGTH");
if (length != null && ce_length != null)
{
double double_length = length.AsDouble();
ce_length.Set(double_length);
}
}
}

public UpdaterId GetUpdaterId()
{
return updaterid;
}

public ChangePriority GetChangePriority()
{
return ChangePriority.Annotations;
}

public string GetUpdaterName()
{
return "SchemaUpdater";
}

public string GetAdditionalInformation()
{
return "";
}
}
}
#endregion
0 Likes
Message 5 of 11

RPTHOMAS108
Mentor
Mentor

From testing your updater it triggers the execute method ok but finds no parameter named Length so doesn't update it. So find the parameter by it's BuiltInParameter value instead. The below code works as required I have changed it slightly so that instead of filtering for the added/modified elements within the execute method it uses the ids from UpdaterData.GetAddedElementIds & UpdaterData.GetModifiedElementIds (better not to filter for things you are already given).

 

When all else fails go back to the basic examples such as is listed under IUpdater in the RevitAPI.chm. 

 

namespace iUpdater3_0
{
    public class RegRoomTracker : IExternalApplication
    {
        RoomTracker updater = null;

        public Result OnStartup(UIControlledApplication uiapp)
        {
            AddInId addinId = uiapp.ActiveAddInId;
            updater = new RoomTracker(addinId);
            updater.RegisterUpdater();
            updater.AddTrigger();
            return Result.Succeeded;
        }

        public Result OnShutdown(UIControlledApplication uiapp)
        {
            UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId());
            return Result.Succeeded;
        }
    }

    class RoomTracker : IUpdater
    {
        private UpdaterId updaterid;

        internal RoomTracker(AddInId addinId)
        {
            updaterid = new UpdaterId(addinId, new Guid("4c27c349-9581-44ae-9ada-1234675e5e60"));
        }

        internal void RegisterUpdater()
        {
            if (!UpdaterRegistry.IsUpdaterRegistered(updaterid))
                UpdaterRegistry.RegisterUpdater(this, true);
        }

        internal void AddTrigger()
        {

            UpdaterRegistry.AddTrigger(updaterid, new ElementCategoryFilter(BuiltInCategory.OST_Conduit), Element.GetChangeTypeElementAddition());
            UpdaterRegistry.AddTrigger(updaterid, new ElementCategoryFilter(BuiltInCategory.OST_Conduit), Element.GetChangeTypeParameter(new ElementId(BuiltInParameter.CURVE_ELEM_LENGTH)));

        }

       
        public void Execute(UpdaterData data)
        {
            Document doc = data.GetDocument();

            IList<ElementId> LST_add = data.GetAddedElementIds().ToList();
            IList<ElementId> LST_mod = data.GetModifiedElementIds().ToList();
            LST_mod = LST_mod.Union(LST_add).ToList();

            foreach (ElementId Id in LST_mod)
            {
                Element El = doc.GetElement(Id);
                Parameter length = El.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH);
                Parameter ce_length = El.LookupParameter("_CE_LENGTH");
                if (length != null && ce_length != null)
                {
                    double double_length = length.AsDouble();
                    ce_length.Set(double_length);
                }
            }


            //    FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Conduit);
            //foreach (Element element in collector)
            //{
            //    Parameter length = element.LookupParameter("Length");
            //    Parameter ce_length = element.LookupParameter("_CE_LENGTH");
            //    if (length != null && ce_length != null)
            //    {
            //        double double_length = length.AsDouble();
            //        ce_length.Set(double_length);
            //    }
            //}
        }

        public UpdaterId GetUpdaterId()
        {
            return updaterid;
        }

        public ChangePriority GetChangePriority()
        {
            return ChangePriority.Annotations;
        }

        public string GetUpdaterName()
        {
            return "SchemaUpdater";
        }

        public string GetAdditionalInformation()
        {
            return "";
        }
    }
}

 

Message 6 of 11

jsnowHJVYV
Contributor
Contributor
Sorry for the late response busy week last week. What are you using to get the to list to work?
0 Likes
Message 7 of 11

jsnowHJVYV
Contributor
Contributor
It isn't triggering when I placed down a piece of conduit
0 Likes
Message 8 of 11

RPTHOMAS108
Mentor
Mentor

What version of Revit are you using? I tested the above code: both placing a conduit and changing it's length, both worked in Revit 2022.

Message 9 of 11

jsnowHJVYV
Contributor
Contributor
I am using 2020
0 Likes
Message 10 of 11

jsnowHJVYV
Contributor
Contributor
I had just tried in 2022, maybe i am doing something wrong?
0 Likes
Message 11 of 11

RPTHOMAS108
Mentor
Mentor

If you were to copy and paste the above code and it doesn't work then not sure what the issue is. You need to check you've installed all the updates for that version.

 

When I run this it was from VB so I referenced a C# assembly stored an instance of the RegRoomTracker class from that assembly in a static variable then called OnStartUp and OnShutDown on it during those IExternalApplication stages in the VB code.

 

The WallUpdater example under RevitAPI.chm stores the AddInId and UpdaterId in static variables but your implementation doesn't. Without given it much thought I don't see why that would be the issue but I'd try going back to the more basic example and modify the WallUpdater from the RevitAPI.chm under IUpdater. 

0 Likes