RunninThruLife RunninThruLife - 4 months ago 15
Vb.net 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:

Populate:

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
p.Set(VarVal)
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...

Try
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)
Next
MessageBox.Show(sTemp)
Catch ex As Exception
MessageBox.Show(ex.Message)
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)
Next
MessageBox.Show(sTemp)


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.

Regards,
Glen

Answer

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)
  fec.WhereElementIsNotElementType()
  fec.WherePasses(fec_filter1)
  Dim fec_i As FilteredElementIterator = fec.GetElementIterator
  Dim e As Element = Nothing
  fec_i.Reset()

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

    Try
      For Each ee As Element In ElemSet
        GetElementParameterInformation(doc, ee)
      Next
    Catch ex As Exception
      TaskDialog.Show("ERROR", ex.Message.ToString)
    End Try
    trans.Commit()
  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