Skip to content

Commit

Permalink
added VB.NET and migrated to Revit 2013
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Tammik committed Aug 21, 2015
1 parent a60f458 commit 4deeb90
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 18 deletions.
29 changes: 29 additions & 0 deletions cs/Command.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
#endregion

namespace $safeprojectname$
Expand All @@ -22,6 +24,33 @@ public Result Execute(
Application app = uiapp.Application;
Document doc = uidoc.Document;

// Access current selection

Selection sel = uidoc.Selection;

// Retrieve elements from database

FilteredElementCollector col
= new FilteredElementCollector( doc )
.WhereElementIsNotElementType()
.OfCategory( BuiltInCategory.INVALID )
.OfClass( typeof( Wall ) );

// Filtered element collector is iterable

foreach( Element e in col )
{
Debug.Print( e.Name );
}

// Modify document within a transaction

using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Transaction Name" );
tx.Commit();
}

return Result.Succeeded;
}
}
Expand Down
4 changes: 2 additions & 2 deletions cs/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
[assembly: AssemblyDescription( "Revit Add-In Description" )]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Autodesk Inc.")]
[assembly: AssemblyProduct( "Revit Add-In Template Application" )]
[assembly: AssemblyCopyright( "Copyright 2011 © Jeremy Tammik Autodesk Inc." )]
[assembly: AssemblyProduct( "Revit Add-In Wizard Template Application" )]
[assembly: AssemblyCopyright( "Copyright 2012 © Jeremy Tammik Autodesk Inc." )]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
26 changes: 12 additions & 14 deletions cs/TemplateRevitCs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>$safeprojectname$</RootNamespace>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -21,7 +21,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<StartAction>Program</StartAction>
<StartProgram>$(ProgramFiles)\Autodesk\Revit Architecture 2012\Program\Revit.exe</StartProgram>
<StartProgram>$(ProgramFiles)\Autodesk\Revit 2013\Program\Revit.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -31,17 +31,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<StartAction>Program</StartAction>
<StartProgram>$(ProgramFiles)\Autodesk\Revit Architecture 2012\Program\Revit.exe</StartProgram>
<StartProgram>$(ProgramFiles)\Autodesk\Revit 2013\Program\Revit.exe</StartProgram>
</PropertyGroup>
<ItemGroup>
<Reference Include="RevitAPI, Version=2012.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProgramFiles)\Autodesk\Revit Architecture 2012\Program\RevitAPI.dll</HintPath>
<Reference Include="RevitAPI">
<HintPath>$(ProgramFiles)\Autodesk\Revit 2013\Program\RevitAPI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPIUI, Version=2012.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(ProgramFiles)\Autodesk\Revit Architecture 2012\Program\RevitAPIUI.dll</HintPath>
<Reference Include="RevitAPIUI">
<HintPath>$(ProgramFiles)\Autodesk\Revit 2013\Program\RevitAPIUI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -63,11 +61,11 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterClean">
<Delete Files="$(AppData)\Autodesk\REVIT\Addins\2012\$projectname$.addin" />
<Delete Files="$(AppData)\Autodesk\REVIT\Addins\2012\$projectname$.dll" />
<Delete Files="$(AppData)\Autodesk\REVIT\Addins\2013\$projectname$.addin" />
<Delete Files="$(AppData)\Autodesk\REVIT\Addins\2013\$projectname$.dll" />
</Target>
<PropertyGroup>
<PostBuildEvent>copy "$(ProjectDir)$projectname$.addin" "$(AppData)\Autodesk\REVIT\Addins\2012"
copy "$destinationdirectory$\bin\debug\$projectname$.dll" "$(AppData)\Autodesk\REVIT\Addins\2012"</PostBuildEvent>
<PostBuildEvent>copy "$(ProjectDir)$projectname$.addin" "$(AppData)\Autodesk\REVIT\Addins\2013"
copy "$destinationdirectory$\bin\debug\$projectname$.dll" "$(AppData)\Autodesk\REVIT\Addins\2013"</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions cs/TemplateRevitCs.vstemplate
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<VSTemplate Type="Project" Version="2.0.0"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>Revit Architecture 2012 Addin</Name>
<Description>A basic template project for Revit Architecture 2012 Addin</Description>
<Name>Revit 2013 Addin</Name>
<Description>Class library template for a Revit 2013 add-in project</Description>
<Icon>TemplateIcon.ico</Icon>
<ProjectType>CSharp</ProjectType>
<CreateNewFolder>true</CreateNewFolder>
Expand Down
51 changes: 51 additions & 0 deletions vb/AdskApplication.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#Region "Imported Namespaces"
Imports Autodesk.Revit.ApplicationServices
Imports Autodesk.Revit.Attributes
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI
#End Region

Class AdskApplication
Implements IExternalApplication
''' <summary>
''' This method is called when Revit starts up before a
''' document or default template is actually loaded.
''' </summary>
''' <param name="app">An object passed to the external
''' application which contains the controlled application.</param>
''' <returns>Return the status of the external application.
''' A result of Succeeded means that the external application started successfully.
''' Cancelled can be used to signify a problem. If so, Revit informs the user that
''' the external application failed to load and releases the internal reference.
''' </returns>
Public Function OnStartup(
ByVal app As UIControlledApplication) _
As Result Implements IExternalApplication.OnStartup

'TODO: Add your code here

'Must return some code
Return Result.Succeeded
End Function

''' <summary>
''' This method is called when Revit is about to exit.
''' All documents are closed before this method is called.
''' </summary>
''' <param name="app">An object passed to the external
''' application which contains the controlled application.</param>
''' <returns>Return the status of the external application.
''' A result of Succeeded means that the external application successfully shutdown.
''' Cancelled can be used to signify that the user cancelled the external operation
''' at some point. If false is returned then the Revit user should be warned of the
''' failure of the external application to shut down correctly.</returns>
Public Function OnShutdown(
ByVal app As UIControlledApplication) _
As Result Implements IExternalApplication.OnShutdown

'TODO: Add your code here

'Must return some code
Return Result.Succeeded
End Function
End Class
40 changes: 40 additions & 0 deletions vb/AdskCommand.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#Region "Imported Namespaces"
Imports System
Imports System.Collections.Generic
Imports Autodesk.Revit.ApplicationServices
Imports Autodesk.Revit.Attributes
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.UI.Selection
#End Region

<Transaction(TransactionMode.Manual)>
Public Class AdskCommand
Implements IExternalCommand

''' <summary>
''' The one and only method required by the IExternalCommand interface, the main entry point for every external command.
''' </summary>
''' <param name="commandData">Input argument providing access to the Revit application, its documents and their properties.</param>
''' <param name="message">Return argument to display a message to the user in case of error if Result is not Succeeded.</param>
''' <param name="elements">Return argument to highlight elements on the graphics screen if Result is not Succeeded.</param>
''' <returns>Cancelled, Failed or Succeeded Result code.</returns>
Public Function Execute(
ByVal commandData As ExternalCommandData,
ByRef message As String,
ByVal elements As ElementSet) _
As Result Implements IExternalCommand.Execute

Dim uiapp As UIApplication = commandData.Application
Dim uidoc As UIDocument = uiapp.ActiveUIDocument
Dim app As Application = uiapp.Application
Dim doc As Document = uidoc.Document

Dim sel As Selection = uidoc.Selection

'TODO: Add your code here

'Must return some code
Return Result.Succeeded
End Function
End Class
35 changes: 35 additions & 0 deletions vb/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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("RevitAddinTemplateVb")>
<Assembly: AssemblyDescription("Revit Addin Template for VB")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("RevitAddinTemplateVb")>
<Assembly: AssemblyCopyright("Copyright © 2012 by Jeremy Tammik, Autodesk Inc.")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(False)>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("33e55dac-e8b7-4fb7-80fd-5ce4e6950fb2")>

' 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.*")>

<Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyFileVersion("1.0.*")>
20 changes: 20 additions & 0 deletions vb/RegisterAddin.addin
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="ansi"?>
<RevitAddIns>
<AddIn Type="Command">
<Text>Command $projectname$</Text>
<Description>Some description for $projectname$</Description>
<Assembly>$projectname$.dll</Assembly>
<FullClassName>$safeprojectname$.AdskCommand</FullClassName>
<ClientId>$guid1$</ClientId>
<VendorId>TBC_</VendorId>
<VendorDescription>The Building Coder, http://thebuildingcoder.typepad.com</VendorDescription>
</AddIn>
<AddIn Type="Application">
<Name>Application $projectname$</Name>
<Assembly>$projectname$.dll</Assembly>
<ClientId>$guid2$</ClientId>
<FullClassName>$safeprojectname$.AdskApplication</FullClassName>
<VendorId>TBC_</VendorId>
<VendorDescription>The Building Coder, http://thebuildingcoder.typepad.com</VendorDescription>
</AddIn>
</RevitAddIns>
Binary file added vb/TemplateIcon.ico
Binary file not shown.
90 changes: 90 additions & 0 deletions vb/TemplateRevitVb.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion></ProductVersion>
<SchemaVersion></SchemaVersion>
<ProjectGuid>{00000000-0000-0000-0000-000000000000}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>$safeprojectname$</RootNamespace>
<FileAlignment>512</FileAlignment>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<OptionExplicit>On</OptionExplicit>
<OptionCompare>Binary</OptionCompare>
<OptionStrict>Off</OptionStrict>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile></DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<StartAction>Program</StartAction>
<StartProgram>$(ProgramFiles)\Autodesk\Revit 2013\Program\Revit.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile></DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<StartAction>Program</StartAction>
<StartProgram>$(ProgramFiles)\Autodesk\Revit 2013\Program\Revit.exe</StartProgram>
</PropertyGroup>
<ItemGroup>
<Reference Include="RevitAPI">
<HintPath>$(ProgramFiles)\Autodesk\Revit 2013\Program\RevitAPI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPIUI">
<HintPath>$(ProgramFiles)\Autodesk\Revit 2013\Program\RevitAPIUI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Import Include="Autodesk.Revit.ApplicationServices" />
<Import Include="Autodesk.Revit.Attributes" />
<Import Include="Autodesk.Revit.DB" />
<Import Include="Autodesk.Revit.UI" />
<Import Include="Autodesk.Revit.UI.Selection" />
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="AdskApplication.vb" />
<Compile Include="AdskCommand.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
</ItemGroup>
<ItemGroup>
<None Include="$projectname$.addin" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Target Name="AfterClean">
<Delete Files="$(AppData)\Autodesk\REVIT\Addins\2013\$projectname$.addin" />
<Delete Files="$(AppData)\Autodesk\REVIT\Addins\2013\$projectname$.dll" />
</Target>
<PropertyGroup>
<PostBuildEvent>copy "$(ProjectDir)$projectname$.addin" "$(AppData)\Autodesk\REVIT\Addins\2013"
copy "$(ProjectDir)bin\debug\$projectname$.dll" "$(AppData)\Autodesk\REVIT\Addins\2013"
</PostBuildEvent>
</PropertyGroup>
</Project>
22 changes: 22 additions & 0 deletions vb/TemplateRevitVb.vstemplate
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<VSTemplate Type="Project" Version="2.0.0"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>Revit 2013 Addin</Name>
<Description>Class library template for a Revit 2013 add-in project</Description>
<Icon>TemplateIcon.ico</Icon>
<ProjectType>VisualBasic</ProjectType>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>RevitAddin</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
</TemplateData>
<TemplateContent>
<Project ReplaceParameters="true" File="TemplateRevitVB.vbproj">
<ProjectItem ReplaceParameters="true" TargetFileName="$projectname$.addin">RegisterAddin.addin</ProjectItem>
<ProjectItem ReplaceParameters="true">AdskApplication.vb</ProjectItem>
<ProjectItem ReplaceParameters="true">AdskCommand.vb</ProjectItem>
<ProjectItem ReplaceParameters="true">My Project\AssemblyInfo.vb</ProjectItem>
</Project>
</TemplateContent>
</VSTemplate>

0 comments on commit 4deeb90

Please sign in to comment.