Imports Autodesk.Revit
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
Imports System
Imports System.Windows.Forms
Imports System.Text
Public Class Form1
Private myCD As ExternalCommandData
Public Sub New(ByVal commandData As ExternalCommandData)
MyBase.New()
InitializeComponent()
myCD = commandData
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Что сюда вставить, чтобы отобразить версию revit-а?
Dim App As Autodesk.Revit.UI.UIApplication = myCD.Application
MsgBox(App.Application.VersionNumber)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim App As Autodesk.Revit.UI.UIApplication = myCD.Application
Dim Doc As UIDocument = App.ActiveUIDocument
MsgBox(Doc.Document.PathName)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim App As Autodesk.Revit.UI.UIApplication = myCD.Application
Dim Doc As UIDocument = App.ActiveUIDocument
ListAllElements()
End Sub
Sub ListAllElements()
Dim App As Autodesk.Revit.UI.UIApplication = myCD.Application
Dim Doc As UIDocument = App.ActiveUIDocument
Dim collector As FilteredElementCollector = New FilteredElementCollector(Doc.Document).OfClass(GetType(Family))
'Dim collector As FilteredElementCollector = New FilteredElementCollector(Doc.Document).WhereElementIsNotElementType
' или Dim collector As FilteredElementCollector = New FilteredElementCollector(Doc.Document).OfClass(GetType(Family))
'Dim collector_2 As FilteredElementCollector = New FilteredElementCollector(Doc.Document).WhereElementIsNotElementType
'collector.UnionWith(collector2) ' лишь бы не потерять кусок этого важного кода
Me.ListView1.Clear()
Me.ListView1.Columns.Add("№") '0
Me.ListView1.Columns.Add("ID") '1
Me.ListView1.Columns.Add("Class") '2
Me.ListView1.Columns.Add("Category") '3
Me.ListView1.Columns.Add("Name") '4
Dim s As String
Dim e As Element
Dim num As Long = 1
For Each e In collector
Call GetElementParameterInformation(Doc.Document, e)
Dim LVI As New ListViewItem
With LVI
For i As Long = 0 To 4
.SubItems.Add("")
Next
End With
s = String.Empty
If Not Nothing Is e.Category Then
s = e.Category.Name
End If
If 0 = s.Length AndAlso TypeOf e Is Family AndAlso Not Nothing Is DirectCast(e, Family).FamilyCategory Then
s = DirectCast(e, Family).FamilyCategory.Name
End If
If 0 = s.Length Then
s = "?"
End If
LVI.SubItems(0).Text = num
LVI.SubItems(1).Text = e.Id.IntegerValue.ToString
LVI.SubItems(2).Text = e.GetType.Name
LVI.SubItems(3).Text = s
LVI.SubItems(4).Text = e.Name
If LVI.SubItems(2).Text = "Family" Then
Me.ListView1.Items.Add(LVI)
num += 1
'ElseIf LVI.SubItems(2).Text = "Element" Then
' Me.ListView1.Items.Add(LVI)
' num += 1
End If
Next
For i As Integer = 0 To Me.ListView1.Columns.Count - 1
Me.ListView1.Columns(i).AutoResize(Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent)
Next i
End Sub
Public Sub GetElementParameterInformation(document As Document, element As Element)
Dim prompt As String = "Show parameters in selected Element:"
'Dim st As New StringBuilder()
Dim st As String = ""
For Each para As Parameter In element.Parameters
st = st & para.Definition.Name & " - " & para.HasValue & " - " & para.AsValueString & vbCrLf
Next
'MsgBox(st)
'TaskDialog.Show("Revit", st)
End Sub
Public Shared Function ParameterToString(ByVal param As Parameter) As String
Dim val As String = "none"
If param Is Nothing Then
Return val
End If
Select Case param.StorageType
Case StorageType.Double
Dim dVal As Double = param.AsDouble
val = dVal.ToString & " - " & param.AsValueString
Case StorageType.Integer
Dim iVal As Integer = param.AsInteger
val = iVal.ToString() & " - " & param.AsValueString
Case StorageType.String
Dim sVal As String = param.AsString
val = sVal & " - " & param.AsValueString
Case StorageType.ElementId
Dim idVal As ElementId = param.AsElementId
val = idVal.IntegerValue.ToString & " - " & param.AsValueString
Case StorageType.None
Case Else
End Select
Return val
End Function
Public Sub Add_New_Element_ListView2(ByVal element1 As String, ByVal element2 As String, ByVal element3 As String, ByVal element4 As String)
Dim acElNewLVI As New ListViewItem
With acElNewLVI
For i As Long = 0 To 3
.SubItems.Add("")
Next
.SubItems(0).Text = element1
.SubItems(1).Text = element2
.SubItems(2).Text = element3
.SubItems(3).Text = element4
End With
Me.ListView2.Items.Add(acElNewLVI)
End Sub
Public Sub Show_Parameters_Of_Element_By_Id(ByVal Id As String, Optional ByVal AsSecondaryVariant As Boolean = True)
Dim uiApp As Autodesk.Revit.UI.UIApplication = myCD.Application
Dim App As Autodesk.Revit.ApplicationServices.Application = uiApp.Application
Dim uiDoc As UIDocument = uiApp.ActiveUIDocument
Dim Doc As Document = uiDoc.Document
Dim coll As FilteredElementCollector = New FilteredElementCollector(Doc).OfClass(GetType(DB.Family))
Me.ListView2.Clear()
Me.ListView2.Columns.Add("№") '0
Me.ListView2.Columns.Add("Designation") '1
Me.ListView2.Columns.Add("Value") '2
Me.ListView2.Columns.Add("Additional value") '3
Dim acElNum As Integer = 1
For Each acEl As DB.Element In coll
Dim acElId As Integer = acEl.Id.IntegerValue
Select Case acElId
Case Id
Dim acElFam As DB.Family = CType(acEl, DB.Family)
Add_New_Element_ListView2(CType(acElNum, String), _
"Местоположение семейства", IIf(acElFam.IsInPlace, "Местный", "Загруженный"), "Family.IsInPlace") : acElNum += 1
Add_New_Element_ListView2(CType(acElNum, String), _
"Имя семейства", acEl.Name.ToString, "Family.Name") : acElNum += 1
Add_New_Element_ListView2(CType(acElNum, String), _
"Семейство рукотворное", IIf(acElFam.IsOwnerFamily, "Да", "Нет"), "Family.IsOwnerFamily") : acElNum += 1
Add_New_Element_ListView2(CType(acElNum, String), _
"ID", acEl.Id.IntegerValue.ToString, "Family.Id.IntegerValue.ToString") : acElNum += 1
Add_New_Element_ListView2(CType(acElNum, String), _
"GUID", acEl.UniqueId.ToString, "Family.UniqueId.ToString") : acElNum += 1
Add_New_Element_ListView2(CType(acElNum, String), _
"Тип элемента", acEl.GetType.Name.ToString, "Family.GetType.Name.ToString") : acElNum += 1
Dim s As String = String.Empty
If Not Nothing Is acEl.Category Then
s = acEl.Category.Name
End If
If 0 = s.Length AndAlso TypeOf acEl Is Family AndAlso Not Nothing Is DirectCast(acEl, Family).FamilyCategory Then
s = DirectCast(acEl, Family).FamilyCategory.Name
End If
If 0 = s.Length Then
s = "?"
End If
Add_New_Element_ListView2(CType(acElNum, String), _
"Имя категории", s, "Family.Category.Name") : acElNum += 1
If TypeOf acEl Is Wall Then
s = "Wall (Стена)"
ElseIf TypeOf acEl Is Floor Then
s = "Floor (Пол)"
ElseIf TypeOf acEl Is RoofBase Then
s = "Roof (Крыша)"
ElseIf TypeOf acEl Is FamilyInstance Then
If acEl.Category.Id.IntegerValue = _
BuiltInCategory.OST_Doors Then
s = "Door (Дверь)"
ElseIf acEl.Category.Id.IntegerValue = _
BuiltInCategory.OST_Windows Then
s = "Window (Окно)"
ElseIf acEl.Category.Id.IntegerValue = _
BuiltInCategory.OST_Furniture Then
s = "Furniture (Фурнитура)"
Else
s = "Component family instance (Компонент экземпляра семейства)" ' e.g. Plant
End If
ElseIf TypeOf acEl Is HostObject Then
s = "System family instance (Системный экземпляр семейства)"
Else
s = "Другой"
End If
Add_New_Element_ListView2(CType(acElNum, String), _
"Тип семейства", s, "TypeOf Family Is ...") : acElNum += 1
' Параметры семейства
Dim params As ParameterSet = acEl.Parameters
Dim nump As Integer = 1
For Each param As DB.Parameter In params
Dim name As String = param.Definition.Name
Dim val As String = ParameterToString(param)
Add_New_Element_ListView2(CType(acElNum, String), _
"Параметр #" & nump & " [" & name & "]", val, "Family.Definition.Name / ParamToString[Parameter]") : acElNum += 1
nump += 1
Next
Dim acPars As Object = acEl.GetOrderedParameters
For j As Integer = 0 To acPars.count - 1
Dim acParsVal As DB.Parameter = CType(acPars(j), DB.Parameter)
Add_New_Element_ListView2(CType(acElNum, String), _
"Параметр #" & nump & " map #" & j + 1 & " [" & acPars(j).Definition.Name & "]", ParameterToString(acParsVal), "Family.Parameter.Definition.Name / ParamToString[Parameter]") : acElNum += 1
nump += 1
Next
Case Else
End Select
Next
For i As Integer = 0 To Me.ListView2.Columns.Count - 1
Me.ListView2.Columns(i).AutoResize(Windows.Forms.ColumnHeaderAutoResizeStyle.ColumnContent)
Next i
' ПРОБЛЕМА ЗДЕСЬ
Dim acFamParams As Object = Doc.FamilyManager.GetParameters
Dim acSingleParam As FamilyParameter = CType(acFamParams(0), DB.FamilyParameter)
Dim acSP_ed As DB.Definition = acSingleParam.Definition
MsgBox(acFamParams(0).Definition.Visible & vbCr & acFamParams(0).Definition.Name)
MsgBox(Doc.FamilyManager.Parameter("Water Mark").Definition.Name)
Using tr As New Transaction(Doc)
tr.Start("add par")
Doc.FamilyManager.RenameParameter(acSingleParam, "wm")
tr.Commit()
tr.Dispose()
End Using
MsgBox(Doc.FamilyManager.Parameter("wm").Definition.Name)
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Process.Start(Environ("TEMP") & "\ref.txt")
End Sub
Private Sub ListView1_DoubleClick1(sender As Object, e As EventArgs) Handles ListView1.DoubleClick
Dim LVI As ListViewItem
LVI = ListView1.FocusedItem
Call Show_Parameters_Of_Element_By_Id(LVI.SubItems(1).Text, False)
End Sub
End Class