Tell if Parameter Definition is shared or project

Tell if Parameter Definition is shared or project

Anonymous
Not applicable
712 Views
7 Replies
Message 1 of 8

Tell if Parameter Definition is shared or project

Anonymous
Not applicable

 Hello,

 

How can I tell if a Parameter Definition is shared or project. I tried to use the following function however I think that if the parameter is not in the current shared parameters file then I get false even if it is shared within the model.

 

Any help would be very much apprectiated.

 

  Public Shared Function Rockit_DefinitionIsShared(ByVal objDefinition As Definition) As Boolean
        Dim extDef As ExternalDefinition = TryCast(objDefinition, ExternalDefinition)
        If extDef IsNot Nothing Then
            Return True
        Else
            Return False
        End If
    End Function

 

Kind Regards

David Rock

0 Likes
713 Views
7 Replies
Replies (7)
Message 2 of 8

jeremytammik
Autodesk
Autodesk

Dear David,

Yes, unfortunately the cast to ExternalDefinition is not possible.

One way to find out would be to hunt down a parameter using this definition somewhere in the project.

Once you have the Parameter instance, you can use its GUID property to find out whether it is shared or not.

I hope this helps.

Best regards,

Jeremy
--
Jeremy Tammik
Autodesk Developer Network -- http://www.autodesk.com/joinadn
The Building Coder -- http://thebuildingcoder.typepad.com




Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 8

Anonymous
Not applicable

Hello Jeremy,

 

Thank you so much for your reply, actually that is the method I have been forced to apply, but my function Enumerats through the entire model database and it's painfully slow. So I was hopefull there was anouther method. I guess I could try and do some category filtering (since I know to which categories the definition are bound) to try to speed up the function.

 

Thanks again 🙂

David

 

 

0 Likes
Message 4 of 8

jeremytammik
Autodesk
Autodesk

Hi David,

 

I would definitely suggest using all the filters you can, starting by category and type, and also adding a parameter filter.

 

I bet there is a way to make the search absolutely instantaneous.

 

Cheers, Jeremy.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 8

Anonymous
Not applicable

Hello,

 

I've worked on my function to use cetegory filtering, I'm not sure how to filter the parameter? However my program is still as slow as before, painfully slow :-(. Any more ideas? You might recognise some of your code from your blog, Thanks 🙂

 

Thanks so much.

 

Currently I have:

 

    Public Shared Function GetAllElementsFiltered(ByRef activeDBdoc As Document,
                                                         ByVal objCategory As Category) As FilteredElementCollector
        Dim categories As Categories = activeDBdoc.Settings.Categories
        Dim bics As Array = [Enum].GetValues(GetType(BuiltInCategory))

        For Each bic As BuiltInCategory In bics
            Try
                Dim objBICategory As Category = categories.Item(bic)
                If objBICategory.Name = objCategory.Name Then
                    Dim col As FilteredElementCollector = New FilteredElementCollector(activeDBdoc).WhereElementIsElementType().OfCategory(bic)                    Return col
                    Exit Function
                End If
            Catch ex As Exception
             Msgbox (ex.message)

            End Try
        Next
        Return Nothing
    End Function

 

    Public Shared Function GetCategorySetFromBinding(ByVal objBinding As Autodesk.Revit.DB.Binding) As CategorySet
        If BindingIsInstance(objBinding) Then
            Return TryCast(objBinding, InstanceBinding).Categories
        Else
            Return TryCast(objBinding, TypeBinding).Categories
        End If
    End Function

 

    Public Shared Function BindingIsInstance(ByVal objbinding As Autodesk.Revit.DB.Binding) As Boolean
        Return TryCast(objbinding, InstanceBinding) IsNot Nothing
    End Function

 

    Public Shared Function TryGetParameterFromDefinitionUsingElements(ByVal activeDBdoc As Document,
                                                                      ByVal objDefinition As Definition,
                                                                      ByVal objBinding As Autodesk.Revit.DB.Binding) As Parameter

        Dim objCategorySet As CategorySet = GetCategorySetFromBinding(objBinding)
        For Each objCategory As Category In objCategorySet
            Dim eleactiveDBdoc As FilteredElementCollector = GetAllElementsFiltered(activeDBdoc, objCategory)
            Dim ElementIter As IEnumerator = eleactiveDBdoc.GetEnumerator
            ElementIter.Reset()
            Do While ElementIter.MoveNext
                Dim objElement As Autodesk.Revit.DB.Element = ElementIter.Current
                Try
                    Dim objElementParameter As Parameter = objElement.Parameter(objDefinition.Name)
                    If objElementParameter IsNot Nothing Then
                        Return objElementParameter
                        Exit Function
                    End If
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            Loop
        Next
        Return Nothing
    End Function

0 Likes
Message 6 of 8

Anonymous
Not applicable

I can only get type parameters using the following method, any ideas on how I can get to the instance parameters?

 

Thanks. 

 

<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)> _
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)> _
<Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)> _
Public Class cmdAATesting
    Implements Autodesk.Revit.UI.IExternalCommand

    Public Function Execute(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData, _
                             ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) _
                             As Autodesk.Revit.UI.Result Implements Autodesk.Revit.UI.IExternalCommand.Execute

        Dim docActiveUIDoc As UIDocument = commandData.Application.ActiveUIDocument
        Dim activeDBdoc As Document = commandData.Application.ActiveUIDocument.Document

        Dim collector As New FilteredElementCollector(activeDBdoc)
        collector.OfCategory(BuiltInCategory.OST_DuctCurves)
        Dim duct As Element = collector.FirstElement()
        For Each objParameter As Parameter In duct.Parameters
            MsgBox(objParameter.Definition.Name)
        Next
    End Function
End Class

0 Likes
Message 7 of 8

jeremytammik
Autodesk
Autodesk

Dear David,

Of course this is painfully slow!

You are NOT using a parameter filter, and even worse, you are iterating over all parameters on all the elements you find.

There are lots of examples of using a parameter filter on the blog; search for ElementParameterFilter.

Here is one of the shorter ones which shows you the idea pretty clearly:

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

What I mean is, if you are interested in one specific parameter then you do NOT need to look at a single element that does not have that parameter, and you do NOT need to iterate over any other paramters, just pick out the single one you are interested in.

That should entirely eliminate all your time-consuming overhead.

Cheers, Jeremy.
--
Jeremy Tammik
Autodesk Developer Network -- http://www.autodesk.com/joinadn
The Building Coder -- http://thebuildingcoder.typepad.com



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 8

Anonymous
Not applicable

Sorry still no luck 😞

 

All the examples I found assume I select an object or already have the parameter ID.

 

Even if I know how to simply get all the parameters as elements. The following does not work though.

 

I neet hep with a function to get parameters as parameter (or parameter element) based on the parameter name.

 

    Public Shared Function Rockit_GetAllParameterElements(ByRef activeDBdoc As Document) As List(Of Element)

        Try
            Dim objCollector As FilteredElementCollector = New FilteredElementCollector(activeDBdoc).OfClass(GetType(Parameter))
            If objCollector IsNot Nothing Then
                Return objCollector.ToElements
                Exit Function
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return Nothing
    End Function

 

 

0 Likes