IUpdater Trigger based on parameter change

IUpdater Trigger based on parameter change

Anonymous
Not applicable
4,206 Views
39 Replies
Message 1 of 40

IUpdater Trigger based on parameter change

Anonymous
Not applicable

I writing an API to do some calculations whenever a certain parameter is changed. I have gotten it to work using the .GetChangeAny trigger but can not figure out how to get it to change only if a certain parameter has been changed. I currently it being registered during startup and I think that is my problem since I can't find the parameter since there isn't any document open. I even tried hard coded the element ID and that didn't seem to work either. Any insight would be greated appreciated.

 

Thanks

0 Likes
4,207 Views
39 Replies
Replies (39)
Message 2 of 40

Anonymous
Not applicable

It somewhat depends on the type of parameter you are using, but here is how I find a change to one Built-In Parameter:

 

ElementClassFilter sheets = new ElementClassFilter(typeof(ViewSheet));
ElementId ShtNumID = new ElementId(BuiltInParameter.SHEET_NUMBER);
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), sheets, Element.GetChangeTypeParameter(ShtNumID));

 

0 Likes
Message 3 of 40

Anonymous
Not applicable

I am actually trying to track a change to a shared parameter. I have the updater register based on the document opened event. That seems to work ok. But for what ever reason when I try and assign the parameter to the trigger it doesn't take.

0 Likes
Message 4 of 40

Anonymous
Not applicable

Can you post a code snippet?

 

Does it error out or just fail to work properly?

0 Likes
Message 5 of 40

Anonymous
Not applicable

Here is the code for registering the updater. It isn't throwing an error when it is run. It just isn't doing anything. I'm wondering if maybe if it is the filter I am using. Thanks for you help.

 

 

Public Sub application_DocumentOpened(ByVal sender As Object, ByVal args As Autodesk.Revit.DB.Events.DocumentOpenedEventArgs)
        ' get document from event args.

        Dim doc As Document = args.Document
        Dim updater As New ViewingConeUpdater(sharedApplication.ActiveAddInId)
        UpdaterRegistry.RegisterUpdater(updater)


        Dim displayInstanceFilter As New ElementClassFilter(GetType(FamilyType))
        
        Dim ecollector As New FilteredElementCollector(doc)
        ecollector.OfCategory(BuiltInCategory.OST_CommunicationDevices)

        For Each e As Element In ecollector
            Try

                If e.ParametersMap.Contains("Image Height") Then
                    UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), displayInstanceFilter, Autodesk.Revit.DB.Element.GetChangeTypeParameter(e.Parameter("Image Height")))
                    Exit For
                End If

                UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), displayInstanceFilter, Autodesk.Revit.DB.Element.GetChangeTypeElementAddition())
            Catch ex As Exception
                TaskDialog.Show("Error", ex.StackTrace.ToString)
            End Try

        Next
    End Sub

End Class

0 Likes
Message 6 of 40

Anonymous
Not applicable

I am not familiar with VB- I work in C#, but I will give it a try.

 

I question your use of "ParametersMap." RevitLookup has no usable data there, and certainly no names. I would suggest:

 

For Each e As Element In ecollector
	Try
	For Each p as Parameter in e.Parameters
		If p.Definition.Name = "Image Height" Then
		UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), displayInstanceFilter, Autodesk.Revit.DB.Element.GetChangeTypeParameter(p))
		Exit For
		Exit For		
	End If

 

0 Likes
Message 7 of 40

Anonymous
Not applicable

Thank you for all your help Peter. That is getting the trigger to register but it still isn't triggering anything when the parameter is changed. I have a feeling it has to do with the Element filter I am using.

 

This is the code I am currently using

 

  Dim displayInstanceFilter As New ElementClassFilter(GetType(FamilyType))

 

After some reading ,because the parameter Image Height is a type parameter, I tried changing it to  this

 

Dim displayInstanceFilter As New ElementClassFilter(GetType(FamilySymbol))

 

but it still doesn't seem to work. Do you have any idea what filter I should use for an Instance parameter vs a type parameter. Thanks again

 

 

 

0 Likes
Message 8 of 40

gopinath.taget
Alumni
Alumni

Hello,

 

May be this blog post will help:

 

http://thebuildingcoder.typepad.com/blog/2010/08/elementparameterfilter-with-a-shared-parameter.html

 

Best Regards

Gopinath

0 Likes
Message 9 of 40

arnostlobel
Alumni
Alumni
Adeuley:

I am afraid changes to shared parameters are not considered parameter changes, at least for the dynamic update triggering purposes. The only way to watch for changes of shared parameters on an element is to set the trigger for change-any on that element.

Arnošt Löbel
Autodesk Revit R&D
Arnošt Löbel
0 Likes
Message 10 of 40

Anonymous
Not applicable

So the only parameter that are considered parameter changes for the dynamic update are built-in parameters?

0 Likes
Message 11 of 40

Anonymous
Not applicable

I did find this post where a non built in parameter "Fred" was used.

 

http://boostyourbim.wordpress.com/2013/07/13/live-link-between-parameters-in-model-detail-families/#...

 

It looks like he did it using a macro but since it is not in VB.net I am have trouble getting it to compile.

0 Likes
Message 12 of 40

arnostlobel
Alumni
Alumni
It is not clear that Harry meant a shared parameter when using the "Fred" parameter in his example. I think he meant it as an example of "any" parameter. I'll ask him.

Arnošt Löbel
Autodesk Revit R&D
Arnošt Löbel
0 Likes
Message 13 of 40

arnostlobel
Alumni
Alumni
I talked to Harry Mattison, the author of the code from the blog you referenced, and Harry confirmed that indeed in R2014 he could use it for shared parameters as well, at least for those he tried it with. We will do more investigation on that, but apparently our few fixes for dynamic updaters we included in 2014 now allow shared parameters (at least some) to be tracked by ChangeTypeParameter.

Arnošt Löbel
Autodesk, Revit R&D
Arnošt Löbel
0 Likes
Message 14 of 40

gopinath.taget
Alumni
Alumni

Hello adeuley,

 

If Harry's solution works as Arnost indicated, can you please accept it as the solution please?

 

Thanks

Gopinath

0 Likes
Message 15 of 40

Anonymous
Not applicable

I did some testing on 2014 and it didn't work with the parameter as a type parameter but did as an instance parameter. I then ran the same test on 2013 and it also works if it is an instance parameter. That makes me think that the issue is the filter I am using with the updater but I may be wrong. I will keep trying.

0 Likes
Message 16 of 40

arnostlobel
Alumni
Alumni
That is correct, adeuley; you have to be careful about parameters and always realize which ones are on instances and which ones are on types.
I am glad you've got something working.

Arnošt Löbel
Autodesk, Revit R&D
Arnošt Löbel
0 Likes
Message 17 of 40

Anonymous
Not applicable

Does the Iupdater only work on instance parameters or can it also work on type parameters?

0 Likes
Message 18 of 40

arnostlobel
Alumni
Alumni
It should work on both kinds of parameters, but you must use it with the right respective elements – either the type element, or an instance.

Arnošt Löbel
Autodesk, Revit R&D
Arnošt Löbel
0 Likes
Message 19 of 40

Anonymous
Not applicable

I have tried the following filters :

 

 

Dim displayInstanceFilter As New ElementClassFilter(GetType(FamilyInstance))

 

Dim displayTypeFilter As New ElementClassFilter(GetType(FamilySymbol))

 

The top one works for the instances parameters but the bottom one doesn't work for the type parameters. Is it looking for the wrong element? I thought that Family Symbol represents each Family Type. Thanks for all of your help.

0 Likes
Message 20 of 40

arnostlobel
Alumni
Alumni

That is not the right approach, I believe. If we consider you have an instance element myInstanceElem and wanted to look for changes of parameters of the instance type, then you would get the element of the type by calling myInstanceElem.GetTypeId(). That returns an element Id you would then use to set up the updater’s trigger.

 

Arnošt Löbel

Autodesk, Revit R&D

Arnošt Löbel
0 Likes