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,412 @@
//
// (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.
//
using System;
using System.Collections.Generic;
using Autodesk.Revit;
using Autodesk.Revit.Creation;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
namespace Revit.SDK.Samples.CreateAirHandler.CS
{
/// <summary>
/// Create one air handler and add connectors.
/// </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
{
/// <summary>
/// The revit application
/// </summary>
private static Autodesk.Revit.ApplicationServices.Application m_application;
/// <summary>
/// The current document of the application
/// </summary>
private static Autodesk.Revit.DB.Document m_document;
/// <summary>
/// the factory to creaate extrusions and connectors
/// </summary>
private FamilyItemFactory f;
/// <summary>
/// the extrusion array
/// </summary>
private Extrusion[] extrusions;
/// <summary>
/// The list of all the elements to be combined in the air handler system
/// </summary>
private CombinableElementArray m_combineElements;
#region Data used to create extrusions and connectors
/// <summary>
/// Data to create extrusions and connectors
/// </summary>
private Autodesk.Revit.DB.XYZ[,] profileData = new Autodesk.Revit.DB.XYZ[5, 4]
{
// In Array 0 to 2, the data is the points that defines the edges of the profile
{
new Autodesk.Revit.DB.XYZ (-17.28, -0.53, 0.9),
new Autodesk.Revit.DB.XYZ (-17.28, 11, 0.9),
new Autodesk.Revit.DB.XYZ (-0.57, 11, 0.9),
new Autodesk.Revit.DB.XYZ (-0.57, -0.53, 0.9)
},
{
new Autodesk.Revit.DB.XYZ (-0.57, 7, 6.58),
new Autodesk.Revit.DB.XYZ (-0.57, 7, 3),
new Autodesk.Revit.DB.XYZ (-0.57, 3.6, 3),
new Autodesk.Revit.DB.XYZ (-0.57, 3.6, 6.58)
},
{
new Autodesk.Revit.DB.XYZ (-17.28, -0.073, 7.17),
new Autodesk.Revit.DB.XYZ (-17.28, 10.76, 7.17),
new Autodesk.Revit.DB.XYZ (-17.28, 10.76, 3.58),
new Autodesk.Revit.DB.XYZ (-17.28, -0.073, 3.58)
},
// In Array 3 and 4, the data is the normal and origin of the plane of the arc profile
{
new Autodesk.Revit.DB.XYZ (0, -1, 0),
new Autodesk.Revit.DB.XYZ (-9, 0.53, 7.17),
null,
null
},
{
new Autodesk.Revit.DB.XYZ (0, -1, 0),
new Autodesk.Revit.DB.XYZ (-8.24, 0.53, 0.67),
null,
null
}
};
/// <summary>
/// the normal and origin of the sketch plane
/// </summary>
private Autodesk.Revit.DB.XYZ[,] sketchPlaneData = new Autodesk.Revit.DB.XYZ[5, 2]
{
{new Autodesk.Revit.DB.XYZ (0, 0, 1), new Autodesk.Revit.DB.XYZ (0, 0, 0.9)},
{new Autodesk.Revit.DB.XYZ (1, 0, 0), new Autodesk.Revit.DB.XYZ (-0.57, 0, 0)},
{new Autodesk.Revit.DB.XYZ (-1, 0, 0), new Autodesk.Revit.DB.XYZ (-17.28, 0, 0)},
{new Autodesk.Revit.DB.XYZ (0, -1, 0), new Autodesk.Revit.DB.XYZ (0, 0.53, 0)},
{new Autodesk.Revit.DB.XYZ (0, -1, 0), new Autodesk.Revit.DB.XYZ (0, 0.53, 0)}
};
/// <summary>
/// the start and end offsets of the extrusion
/// </summary>
private double[,] extrusionOffsets = new double[5, 2]
{
{-0.9, 6.77},
{0, -0.18},
{0, -0.08},
{1, 1.15},
{1, 1.15}
};
/// <summary>
/// whether the extrusion is solid
/// </summary>
private bool[] isSolid = new bool[5] { true, false, false, true, true };
/// <summary>
/// the radius of the arc profile
/// </summary>
private double arcRadius = 0.17;
/// <summary>
/// the height and width of the connector
/// </summary>
private double[,] connectorDimensions = new double[2, 2]
{
{3.58, 3.4},
{3.59, 10.833}
};
/// <summary>
/// the flow of the connector
/// </summary>
private double flow = 547;
/// <summary>
/// Transaction of ExternalCommand
/// </summary>
private Transaction m_transaction;
#endregion
#region IExternalCommand 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,
ElementSet elements)
{
// set out default result to failure.
Autodesk.Revit.UI.Result retRes = Autodesk.Revit.UI.Result.Failed;
m_application = commandData.Application.Application;
m_document = commandData.Application.ActiveUIDocument.Document;
f = m_document.FamilyCreate;
extrusions = new Extrusion[5];
m_combineElements = new CombinableElementArray();
m_transaction = new Transaction(m_document, "External Tool");
m_transaction.Start();
if (m_document.OwnerFamily.FamilyCategory.Name !=
m_document.Settings.Categories.get_Item(BuiltInCategory.OST_MechanicalEquipment).Name) // FamilyCategory.Name is not "Mechanical Equipment".
{
message = "Please make sure you opened a template of Mechanical Equipment.";
return retRes;
}
try
{
CreateExtrusions();
m_document.Regenerate();
CreateConnectors();
m_document.Regenerate();
m_document.CombineElements(m_combineElements);
m_document.Regenerate();
}
catch (Exception x)
{
m_transaction.RollBack();
message = x.Message;
return retRes;
}
m_transaction.Commit();
retRes = Autodesk.Revit.UI.Result.Succeeded;
return retRes;
}
#endregion
/// <summary>
/// get all planar faces of an extrusion
/// </summary>
/// <param name="extrusion">the extrusion to read</param>
/// <returns>a list of all planar faces of the extrusion</returns>
public List<PlanarFace> GetPlanarFaces(Extrusion extrusion)
{
// the option to get geometry elements
Options m_geoOptions = m_application.Create.NewGeometryOptions();
m_geoOptions.View = m_document.ActiveView;
m_geoOptions.ComputeReferences = true;
// get the planar faces
List<PlanarFace> m_planarFaces = new List<PlanarFace>();
Autodesk.Revit.DB.GeometryElement geoElement = extrusion.get_Geometry(m_geoOptions);
//foreach (GeometryObject geoObject in geoElement.Objects)
IEnumerator<GeometryObject> Objects = geoElement.GetEnumerator();
while (Objects.MoveNext())
{
GeometryObject geoObject = Objects.Current;
Solid geoSolid = geoObject as Solid;
if (null == geoSolid)
{
continue;
}
foreach (Face geoFace in geoSolid.Faces)
{
if (geoFace is PlanarFace)
{
m_planarFaces.Add(geoFace as PlanarFace);
}
}
}
return m_planarFaces;
}
/// <summary>
/// create the extrusions of the air handler system
/// </summary>
private void CreateExtrusions()
{
Autodesk.Revit.Creation.Application app = m_application.Create;
CurveArray curves = null;
CurveArrArray profile = null;
Plane plane = null;
SketchPlane sketchPlane = null;
#region Create the cuboid extrusions
for (int i = 0; i <= 2; ++i)
{
// create the profile
curves = app.NewCurveArray();
curves.Append(Line.CreateBound(profileData[i, 0], profileData[i, 1]));
curves.Append(Line.CreateBound(profileData[i, 1], profileData[i, 2]));
curves.Append(Line.CreateBound(profileData[i, 2], profileData[i, 3]));
curves.Append(Line.CreateBound(profileData[i, 3], profileData[i, 0]));
profile = app.NewCurveArrArray();
profile.Append(curves);
// create the sketch plane
plane = Plane.CreateByNormalAndOrigin(sketchPlaneData[i, 0], sketchPlaneData[i, 1]);
sketchPlane = SketchPlane.Create(m_document, plane);
// create the extrusion
extrusions[i] = f.NewExtrusion(isSolid[i], profile, sketchPlane,
extrusionOffsets[i, 1]);
extrusions[i].StartOffset = extrusionOffsets[i, 0];
m_combineElements.Append(extrusions[i]);
}
#endregion
#region Create the round extrusions
for (int i = 3; i <= 4; ++i)
{
// create the profile
profile = app.NewCurveArrArray();
curves = app.NewCurveArray();
plane = Plane.CreateByNormalAndOrigin(profileData[i, 0], profileData[i, 1]);
curves.Append(Arc.Create(plane, arcRadius, 0, Math.PI * 2));
profile.Append(curves);
// create the sketch plane
plane = Plane.CreateByNormalAndOrigin(sketchPlaneData[i, 0], sketchPlaneData[i, 1]);
sketchPlane = SketchPlane.Create(m_document, plane);
// create the extrusion
extrusions[i] = f.NewExtrusion(isSolid[i], profile, sketchPlane,
extrusionOffsets[i, 1]);
extrusions[i].StartOffset = extrusionOffsets[i, 0];
m_combineElements.Append(extrusions[i]);
}
#endregion
}
/// <summary>
/// create the connectors on the extrusions
/// </summary>
private void CreateConnectors()
{
List<PlanarFace> m_planarFaces = null;
Parameter param = null;
#region Create the Supply Air duct connector
// get the planar faces of extrusion1
m_planarFaces = GetPlanarFaces(extrusions[1]);
// create the Supply Air duct connector
//DuctConnector connSupplyAir = f.NewDuctConnector(m_planarFaces[0].Reference,
// DuctSystemType.SupplyAir);
ConnectorElement connSupplyAir = ConnectorElement.CreateDuctConnector(m_document, DuctSystemType.SupplyAir, ConnectorProfileType.Rectangular, m_planarFaces[0].Reference);
param = connSupplyAir.get_Parameter(BuiltInParameter.CONNECTOR_HEIGHT);
param.Set(connectorDimensions[0, 0]);
param = connSupplyAir.get_Parameter(BuiltInParameter.CONNECTOR_WIDTH);
param.Set(connectorDimensions[0, 1]);
param = connSupplyAir.get_Parameter(BuiltInParameter.RBS_DUCT_FLOW_DIRECTION_PARAM);
param.Set(2);
param = connSupplyAir.get_Parameter(BuiltInParameter.RBS_DUCT_FLOW_CONFIGURATION_PARAM);
param.Set(1);
param = connSupplyAir.get_Parameter(BuiltInParameter.RBS_DUCT_FLOW_PARAM);
param.Set(flow);
#endregion
#region Create the Return Air duct connector
// get the planar faces of extrusion2
m_planarFaces = GetPlanarFaces(extrusions[2]);
// create the Return Air duct connector
//DuctConnector connReturnAir = f.NewDuctConnector(m_planarFaces[0].Reference,
// DuctSystemType.ReturnAir);
ConnectorElement connReturnAir = ConnectorElement.CreateDuctConnector(m_document, DuctSystemType.ReturnAir, ConnectorProfileType.Rectangular, m_planarFaces[0].Reference);
param = connReturnAir.get_Parameter(BuiltInParameter.CONNECTOR_HEIGHT);
param.Set(connectorDimensions[1, 0]);
param = connReturnAir.get_Parameter(BuiltInParameter.CONNECTOR_WIDTH);
param.Set(connectorDimensions[1, 1]);
param = connReturnAir.get_Parameter(BuiltInParameter.RBS_DUCT_FLOW_DIRECTION_PARAM);
param.Set(1);
param =
connReturnAir.get_Parameter(BuiltInParameter.RBS_DUCT_FLOW_CONFIGURATION_PARAM);
param.Set(1);
param = connReturnAir.get_Parameter(BuiltInParameter.RBS_DUCT_FLOW_PARAM);
param.Set(flow);
#endregion
#region Create the Supply Hydronic pipe connector
// get the planar faces of extrusion3
m_planarFaces = GetPlanarFaces(extrusions[3]);
// create the Hydronic Supply pipe connector
//PipeConnector connSupplyHydronic = f.NewPipeConnector(m_planarFaces[0].Reference,
// PipeSystemType.SupplyHydronic);
ConnectorElement connSupplyHydronic = ConnectorElement.CreatePipeConnector(m_document, PipeSystemType.SupplyHydronic, m_planarFaces[0].Reference);
param = connSupplyHydronic.get_Parameter(BuiltInParameter.CONNECTOR_RADIUS);
param.Set(arcRadius);
param =
connSupplyHydronic.get_Parameter(BuiltInParameter.RBS_PIPE_FLOW_DIRECTION_PARAM);
param.Set(2);
#endregion
#region Create the Return Hydronic pipe connector
// get the planar faces of extrusion4
m_planarFaces = GetPlanarFaces(extrusions[4]);
// create the Hydronic Return pipe connector
//PipeConnector connReturnHydronic = f.NewPipeConnector(m_planarFaces[0].Reference,
// PipeSystemType.ReturnHydronic);
ConnectorElement connReturnHydronic = ConnectorElement.CreatePipeConnector(m_document, PipeSystemType.ReturnHydronic, m_planarFaces[0].Reference);
param = connReturnHydronic.get_Parameter(BuiltInParameter.CONNECTOR_RADIUS);
param.Set(arcRadius);
param =
connReturnHydronic.get_Parameter(BuiltInParameter.RBS_PIPE_FLOW_DIRECTION_PARAM);
param.Set(1);
#endregion
}
}
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>CreateAirHandler.dll</Assembly>
<ClientId>624e832a-d412-4365-8060-5adb9e921128</ClientId>
<FullClassName>Revit.SDK.Samples.CreateAirHandler.CS.Command</FullClassName>
<Text>Create Air Handler</Text>
<Description>Create one air handler and add connectors.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,84 @@
<?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>{3251A8F4-57C3-4D4E-B5C8-6E7AC7D4E17A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CreateAirHandler</RootNamespace>
<AssemblyName>CreateAirHandler</AssemblyName>
<FileAlignment>512</FileAlignment>
<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>
</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.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,36 @@
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("CreateAirHandler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Autodesk, Inc.")]
[assembly: AssemblyProduct("CreateAirHandler")]
[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("dc6759c3-7d5d-460e-8a8f-635e336daf12")]
// 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.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]