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
+409
View File
@@ -0,0 +1,409 @@
//
// (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 notify appears in all copies and
// that both that copyright notify and the limited warranty and
// restricted rights notify 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.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
namespace Revit.SDK.Samples.ErrorHandling.CS
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand and IExternalApplication
/// </summary>
[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 : IExternalCommand, IExternalApplication
{
/// <summary>
/// The failure definition id for warning
/// </summary>
public static FailureDefinitionId m_idWarning;
/// <summary>
/// The failure definition id for error
/// </summary>
public static FailureDefinitionId m_idError;
/// <summary>
/// The failure definition for warning
/// </summary>
private FailureDefinition m_fdWarning;
/// <summary>
/// The failure definition for error
/// </summary>
private FailureDefinition m_fdError;
/// <summary>
/// The Revit application
/// </summary>
private Application m_revitApp;
/// <summary>
/// The active document
/// </summary>
private Document m_doc;
#region IExternalApplication Members
/// <summary>
/// Implements the OnShutdown event
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
/// <summary>
/// Implements the OnStartup event
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
public Result OnStartup(UIControlledApplication application)
{
try
{
// Create failure definition Ids
Guid guid1 = new Guid("0C3F66B5-3E26-4d24-A228-7A8358C76D39");
Guid guid2 = new Guid("93382A45-89A9-4cfe-8B94-E0B0D9542D34");
Guid guid3 = new Guid("A16D08E2-7D06-4bca-96B0-C4E4CC0512F8");
m_idWarning = new FailureDefinitionId(guid1);
m_idError = new FailureDefinitionId(guid2);
// Create failure definitions and add resolutions
m_fdWarning = FailureDefinition.CreateFailureDefinition(m_idWarning, FailureSeverity.Warning, "I am the warning.");
m_fdError = FailureDefinition.CreateFailureDefinition(m_idError, FailureSeverity.Error, "I am the error");
m_fdWarning.AddResolutionType(FailureResolutionType.MoveElements, "MoveElements", typeof(DeleteElements));
m_fdWarning.AddResolutionType(FailureResolutionType.DeleteElements, "DeleteElements", typeof(DeleteElements));
m_fdWarning.SetDefaultResolutionType(FailureResolutionType.DeleteElements);
m_fdError.AddResolutionType(FailureResolutionType.DetachElements, "DetachElements", typeof(DeleteElements));
m_fdError.AddResolutionType(FailureResolutionType.DeleteElements, "DeleteElements", typeof(DeleteElements));
m_fdError.SetDefaultResolutionType(FailureResolutionType.DeleteElements);
}
catch (System.Exception)
{
return Result.Failed;
}
return Result.Succeeded;
}
#endregion
#region IExternalApplication Members
/// <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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, Autodesk.Revit.DB.ElementSet elements)
{
m_revitApp = commandData.Application.Application;
m_doc = commandData.Application.ActiveUIDocument.Document;
Level level1 = GetLevel();
if (level1 == null)
{
throw new Exception("[ERROR] Failed to get level 1");
}
try
{
//
// Post a warning and resolve it in FailurePreproccessor
try
{
Transaction transaction = new Transaction(m_doc, "Warning_FailurePreproccessor");
FailureHandlingOptions options = transaction.GetFailureHandlingOptions();
FailurePreproccessor preproccessor = new FailurePreproccessor();
options.SetFailuresPreprocessor(preproccessor);
transaction.SetFailureHandlingOptions(options);
transaction.Start();
FailureMessage fm = new FailureMessage(m_idWarning);
m_doc.PostFailure(fm);
transaction.Commit();
}
catch (System.Exception)
{
message = "Failed to commit transaction Warning_FailurePreproccessor";
return Result.Failed;
}
//
// Dismiss the overlapped wall warning in FailurePreproccessor
try
{
Transaction transaction = new Transaction(m_doc, "Warning_FailurePreproccessor_OverlappedWall");
FailureHandlingOptions options = transaction.GetFailureHandlingOptions();
FailurePreproccessor preproccessor = new FailurePreproccessor();
options.SetFailuresPreprocessor(preproccessor);
transaction.SetFailureHandlingOptions(options);
transaction.Start();
Line line = Line.CreateBound(new XYZ(-10, 0, 0), new XYZ(-20, 0, 0));
Wall wall1 = Wall.Create(m_doc, line, level1.Id, false);
Wall wall2 = Wall.Create(m_doc, line, level1.Id, false);
m_doc.Regenerate();
transaction.Commit();
}
catch (System.Exception)
{
message = "Failed to commit transaction Warning_FailurePreproccessor_OverlappedWall";
return Result.Failed;
}
//
// Post an error and resolve it in FailuresProcessingEvent
try
{
m_revitApp.FailuresProcessing += new EventHandler<Autodesk.Revit.DB.Events.FailuresProcessingEventArgs>(FailuresProcessing);
Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessingEvent");
transaction.Start();
Line line = Line.CreateBound(new XYZ(0, 10, 0), new XYZ(20, 10, 0));
Wall wall = Wall.Create(m_doc, line, level1.Id, false);
m_doc.Regenerate();
FailureMessage fm = new FailureMessage(m_idError);
FailureResolution fr = DeleteElements.Create(m_doc, wall.Id);
fm.AddResolution(FailureResolutionType.DeleteElements, fr);
m_doc.PostFailure(fm);
transaction.Commit();
}
catch (System.Exception)
{
message = "Failed to commit transaction Error_FailuresProcessingEvent";
return Result.Failed;
}
//
// Post an error and resolve it in FailuresProcessor
try
{
FailuresProcessor processor = new FailuresProcessor();
Application.RegisterFailuresProcessor(processor);
Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessor");
transaction.Start();
Line line = Line.CreateBound(new XYZ(0, 20, 0), new XYZ(20, 20, 0));
Wall wall = Wall.Create(m_doc, line, level1.Id, false);
m_doc.Regenerate();
FailureMessage fm = new FailureMessage(m_idError);
FailureResolution fr = DeleteElements.Create(m_doc, wall.Id);
fm.AddResolution(FailureResolutionType.DeleteElements, fr);
m_doc.PostFailure(fm);
transaction.Commit();
}
catch (System.Exception)
{
message = "Failed to commit transaction Error_FailuresProcessor";
return Result.Failed;
}
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
return Result.Succeeded;
}
/// <summary>
/// Implements the FailuresProcessing event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FailuresProcessing(object sender, Autodesk.Revit.DB.Events.FailuresProcessingEventArgs e)
{
FailuresAccessor failuresAccessor = e.GetFailuresAccessor();
//failuresAccessor
String transactionName = failuresAccessor.GetTransactionName();
IList<FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages();
if (fmas.Count == 0)
{
e.SetProcessingResult(FailureProcessingResult.Continue);
return;
}
if (transactionName.Equals("Error_FailuresProcessingEvent"))
{
foreach (FailureMessageAccessor fma in fmas)
{
FailureDefinitionId id = fma.GetFailureDefinitionId();
if (id == Command.m_idError)
{
failuresAccessor.ResolveFailure(fma);
}
}
e.SetProcessingResult(FailureProcessingResult.ProceedWithCommit);
return;
}
e.SetProcessingResult(FailureProcessingResult.Continue);
}
/// <summary>
/// Gets the level named "Level 1"
/// </summary>
/// <returns></returns>
private Level GetLevel()
{
Level level1 = null;
FilteredElementCollector collector = new FilteredElementCollector(m_doc);
ElementClassFilter filter = new ElementClassFilter(typeof(Level));
IList<Element> levels = collector.WherePasses(filter).ToElements();
foreach (Level level in levels)
{
if (level.Name.Equals("Level 1"))
{
level1 = level;
break;
}
}
return level1;
}
#endregion
}
/// <summary>
/// Implements the interface IFailuresPreprocessor
/// </summary>
public class FailurePreproccessor : IFailuresPreprocessor
{
/// <summary>
/// This method is called when there have been failures found at the end of a transaction and Revit is about to start processing them.
/// </summary>
/// <param name="failuresAccessor">The Interface class that provides access to the failure information. </param>
/// <returns></returns>
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages();
if (fmas.Count == 0)
{
return FailureProcessingResult.Continue;
}
String transactionName = failuresAccessor.GetTransactionName();
if (transactionName.Equals("Warning_FailurePreproccessor"))
{
foreach (FailureMessageAccessor fma in fmas)
{
FailureDefinitionId id = fma.GetFailureDefinitionId();
if (id == Command.m_idWarning)
{
failuresAccessor.DeleteWarning(fma);
}
}
return FailureProcessingResult.ProceedWithCommit;
}
else if (transactionName.Equals("Warning_FailurePreproccessor_OverlappedWall"))
{
foreach (FailureMessageAccessor fma in fmas)
{
FailureDefinitionId id = fma.GetFailureDefinitionId();
if (id == BuiltInFailures.OverlapFailures.WallsOverlap)
{
failuresAccessor.DeleteWarning(fma);
}
}
return FailureProcessingResult.ProceedWithCommit;
}
else
{
return FailureProcessingResult.Continue;
}
}
}
/// <summary>
/// Implements the interface IFailuresProcessor
/// </summary>
public class FailuresProcessor : IFailuresProcessor
{
/// <summary>
/// This method is being called in case of exception or document destruction to dismiss any possible pending failure UI that may have left on the screen
/// </summary>
/// <param name="document">Document for which pending failures processing UI should be dismissed </param>
public void Dismiss(Document document)
{
}
/// <summary>
/// Method that Revit will invoke to process failures at the end of transaction.
/// </summary>
/// <param name="failuresAccessor">Provides all necessary data to perform the resolution of failures.</param>
/// <returns></returns>
public FailureProcessingResult ProcessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> fmas = failuresAccessor.GetFailureMessages();
if (fmas.Count == 0)
{
return FailureProcessingResult.Continue;
}
String transactionName = failuresAccessor.GetTransactionName();
if (transactionName.Equals("Error_FailuresProcessor"))
{
foreach (FailureMessageAccessor fma in fmas)
{
FailureDefinitionId id = fma.GetFailureDefinitionId();
if (id == Command.m_idError)
{
failuresAccessor.ResolveFailure(fma);
}
}
return FailureProcessingResult.ProceedWithCommit;
}
else
{
return FailureProcessingResult.Continue;
}
}
}
}
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Application">
<Name>External Tool</Name>
<Assembly>ErrorHandling.dll</Assembly>
<ClientId>5173fedd-fdfd-4a52-8319-cb956bc3263e</ClientId>
<FullClassName>Revit.SDK.Samples.ErrorHandling.CS.Command</FullClassName>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
<AddIn Type="Command">
<Assembly>ErrorHandling.dll</Assembly>
<ClientId>931e878f-635f-4163-b9c8-fd2dc59a3f7c</ClientId>
<FullClassName>Revit.SDK.Samples.ErrorHandling.CS.Command</FullClassName>
<Text>ErrorHandling</Text>
<Description>Demonstrates how to use the error handling framework..</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{319AB620-9C6F-4F1B-9A9A-2543F4283AAA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ErrorHandling</RootNamespace>
<AssemblyName>ErrorHandling</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Command.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(SolutionDir)VSProps\SDKSamples.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<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,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using 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.
[assembly: AssemblyTitle("TransactionControl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TransactionControl")]
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc. 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("18f5d6d3-6f43-40cd-b274-b0f286625e08")]
// 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 Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]