应用程序:TypeSelector
Revit平台:所有
Revit版本:2011.0
首次发布时间:8.0
编程语言:VB.NET
技能水平:初级
类别:族文件
类型:ExternalCommand
主题:墙体类型检索。
概述:
此示例演示了如何在项目中检索一个特定族(墙)的所有类型以及如何更改一个族实例或墙的类型。
相关类:
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB.Document
Autodesk.Revit.DB.ElementId
Autodesk.Revit.DB.Family
Autodesk.Revit.DB.FamilySymbol
Autodesk.Revit.DB.FamilyInstance
Autodesk.Revit.DB.FamilySymbol
Autodesk.Revit.DB.FamilySymbolSet
Autodesk.Revit.DB.WallType
Autodesk.Revit.DB.WallTypeSet
项目文件:
Command.vb
此文件包含继承自IExternalCommand接口并实现Execute方法的Command类。
TypeSelectorWindow.vb
此文件包含一个窗体类,该类由一个ListBox控件组成,用于显示一个特定家族和墙体的所有类型。
描述:
此示例主要使用Autodesk.Revit.Elements.FamilyInstance、Family和Wall类来获取一个家族和墙体的所有类型,然后将家族实例和墙壁设置为一个特定类型。
- 使用Docment.Element(ElementId)方法通过其Id获取一个元素。
- 获取一个家族实例的家族,请使用FamilyInstance.Symbol.Family属性。
- 要获取一个族的所有类型,请使用Family.Symobls属性。
- 要获取项目中所有墙的类型,请使用Document.WallTypes属性。
- FamilyInstance.Symbol用于获取或设置家族实例的类型。
- Wall.WallType属性用于获取或设置墙体的类型。
使用说明:
1.绘制一个墙或其他家族实例(梁、柱等)。您可以为此新元素定义类型。
2.选择一个墙,在弹出的表单中,所有可用于项目中的墙体类型都在ListBox控件中列出,并选择选定元素的当前类型。
3.如果您选择一个家族实例,将检索所有所选家族实例所属家族的类型(符号),并在ListBox控件中列出。
4. 为所选元素选择一个不同类型,然后单击“确定”按钮以保存更改。之后,在元素的属性对话框中,您将发现该元素具有用户在上述表单中选择的类型。
源代码:
完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码
AssemblyInfo.vb
'
' (C) Copyright 2003-2019 by Autodesk, Inc.
'
' Permission to use, copy, modify, and distribute this software in
' object code form for any purpose and without fee is hereby granted,
' provided that the above copyright notice appears in all copies and
' that both that copyright notice and the limited warranty and
' restricted rights notice below appear in all supporting
' documentation.
'
' AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
' AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
' MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.?AUTODESK, INC.
' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
' UNINTERRUPTED OR ERROR FREE.
'
' Use, duplication, or disclosure by the U.S. Government is subject to
' restrictions set forth in FAR 52.227-19 (Commercial Computer
' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
' (Rights in Technical Data and Computer Software), as applicable.
'
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.
' Review the values of the assembly attributes
<Assembly: AssemblyTitle("")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("CC6B4E53-AFCD-482E-99A6-EDDFFF6C8890")>
' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
<Assembly: AssemblyVersion("1.0.*")>
Command.vb
'
' (C) Copyright 2003-2019 by Autodesk, Inc.
'
' Permission to use, copy, modify, and distribute this software in
' object code form for any purpose and without fee is hereby granted,
' provided that the above copyright notice appears in all copies and
' that both that copyright notice and the limited warranty and
' restricted rights notice below appear in all supporting
' documentation.
'
' AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
' AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
' MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.?AUTODESK, INC.
' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
' UNINTERRUPTED OR ERROR FREE.
'
' Use, duplication, or disclosure by the U.S. Government is subject to
' restrictions set forth in FAR 52.227-19 (Commercial Computer
' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
' (Rights in Technical Data and Computer Software), as applicable.
'
Option Explicit On
Imports System
Imports Autodesk.Revit.DB
''' <summary>
''' This sample shows how the type of a selected element, such as a wall can be changed using the API.
''' </summary>
''' <remarks></remarks>
<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 Command
Implements Autodesk.Revit.UI.IExternalCommand
''' <summary>
''' Implement this method as an external command for Revit.
''' </summary>
''' <param name="commandData">An object that is passed to the external application
''' which contains data related to the command,
''' such as the application object and active view.</param>
''' <param name="message">A message that can be set by the external application
''' which will be displayed if a failure or cancellation is returned by
''' the external command.</param>
''' <param name="elements">A set of elements to which the external application
''' can add elements that are to be highlighted in case of failure or cancellation.</param>
''' <returns>Return the status of the external command.
''' A result of Succeeded means that the API external method functioned as expected.
''' Cancelled can be used to signify that the user cancelled the external operation
''' at some point. Failure should be returned if the application is unable to proceed with
''' the operation.</returns>
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
' result of command
Dim result As Autodesk.Revit.UI.Result
result = Autodesk.Revit.UI.Result.Failed
' start transaction
Dim tran As Autodesk.Revit.DB.Transaction
tran = New Autodesk.Revit.DB.Transaction(commandData.Application.ActiveUIDocument.Document, "TypeSelector")
tran.Start()
' get all selection element
Dim selectionObject As Autodesk.Revit.UI.Selection.Selection
Dim selection As Autodesk.Revit.DB.ElementSet
selectionObject = commandData.Application.ActiveUIDocument.Selection
selection = New ElementSet()
Dim elementId As Autodesk.Revit.DB.ElementId
For Each elementId In selectionObject.GetElementIds()
selection.Insert(commandData.Application.ActiveUIDocument.Document.GetElement(elementId))
Next
Debug.Write(selection.IsEmpty)
' if one component is not selected then throw a wobbly
If (selection.Size <> 1) Then
message = "A single component or wall must be selected"
Return Autodesk.Revit.UI.Result.Failed
Else
Dim element As Autodesk.Revit.DB.Element = Nothing
Dim iter As IEnumerator
iter = selection.ForwardIterator
Do While iter.MoveNext
element = iter.Current
Loop
If Not (TypeOf element Is Autodesk.Revit.DB.FamilyInstance Or TypeOf element Is Autodesk.Revit.DB.Wall) Then
message = "A component or wall must be selected"
Return Autodesk.Revit.UI.Result.Failed
Else
Dim dialog As New TypeSelectorWindow
dialog.Initialise(commandData.Application.ActiveUIDocument.Document, element)
dialog.ShowDialog()
result = dialog.m_result
message = dialog.m_resultMessage
End If
End If
tran.Commit()
Return result
End Function
End Class