Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Element ID of shared parameter

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
wouter_vandebergh
3982 Views, 4 Replies

Element ID of shared parameter

wouter_vandebergh
Contributor
Contributor

I can manage registering changes of object parameters in case they are built in. In case of a shared parameter I need an elementID which I can't seem to retrieve on startup.

 

        UpdaterRegistry.AddTrigger(_updater.GetUpdaterId(), catFilter_ProjectInformation, Element.GetChangeTypeParameter("MySharedParameterHere"));

 

I would like to know when a specific project parameter changes.

I tried traversing the shared parameter file which gives me external definitions without element ID's.

0 Likes

Element ID of shared parameter

I can manage registering changes of object parameters in case they are built in. In case of a shared parameter I need an elementID which I can't seem to retrieve on startup.

 

        UpdaterRegistry.AddTrigger(_updater.GetUpdaterId(), catFilter_ProjectInformation, Element.GetChangeTypeParameter("MySharedParameterHere"));

 

I would like to know when a specific project parameter changes.

I tried traversing the shared parameter file which gives me external definitions without element ID's.

4 REPLIES 4
Message 2 of 5
JimJia
in reply to: wouter_vandebergh

JimJia
Alumni
Alumni
Accepted solution

Dear Wouter Vandebergh,

 

After creating the shared parameter, you can find the ID by Parameter.Id API or with Revit lookup tool.

Generally, the Element ID for shared parameter is positive integer while builtin Parameter is negative integer. 

You can find the RevitLookup tool from here: http://thebuildingcoder.typepad.com/blog/2016/04/revit-2017-revitlookup-and-sdk-samples.html


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com

Dear Wouter Vandebergh,

 

After creating the shared parameter, you can find the ID by Parameter.Id API or with Revit lookup tool.

Generally, the Element ID for shared parameter is positive integer while builtin Parameter is negative integer. 

You can find the RevitLookup tool from here: http://thebuildingcoder.typepad.com/blog/2016/04/revit-2017-revitlookup-and-sdk-samples.html


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
Message 3 of 5
wouter_vandebergh
in reply to: JimJia

wouter_vandebergh
Contributor
Contributor

Hi

 

This can work out if the template contained the shared parameter before we started this project.

I assume that if I add the new parameter to both our template and this specific project, the internal ID's will be different for the same shared parameter?

 

0 Likes

Hi

 

This can work out if the template contained the shared parameter before we started this project.

I assume that if I add the new parameter to both our template and this specific project, the internal ID's will be different for the same shared parameter?

 

Message 4 of 5
JimJia
in reply to: wouter_vandebergh

JimJia
Alumni
Alumni

Yes, you're right. The shared parameter is generated by Revit internal parameters mechanism, this is not guaranteed that the id of same name shared parameter is identical for different projects.


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes

Yes, you're right. The shared parameter is generated by Revit internal parameters mechanism, this is not guaranteed that the id of same name shared parameter is identical for different projects.


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
Message 5 of 5

RPTHOMAS108
Mentor
Mentor

You can update the the UpdaterRegistry when a document is opened or closed via the document event handlers.

 

i.e. When a new document is opened you search for an element containing your parameter (SharedParameterApplicableRule) and then use the found parameter ElementID to add the trigger. Likewise when a document is closing you can remove the trigger just by supplying the document (for this you don't even need the ElementID of the parameter, just the document).

 

So your document opened event handler will call something similar to the below function (GetInstanceOfSharedParameter). In the below I'm first searching by the existance of a parameter by name and then using it's GUID to verify it. If it's a project parameter which isn't shared then you can't adopt this approach. I used this approach some years ago, there may be better approaches now. For some reason the SharedParameterApplicableRule uses names of shared parameters and not GUIDs (there may be more than one parameter with the same name so GUID must be checked).

 

In the above you need to ensure at least one such element will exist in the project. You may have to also use the document changed event as part of the process for adding triggers i.e. wait until first element is added, see what it is (unless trigger has already been added by document.opened).

 

 

    Private Shared Function FilterBySharedParamExists(ParameterName As String, Optional ViewID As ElementId = Nothing) As IList(Of Element)

        Dim fRule As New SharedParameterApplicableRule(ParameterName)
         Dim filter As New ElementParameterFilter(fRule)
        Dim collector As FilteredElementCollector = Nothing
        If ViewID = Nothing Then
            collector = New FilteredElementCollector(IntDoc)
        Else
            collector = New FilteredElementCollector(IntDoc, ViewID)
        End If
        collector.WhereElementIsNotElementType()
        Dim Results As IList(Of Element) = collector.WherePasses(filter).ToElements()

        Return Results
    End Function
    Private Shared Function GetInstanceOfSharedParameter(Name As String, GUID As Guid) As Parameter
        Dim X As List(Of Element) = FilterBySharedParamExists(Name)
        For Each item As Element In X
            Dim P As Parameter = item.Parameter(GUID)
            If Not P Is Nothing Then
                Return P
            End If
        Next
        Return Nothing
    End Function

 

 

 

0 Likes

You can update the the UpdaterRegistry when a document is opened or closed via the document event handlers.

 

i.e. When a new document is opened you search for an element containing your parameter (SharedParameterApplicableRule) and then use the found parameter ElementID to add the trigger. Likewise when a document is closing you can remove the trigger just by supplying the document (for this you don't even need the ElementID of the parameter, just the document).

 

So your document opened event handler will call something similar to the below function (GetInstanceOfSharedParameter). In the below I'm first searching by the existance of a parameter by name and then using it's GUID to verify it. If it's a project parameter which isn't shared then you can't adopt this approach. I used this approach some years ago, there may be better approaches now. For some reason the SharedParameterApplicableRule uses names of shared parameters and not GUIDs (there may be more than one parameter with the same name so GUID must be checked).

 

In the above you need to ensure at least one such element will exist in the project. You may have to also use the document changed event as part of the process for adding triggers i.e. wait until first element is added, see what it is (unless trigger has already been added by document.opened).

 

 

    Private Shared Function FilterBySharedParamExists(ParameterName As String, Optional ViewID As ElementId = Nothing) As IList(Of Element)

        Dim fRule As New SharedParameterApplicableRule(ParameterName)
         Dim filter As New ElementParameterFilter(fRule)
        Dim collector As FilteredElementCollector = Nothing
        If ViewID = Nothing Then
            collector = New FilteredElementCollector(IntDoc)
        Else
            collector = New FilteredElementCollector(IntDoc, ViewID)
        End If
        collector.WhereElementIsNotElementType()
        Dim Results As IList(Of Element) = collector.WherePasses(filter).ToElements()

        Return Results
    End Function
    Private Shared Function GetInstanceOfSharedParameter(Name As String, GUID As Guid) As Parameter
        Dim X As List(Of Element) = FilterBySharedParamExists(Name)
        For Each item As Element In X
            Dim P As Parameter = item.Parameter(GUID)
            If Not P Is Nothing Then
                Return P
            End If
        Next
        Return Nothing
    End Function

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report