added Revit 2022 SDK minus except *rvt and *rfa

This commit is contained in:
Jeremy Tammik
2021-04-20 11:36:21 +02:00
parent 1133a82dc5
commit 7e327986e8
3034 changed files with 1245318 additions and 0 deletions
@@ -0,0 +1,39 @@
'
' (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.Reflection
Imports System.Runtime.InteropServices
<Assembly: AssemblyTitle("")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>
<Assembly: Guid("5A0846D9-CBB3-4674-9ED9-894EEA0DFC72")>
<Assembly: AssemblyVersion("1.0.*")>
@@ -0,0 +1,115 @@
'
' (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.Collections.Generic
Imports Autodesk.Revit
Imports Autodesk.Revit.DB
'
' LibraryPaths
'
' This sample goes through the list of library paths held in the Revit.
' If it has a certain key, it erases it. If not, it adds a new path to the existing set.
' In the Revit UI, you can check the list in:
' Settings --> Options... --> [File Locations] Tab --> Libraries.
'
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)> _
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)> _
<Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)> _
Public Class RvtCmd_LibraryPaths ' Library Paths
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
Const key As String = "API New Library Path"
Const libPath As String = "C:\Temp"
Const comment As String = _
"Click Revit button --> [Options...] --> [File Locations] tab --> Places"
Dim rvtApp As Autodesk.Revit.ApplicationServices.Application = commandData.Application.Application
' get the collection of library paths.
Dim paths As IDictionary(Of String, String) = rvtApp.GetLibraryPaths()
Dim iter As IEnumerator(Of KeyValuePair(Of String, String)) = paths.GetEnumerator()
' iterate through the collection, and gether them in a string to display it.
'
Dim str As String = ""
Do While (iter.MoveNext())
str += iter.Current.Key + " = " + iter.Current.Value + vbCr
Loop
' show it.
MsgBox(str)
' do we have lib path with this key?
If (paths.ContainsKey(key)) Then
' erase the key
paths.Remove(key)
Else
' add a new path to the collection.
paths.Add(key, libPath)
End If
' update the path.
rvtApp.SetLibraryPaths(paths)
' display it again.
'
iter = paths.GetEnumerator()
iter.Reset()
str = ""
Do While (iter.MoveNext())
str += iter.Current.Key + " = " + iter.Current.Value + vbCr
Loop
MsgBox(str + vbCr + comment)
Return Autodesk.Revit.UI.Result.Succeeded
End Function
End Class
@@ -0,0 +1,212 @@
'
' (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.
'
'
' RevitCommands - Revit API custom command samplers. This project includes the following function/object usage.
'
' LoadFamily
' LoadFamilySymbol
'
Imports System
Imports System.IO
Imports System.Reflection
Imports System.Collections.Generic
Imports Autodesk.Revit
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI
'
' LoadFamilySymbol - loads a family symbol/type of the given file and the symbol name.
'
<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 RvtCmd_LoadFamilySymbol
Implements 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
Environment.CurrentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
' hard coded family file and type name
Dim fileName As String = "W-Wide Flange-Column.rfa"
fileName = Path.GetFullPath(fileName)
Const symName As String = "W10X49"
If Not File.Exists(fileName) Then
message = String.Format("Can't find the file '{0}'", fileName)
Return Autodesk.Revit.UI.Result.Failed
End If
Dim revitDoc As Document = commandData.Application.ActiveUIDocument.Document
Dim transaction As New Autodesk.Revit.DB.Transaction(revitDoc, "RvtCmd_LoadFamilySymbol")
Try
transaction.Start()
Dim loadSuccess As Boolean = revitDoc.LoadFamilySymbol(fileName, symName)
transaction.Commit()
If (loadSuccess) Then
MsgBox("Family " & fileName & ", Type " & symName & " successfully loaded!")
Return Autodesk.Revit.UI.Result.Succeeded
End If
Catch ex As Exception
transaction.RollBack()
End Try
MsgBox("ERROR in loading Family " & fileName & ", Type " & symName)
Return Autodesk.Revit.UI.Result.Failed
End Function
End Class
'
' LoadFamily - loads a family of the given family name.
'
'
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)> _
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)> _
Public Class RvtCmd_LoadFamily
Implements Autodesk.Revit.UI.IExternalCommand
Private libPaths As String
''' <summary>
''' Implement this method as an external command for Revit.
''' </summary>
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
Dim rvtApp As Autodesk.Revit.UI.UIApplication = commandData.Application
Dim revitDoc As Document = commandData.Application.ActiveUIDocument.Document
libPaths = Nothing
' family file name. hard coded for simplicity.
'
Dim fileName As String = "Sink Kitchen-Single.rfa"
' (1) hard coded family path.
'Dim filePath As String =
'"C:\Documents and Settings\All Users\Application Data\Autodesk\Revit Architecture 2009\Metric Library\Structural\Framing\Steel"
' (2) or search a family path in the library paths.
Dim filePath As String = findFile(rvtApp.Application, fileName)
If (filePath Is Nothing) Then
message = "Cannot find the file '" + fileName + "' in Revit Libraries:" + ControlChars.NewLine + libPaths
Return Autodesk.Revit.UI.Result.Failed
End If
' set a full path to call LoadFamily method.
Dim fullPath As String = filePath + "\" + fileName
Dim transaction As New Autodesk.Revit.DB.Transaction(revitDoc, "RvtCmd_LoadFamily")
Try
transaction.Start()
Dim loadSuccess As Boolean = revitDoc.LoadFamily(fullPath)
transaction.Commit()
If (loadSuccess) Then
MsgBox("Loaded a family ok.")
Return Autodesk.Revit.UI.Result.Succeeded
End If
Catch ex As Exception
transaction.RollBack()
End Try
MsgBox("Failed to load a family.")
'Return Autodesk.Revit.UI.Result.Failed ' bug in Revit 8.0
Return Autodesk.Revit.UI.Result.Succeeded
End Function
' Helper function - find the given file name in the set of Revit library paths.
'
Public Function findFile(ByVal rvtApp As Autodesk.Revit.ApplicationServices.Application, ByVal fileName As String) _
As String
Dim paths As IDictionary(Of String, String) = rvtApp.GetLibraryPaths()
Dim iter As IEnumerator(Of KeyValuePair(Of String, String)) = paths.GetEnumerator()
Dim filePath As String = Nothing
' loop through each path in the collection.
Do While (iter.MoveNext())
Dim path As String = iter.Current.Value
libPaths += ControlChars.Tab + path + ";" + ControlChars.NewLine
filePath = SearchFile(path, fileName)
If Not (filePath Is Nothing) Then
Return filePath
End If
Loop
filePath = SearchFile(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), fileName)
If Not (filePath Is Nothing) Then
Return filePath
End If
Return Nothing
End Function
' Helper function - recursively search the given file name under the current directory.
'
Public Function SearchFile(ByVal path As String, ByVal fileName As String) As String
If Not Directory.Exists(path) Then
Return Nothing
End If
' search this directory
Dim fname As String
For Each fname In Directory.GetFiles(path, fileName)
MsgBox("I found the file in: " + fname)
Return path
Next
' recursively search child directories.
Dim dname As String
For Each dname In Directory.GetDirectories(path)
Dim filePath As String = SearchFile(dname, fileName)
If Not (filePath Is Nothing) Then
Return filePath
End If
Next
Return Nothing
End Function
End Class
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>RevitCommands.dll</Assembly>
<ClientId>07f80cfc-ff8a-462c-8165-d7c01385f718</ClientId>
<FullClassName>Revit.SDK.Samples.RevitCommands.VB.NET.RvtCmd_LibraryPaths</FullClassName>
<Text>RvtCmd_LibraryPaths</Text>
<Description>List the Revit library paths.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
<AddIn Type="Command">
<Assembly>RevitCommands.dll</Assembly>
<ClientId>92a73c14-b5d8-4bde-99e6-14740f3657ae</ClientId>
<FullClassName>Revit.SDK.Samples.RevitCommands.VB.NET.RvtCmd_LoadFamilySymbol</FullClassName>
<Text>RvtCmd_LoadFamilySymbol</Text>
<Description>Load a family symbol/type.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
<AddIn Type="Command">
<Assembly>RevitCommands.dll</Assembly>
<ClientId>7f300cbe-8b8e-41d8-967e-c12c8dddaccf</ClientId>
<FullClassName>Revit.SDK.Samples.RevitCommands.VB.NET.RvtCmd_LoadFamily</FullClassName>
<Text>RvtCmd_LoadFamily</Text>
<Description>Load a family.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
<AddIn Type="Command">
<Assembly>RevitCommands.dll</Assembly>
<ClientId>519c35fc-b485-4ac7-a37d-7d7c3021de3c</ClientId>
<FullClassName>Revit.SDK.Samples.RevitCommands.VB.NET.RvtCmd_Selection</FullClassName>
<Text>RvtCmd_Selection</Text>
<Description>show how to use selection set.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
<AddIn Type="Command">
<Assembly>RevitCommands.dll</Assembly>
<ClientId>3f905f59-5f0f-4692-802e-3cb73287949a</ClientId>
<FullClassName>Revit.SDK.Samples.RevitCommands.VB.NET.RvtCmd_ShowElementData</FullClassName>
<Text>RvtCmd_ShowElementData</Text>
<Description>show parameters in selected entities.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{73C4CC97-C4BE-453E-92CA-CA3D3F2F5285}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon>
</ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>RevitCommands</AssemblyName>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyMode>None</AssemblyOriginatorKeyMode>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<OptionCompare>Binary</OptionCompare>
<OptionExplicit>On</OptionExplicit>
<OptionStrict>Off</OptionStrict>
<RootNamespace>Revit.SDK.Samples.RevitCommands.VB.NET</RootNamespace>
<StartupObject>RevitCommands.%28なし%29</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<MyType>Windows</MyType>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\</OutputPath>
<DocumentationFile>
</DocumentationFile>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>
</DefineConstants>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>1</WarningLevel>
<NoWarn>42016,42017,42018,42019,42032</NoWarn>
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\</OutputPath>
<DocumentationFile>
</DocumentationFile>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>
</DefineConstants>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<DebugSymbols>false</DebugSymbols>
<Optimize>true</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>1</WarningLevel>
<NoWarn>42016,42017,42018,42019,42032</NoWarn>
<DebugType>none</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<BaseAddress>285212672</BaseAddress>
<WarningLevel>1</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>42016,42017,42018,42019,42032</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Release\</OutputPath>
<BaseAddress>285212672</BaseAddress>
<Optimize>true</Optimize>
<WarningLevel>1</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>42016,42017,42018,42019,42032</NoWarn>
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
<Name>System</Name>
</Reference>
<Reference Include="System.Data">
<Name>System.Data</Name>
</Reference>
<Reference Include="System.Xml">
<Name>System.XML</Name>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="LibraryPath.vb" />
<Compile Include="LoadFamily.vb" />
<Compile Include="RvtUtils.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="Selection.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="ShowElementData.vb">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<Import Project="$(SolutionDir)VSProps\SDKSamples.VB.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PostBuildEvent>set FILEFORSAMPLEREG="$(SolutionDir)..\..\..\..\Regression\API\SDKSamples\UpdateSampleDllForRegression.pl"
if exist %25FILEFORSAMPLEREG%25 perl %25FILEFORSAMPLEREG%25 $(ProjectExt) "$(ProjectPath)" "$(TargetPath)" "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
</Project>
@@ -0,0 +1,376 @@
'
' (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.Collections.Generic
Imports Autodesk.Revit.DB
'
' Utilities
'
Public Class RvtUtils
'==================================================================
'
' Show Element Information
'
'==================================================================
' List all the parameters of the given element.
'
Public Shared Sub ListParameters(ByVal elem As Autodesk.Revit.DB.Element)
ListInstanceParameters(elem)
ListTypeParameters(elem)
End Sub
'------------------------------------------------------------------
' List Instance Parameters
'
Public Shared Sub ListInstanceParameters(ByVal elem As Autodesk.Revit.DB.Element)
' header
Dim str As String = " -- Instance Paramaters -- " & vbCr & vbCr
' get params
Dim params As ParameterSet = elem.Parameters
str = str + ParameterSetToString(elem.Document, params)
' show it
MsgBox(str)
End Sub
'------------------------------------------------------------------
' List Type Parameters
'
Public Shared Sub ListTypeParameters(ByVal elem As Autodesk.Revit.DB.Element)
' header
Dim str As String = " -- Type Paramaters -- " & vbCr
' get the type.
Dim typeId As Autodesk.Revit.DB.ElementId = elem.GetTypeId()
Dim type As Autodesk.Revit.DB.ElementType = elem.Document.GetElement(typeId)
If Not (type Is Nothing) Then
' get family and type name. Note: this is not the part of parameter set below.
Dim paramFamilyTypeName As Autodesk.Revit.DB.Parameter = type.Parameter( _
BuiltInParameter.SYMBOL_FAMILY_AND_TYPE_NAMES_PARAM)
str = str + "Family Type Name: " + ParameterToString(elem.Document, _
paramFamilyTypeName) + vbCr + vbCr
' get parameter set.
Dim params As ParameterSet = type.Parameters
str = str & ParameterSetToString(elem.Document, params)
Else
str = str & "none"
End If
' show it.
MsgBox(str)
End Sub
'------------------------------------------------------------------
' Return a string form of a given parameter set
'
Public Shared Function ParameterSetToString(ByVal rvtDoc As Autodesk.Revit.DB.Document, _
ByVal params As ParameterSet) As String
Dim str As String = ""
' does the element have parameters? if not, simply return.
If (rvtDoc Is Nothing) Or (params Is Nothing) Or params.IsEmpty Then
str = "none" & vbCr
Return str
End If
' we have some parameters. show it.
Dim param As Autodesk.Revit.DB.Parameter
For Each param In params
Dim name As String = param.Definition.Name
str = str & name & ": " & ParameterToString(rvtDoc, param) & vbCr
Next
Return str
End Function
'------------------------------------------------------------------
' Return a string form of a given parameter
'
Public Shared Function ParameterToString(ByVal rvtDoc As Autodesk.Revit.DB.Document, _
ByVal param As Autodesk.Revit.DB.Parameter) As String
Dim val As String = "none"
If (rvtDoc Is Nothing) Or (param Is Nothing) Then
Return val
End If
Dim type As Autodesk.Revit.DB.StorageType = param.StorageType
' take the internal type of the parameter and convert it into a string
Select Case type
Case StorageType.Double
val = param.AsDouble
Case StorageType.ElementId
' get the element and use its name.
Dim paraElem As Autodesk.Revit.DB.Element = rvtDoc.GetElement(param.AsElementId)
If Not (paraElem Is Nothing) Then
val = paraElem.Name
End If
Case StorageType.Integer
val = param.AsInteger
Case StorageType.String
val = param.AsString
Case StorageType.None
val = param.AsValueString
Case Else
End Select
Return val
End Function
'============================================================================
'
' List geometry information of the given element.
'
'============================================================================
Public Shared Sub ListGeometry(ByVal rvtApp As Autodesk.Revit.ApplicationServices.Application, _
ByVal elem As Autodesk.Revit.DB.Element)
' header.
Dim str As String = " -- Geometry -- " & vbCr
' set the geometry option.
Dim opt As Autodesk.Revit.DB.Options
opt = rvtApp.Create.NewGeometryOptions
opt.DetailLevel = Autodesk.Revit.DB.ViewDetailLevel.Fine
' does the element have geometry data?
Dim geomElem As Autodesk.Revit.DB.GeometryElement = elem.Geometry(opt)
If geomElem Is Nothing Then
MsgBox(str & "no data")
Return
End If
str = GeometryElementToString(geomElem)
MsgBox(str)
End Sub
'------------------------------------------------------------------
Public Shared Function GeometryElementToString( _
ByVal geomElem As Autodesk.Revit.DB.GeometryElement) As String
'Dim geomObjs As Autodesk.Revit.DB.GeometryObjectArray = geomElem.Objects
Dim Objects As IEnumerator(Of GeometryObject) = geomElem.GetEnumerator()
Dim geomObj As GeometryObject
Dim objectsSize As Integer = 0
Do While Objects.MoveNext
objectsSize = objectsSize + 1
Loop
Dim str As String = ""
str = str & "Total number of GeometryObject: " & objectsSize & vbCr
Objects.Reset()
'For Each geomObj In geomObjs
Do While Objects.MoveNext
geomObj = Objects.Current
If TypeOf geomObj Is Autodesk.Revit.DB.Solid Then ' ex. wall
Dim solid As Autodesk.Revit.DB.Solid = geomObj
str = str & GeometrySolidToString(solid)
ElseIf TypeOf geomObj Is Autodesk.Revit.DB.GeometryInstance Then ' ex. door/window
str = str & " -- Geometry.Instance -- " & vbCr
Dim geomInstance As Autodesk.Revit.DB.GeometryInstance = geomObj
Dim geoElem As Autodesk.Revit.DB.GeometryElement = geomInstance.SymbolGeometry()
str = str & GeometryElementToString(geoElem)
ElseIf TypeOf geomObj Is Autodesk.Revit.DB.Curve Then ' ex.
Dim curv As Autodesk.Revit.DB.Curve = geomObj
str = str & GeometryCurveToString(curv)
ElseIf TypeOf geomObj Is Autodesk.Revit.DB.Mesh Then ' ex.
Dim mesh As Autodesk.Revit.DB.Mesh = geomObj
str = str & GeometryMeshToString(mesh)
Else
str = str & " *** unkown geometry type" & geomObj.GetType.ToString
End If
Loop
Return str
End Function
'------------------------------------------------------------------
Public Shared Function GeometrySolidToString(ByVal solid _
As Autodesk.Revit.DB.Solid) As String
Dim str As String = " -- Geometry.Solid -- " + vbCr
Dim faces As Autodesk.Revit.DB.FaceArray = solid.Faces
str = str + "Total number of faces: " + faces.Size.ToString & vbCr
Dim face As Autodesk.Revit.DB.Face
Dim iface As Integer = 0
For Each face In faces
iface = iface + 1
str = str + "Face " & iface & "/" & faces.Size.ToString & vbCr
Dim edgeLoops As Autodesk.Revit.DB.EdgeArrayArray = face.EdgeLoops
Dim iLoop As Integer = 0
Dim edgeLoop As Autodesk.Revit.DB.EdgeArray
For Each edgeLoop In edgeLoops
iLoop = iLoop + 1
str = str & " EdgeLoop[" & iLoop.ToString & "] "
Dim edge As Autodesk.Revit.DB.Edge
For Each edge In edgeLoop
Dim pts As List(Of Autodesk.Revit.DB.XYZ)
pts = edge.Tessellate
str = str + PointArrayToString(pts)
Next
str = str & vbCr
Next
Next
Return str
End Function
'------------------------------------------------------------------
Public Shared Function GeometryCurveToString(ByVal curv As Autodesk.Revit.DB.Curve) _
As String
Dim str As String = " -- Geometry.Curve -- " + vbCr
Dim pts As List(Of Autodesk.Revit.DB.XYZ) = curv.Tessellate
str = str + PointArrayToString(pts)
Return str
End Function
'------------------------------------------------------------------
Public Shared Function GeometryMeshToString(ByVal mesh As Autodesk.Revit.DB.Mesh) _
As String
Dim str As String = " -- Geometry.Mesh -- " + vbCr
Dim pts As List(Of Autodesk.Revit.DB.XYZ)
pts = mesh.Vertices
str = str + PointArrayToString(pts)
Return str
End Function
Public Shared Function PointArrayToString(ByVal pts As List(Of Autodesk.Revit.DB.XYZ)) _
As String
Dim str As String = ""
Dim pt As Autodesk.Revit.DB.XYZ
For Each pt In pts
str = str + PointToString(pt)
Next
Return str
End Function
Public Shared Function PointToString(ByVal pt As Autodesk.Revit.DB.XYZ) As String
Dim str As String = "(" & pt.X.ToString("F3") & ", " & pt.Y.ToString("F3") & ", " _
& pt.Z.ToString("F3") & ") "
Return str
End Function
'============================================================================
'
' List location of the given element.
'
'============================================================================
Public Shared Sub ListLocation(ByVal elem As Autodesk.Revit.DB.Element)
' header
Dim str As String = " -- Location -- " & vbCr
' do we have a location data?
Dim loc As Location = elem.Location
If (loc Is Nothing) Then
MsgBox(str & "no data")
Return
End If
' we have location data. show it.
' location type is LocationCurve
If TypeOf loc Is LocationCurve Then
Dim crv As LocationCurve = loc
Dim startPt As Autodesk.Revit.DB.XYZ = crv.Curve.GetEndPoint(0)
Dim endPt As Autodesk.Revit.DB.XYZ = crv.Curve.GetEndPoint(1)
str = str & "Start Point: " & startPt.X & ", " & startPt.Y & ", " & startPt.Z & vbCr
str = str & "End Point: " & endPt.X & ", " & endPt.Y & ", " & endPt.Z
' location type is LocationPoint
ElseIf TypeOf loc Is LocationPoint Then
Dim locPt As LocationPoint = loc
Dim pt As Autodesk.Revit.DB.XYZ = locPt.Point
str = str & "Point: " & pt.X & ", " & pt.Y & ", " & pt.Z & vbCr
' Others
Else
str = str & "this is not LocationCurve nor LocationPoint"
End If
' show it.
MsgBox(str)
End Sub
End Class
@@ -0,0 +1,109 @@
'
' (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.
'
'
' RevitCommands - Revit API custom command samplers.
'
Imports System
Imports Autodesk
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI
' Selection Set - shows the access to the current selection set.
'
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)> _
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)> _
<Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)> _
Public Class RvtCmd_Selection
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
Dim application As Autodesk.Revit.UI.UIApplication = commandData.Application
' get hold of a revit document.
'
Dim rvtDoc As UIDocument = application.ActiveUIDocument
' get a list of selected elements.
'
Dim selSet As Autodesk.Revit.DB.ElementSet = New Autodesk.Revit.DB.ElementSet
Dim elementId As Autodesk.Revit.DB.ElementId
For Each elementId In rvtDoc.Selection.GetElementIds()
selSet.Insert(rvtDoc.Document.GetElement(elementId))
Next
' how many did you get?
'
If selSet.IsEmpty Then
MsgBox("Nothing selected - exiting command!")
Return Autodesk.Revit.UI.Result.Failed
End If
MsgBox("The number of selected elements = " & selSet.Size & vbCrLf)
' look at each of them.
Dim str As String = ""
Dim i As Integer
Dim elem As Autodesk.Revit.DB.Element
For Each elem In selSet
Dim catName As String = "no category"
If Not (elem.Category Is Nothing) Then
catName = elem.Category.Name
End If
i += 1
str += " " & i.ToString & _
". id=" & elem.Id.IntegerValue.ToString & _
" Cat=" & catName & _
" Type=" & elem.Name & vbCrLf
Next
MsgBox(str)
Return Autodesk.Revit.UI.Result.Succeeded
End Function
End Class
@@ -0,0 +1,99 @@
'
' (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.
'
'
' ShowElementData - displays a few data of selected elements.
'
Imports System
Imports Autodesk
Imports Autodesk.Revit.DB
'
' Show Element Data - show a few data of selected elements.
'
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)> _
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)> _
<Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)> _
Public Class RvtCmd_ShowElementData
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
Dim rvtApp As Autodesk.Revit.UI.UIApplication = commandData.Application
' get a list of selected elements.
Dim selSet As Autodesk.Revit.DB.ElementSet = New Autodesk.Revit.DB.ElementSet
Dim elementId As Autodesk.Revit.DB.ElementId
For Each elementId In rvtApp.ActiveUIDocument.Selection.GetElementIds()
selSet.Insert(rvtApp.ActiveUIDocument.Document.GetElement(elementId))
Next
' how many did you get?
MsgBox("The number of selected elements:" & selSet.Size)
' look at each of them.
Dim elem As Autodesk.Revit.DB.Element
For Each elem In selSet
' show the type.
MsgBox(elem.GetType.ToString)
' location
RvtUtils.ListLocation(elem)
' geometry
RvtUtils.ListGeometry(rvtApp.Application, elem)
' parameters
RvtUtils.ListParameters(elem)
Next
' finishing up.
Return Autodesk.Revit.UI.Result.Succeeded
End Function
End Class