提前感谢您的帮助。我不知道我做错了什么,而且变得非常令人沮丧。首先,一点背景......
计划:Revit MEP 2015 IDE:VS 2013 Ultimate
我创建了一个共享参数文件,并将该文件中的参数添加到了Project Parameters中。这些参数已应用于Conduit Runs,Conduit Fittings和Conduits。
我使用VB.NET填充参数没有问题。代码运行后,我可以在elements属性窗口中看到应用的预期文本。以下是用于填充值的代码:
填充:
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
这是我遇到错误的地方。当我尝试检索该值时,我可以通过参数的定义名称获取参数,但该值始终为空。以下是用于检索...的代码。
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
消息框正确显示所有参数名称,对于Revit参数,它为我提供了一个值。但是,共享参数仅显示参数名称,值始终为空白。我还有另一种方式可以解决这个问题吗?奇怪的是,如果我按照用户选择使用引用,我能够看到共享参数值...
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)
使用上述方法,当用户直接选择对象时,我可以看到共享参数的值和名称。他们有什么不同?
当值设置为开头时,我应该注意某种绑定吗?提前感谢大家的帮助。
此致 格伦
答案 0 :(得分:0)
Holy Bejeesus ......我想出来了,但我不确定为什么这些方法彼此不同......如果有人有任何见解,那就太棒了。
我想在这里发布答案,以防万一其他人正在与同样的事情作斗争,所以...你可以看到我用来尝试阅读上述参数的方法。在现在使用的方法中,只有几个不同的东西...... 1)元素集... 2)活动视图ID作为参数添加到FilteredElementCollector ... 3)FilteredElementIterator已实现
据我所知,迭代器正在使它与众不同......任何人都能解释它的不同之处吗?
以下是真正有效的方法......
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
无论如何,感谢您提供的任何帮助。我相信这不是我最后一次在这里发帖。
此致 奔跑