RunninThruLife RunninThruLife - 2 months ago 6x Question

How do I display the value of a shared parameter using an Element collector in Revit?

Thanks in advance for the help. I have no idea what I'm doing wrong and it's becoming very frustrating. First, a little background...

Program: Revit MEP 2015
IDE: VS 2013 Ultimate

I have created a Shared Parameter file and added the parameters in that file to the Project Parameters. These parameters have been applied to Conduit Runs, Conduit Fittings, and Conduits.

I'm using VB.NET to populate the parameters with no issue. After the code runs, I can see the expected text applied in the elements property window. Here is the code used to populate the values:


Dim p as Parameter = Nothing
Dim VarName as String = "Parameter Name"
Dim VarVal as String = "Parameter Value"

p = elem.LookupParameter(VarName) <-- elem is passed in to the function as an Element

If p IsNot Nothing Then
End if

Here's where I run into the error. When I attempt to retrieve the value, I am able to get the parameter by the parameter's definition name, but the value is always blank. Here is the code used to retrieve...

For Each e As Element In fec.OfCategory(BuiltInCategory.OST_ConduitRun)
sTemp = sTemp & "Name: " & P.Definition.Name & vbCrLf & "Value: " & P.AsString & vbCrLf & "Value As: " & P.AsValueString & vbCrLf & vbCrLf
sTemp2 = sTemp2 & "Name: " & GetParamInfo(P, doc)
Catch ex As Exception
End Try

The message box shows all of the parameter names correctly, and for the Revit parameters it gives me a value. The Shared parameters, however, only show the parameter names, the values are always blank. Is there another way that I'm supposed to be going about this? Oddly, I'm able to see the shared parameter values if I use a reference by user selection like so...

Dim uiDoc As UIDocument = app.ActiveUIDocument
Dim Sel As Selection = uiDoc.Selection
Dim pr As Reference = Nothing
Dim doc As Document = uiDoc.Document
Dim fec As New FilteredElementCollector(doc)
Dim filter As New ElementCategoryFilter(BuiltInCategory.OST_ConduitRun)
Dim sTemp As String = "", sTemp2 As String = ""
Dim elemcol As FilteredElementCollector = fec.OfCategory(BuiltInCategory.OST_ConduitRun)
Dim e As Element = Nothing, el As Element = Nothing
Dim P As Parameter

pr = Sel.PickObject(ObjectType.Element)
e = doc.GetElement(pr)

For Each P in e.Paramters
sTemp = sTemp & "Name: " & P.Definition.Name & vbCrLf & "Value: " & P.AsString & vbCrLf & "Value As: " & P.AsValueString & vbCrLf & vbCrLf
sTemp2 = sTemp2 & "Name: " & GetParamInfo(P, doc)

With the method above, when the user selects the object directly, I can see the values and the names of shared parameters. How are they different?

Is there some sort of binding that I should be looking at when the value is set to begin with? Thanks in advance for everyone's help.



Holy Bejeesus... I figured it out, but I'm not sure why the methods are that different from each other... if anyone had any insight, that'd be great.

I wanted to post the answer here, just in case anyone else is fighting with the same thing, so... you can see the method I was using to try to read the parameters above. In the method being used now there are only a couple of things that are different... 1) An element set... 2) An active view Id was added as a parameter to the FilteredElementCollector... 3) A FilteredElementIterator was implemented.

As far as I can tell it's the iterator that's making it different... can anyone explain what it's doing differently?

Below is the method that actually works...

Public Sub Execute(app As UIApplication) Implements IExternalEventHandler.Execute
  Dim prompt As String = ""
  Dim uiDoc As UIDocument = app.ActiveUIDocument
  Dim doc As Document = uiDoc.Document
  Dim ElemSet As ElementSet = app.Application.Create.NewElementSet
  Dim fec As New FilteredElementCollector(doc, doc.ActiveView.Id)
  Dim fec_filter As New ElementCategoryFilter(BuiltInCategory.OST_Conduit)
  Dim fec_i As FilteredElementIterator = fec.GetElementIterator
  Dim e As Element = Nothing

  Using trans As New Transaction(doc, "Reading Conduit")
    While (fec_i.MoveNext)
      e = TryCast(fec_i.Current, Element)
    End While

      For Each ee As Element In ElemSet
        GetElementParameterInformation(doc, ee)
    Catch ex As Exception
      TaskDialog.Show("ERROR", ex.Message.ToString)
    End Try
  End Using
End Sub

At any rate, thanks for any help that was offered. I'm sure it won't be the last time that I post here.

Regards, Runnin