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,58 @@
//
// (C) Copyright 2003-2013 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.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("QueryingResults")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Autodesk")]
[assembly: AssemblyProduct("QueryingResults")]
[assembly: AssemblyCopyright("Copyright © Autodesk 2012")]
[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("dd3d57cb-15ad-422c-80c7-19f101665444")]
// 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("2015.0.0.0")]
[assembly: AssemblyFileVersion("2015.0.0.2464")]
@@ -0,0 +1,337 @@
//
// (C) Copyright 2003-2012 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 System.Linq;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.ResultsBuilder;
using Autodesk.Revit.DB.ResultsBuilder.Storage;
using Autodesk.Revit.DB.Structure;
namespace Revit.SDK.Samples.QueryingResults.CS
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// </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)]
class QueryResults : IExternalCommand
{
#region Class Members
// Ids of elements used in this example
// ElementIds are hardcoded, so this example has to be used with the included "ResultsInRevit.rvt" file
ElementId linearElementId = new ElementId(262075);
ElementId surfaceElementId = new ElementId(263074);
// Reference to the Revit document
Document document;
#endregion
#region Class Interface Implementation
/// <summary>
/// The top level command.
/// </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)
{
// Set reference to the document and then check if this command is run on the inclueded "ResultsInRevit.rvt" file
document = commandData.Application.ActiveUIDocument.Document;
String outputDocumentPathName = commandData.Application.ActiveUIDocument.Document.PathName + ".ECTesting.txt";
Autodesk.Revit.UI.Result res = Result.Failed;
if (document.Title != "ResultsInRevit.rvt")
{
// Report error if this is a wrong file
Autodesk.Revit.UI.TaskDialog.Show("Wrong Revit file", "Cannot use :\n" + document.PathName + "\n\nPlease use attached " + "\"ResultsInRevit.rvt\" file.");
}
else
{
// Go ahead and read some results from elements otherwise
try
{
// Set ElementIds for Revit elements and loads used in this example. ElementIds are hardcoded
ElementId loadCaseId1 = new ElementId(37232);
ElementId loadCaseId2 = new ElementId(37234);
ElementId combinationId = new ElementId(261966);
ElementId []loadCaseIds = new ElementId[] { loadCaseId1, loadCaseId2, combinationId };
ResultsPackage resultsPackage = null;
try
{
// Get results package
resultsPackage = GetResultsPackage(document);
}
catch
{
Autodesk.Revit.UI.TaskDialog.Show("Cannot get result package.", "\nTry to store results first.");
}
// Read Results from the created result package and store them in the textfile
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(outputDocumentPathName, false))
{
writer.WriteLine(ReadLinearResults(resultsPackage, linearElementId, loadCaseIds));
writer.WriteLine(ReadArbitraryLinearResults(resultsPackage, linearElementId));
writer.WriteLine(ReadSurfaceResults(resultsPackage, surfaceElementId, loadCaseIds));
writer.WriteLine(ReadArbitrarySurfaceResults(resultsPackage, surfaceElementId));
}
res = Result.Succeeded;
}
catch (Exception ex)
{
Autodesk.Revit.UI.TaskDialog.Show("Failed to read results from Revit", ex.Message.ToString());
}
}
return res;
}
#endregion
#region Class Implementation
/// <summary>
/// Gets result package by getting Result Access object from the document, then querying it for a specific name ( "ResultsInRevit" )
/// </summary>
/// <param name="doc">Revit document</param>
/// <returns>ResultsPackage containig results created in the StoringResults example</returns>
ResultsPackage GetResultsPackage(Document doc)
{
ResultsAccess results = ResultsAccess.CreateResultsAccess(doc);
return results.ResultsPackages.First(s => s.Name == "ResultsInRevit");
}
/// <summary>
/// Reads linear analitical results for a specific element, for a set of load cases
/// </summary>
/// <param name="resultsPackage">Package from which to results are to be read</param>
/// <param name="elementId">Revit Element id</param>
/// <param name="loadCaseIds">Collection of load case Ids</param>
/// <returns>Results formatted into a string</returns>
private String ReadLinearResults( ResultsPackage resultsPackage, ElementId elementId, ElementId []loadCaseIds)
{
// Set a list of result type elements
IList<LinearResultType> linearResultTypes = new List<LinearResultType>() { LinearResultType.Fx, LinearResultType.Fy, LinearResultType.Fz, LinearResultType.Mx, LinearResultType.My, LinearResultType.Mz };
List<ElementId> elementIds = new List<ElementId>() { elementId };
// Read results from the package
IList<LineGraph> graphs = resultsPackage.GetLineGraphs(elementIds, loadCaseIds, linearResultTypes, new LineGraphParameters( UnitsSystem.Metric ) );
// Format results
return FormatLinearResultsOutput( "Linear results", graphs);
}
/// <summary>
/// Reads linear arbitrary results for a specific element in a similar way to analitical results
/// No load cases are used as arbitrary results are load independent
/// </summary>
/// <param name="resultsPackage">Package from which to results are to be read</param>
/// <param name="elementId">Revit Element id</param>
/// <returns>Results formatted into a string</returns>
private String ReadArbitraryLinearResults(ResultsPackage resultsPackage, ElementId elementId)
{
IList<String> rnfTypes = new List<String>() { "RnfBarsAngleBottom", "RnfBarsAngleTop", "RnfBarsAngleLeft", "RnfBarsAngleRight" };
List<ElementId> elementIds = new List<ElementId>() { elementId };
List<ElementId> loadCaseIds = new List<ElementId>() { null };
IList<LineGraph> graphs = resultsPackage.GetLineGraphs(elementIds, loadCaseIds, rnfTypes, new LineGraphParameters(UnitsSystem.Metric));
return FormatLinearResultsOutput( "Linear arbitrary results", graphs);
}
/// <summary>
/// Formats linear results into a string
/// </summary>
/// <param name="title">Title of the results group</param>
/// <param name="graphs">Results - collection of LineGraph elements</param>
/// <returns>String containing formatted results</returns>
private String FormatLinearResultsOutput( String title, IList<LineGraph> graphs)
{
// String object
StringBuilder res = new StringBuilder();
res.AppendLine();
// Add header(title)
res.AppendLine("Result type: " + title);
res.AppendLine();
// Add domain
res.AppendLine( "X coordinates: ");
foreach( double xCoord in graphs[0].Points.Select(s=>s.U))
{
res.Append(xCoord);
}
// Group results using loadId
var loads = graphs.GroupBy(s => s.LoadId);
// Iterate over groups
foreach (IGrouping<ElementId,LineGraph> load in loads)
{
res.AppendLine();
res.AppendLine();
// Get and add to the string Load info for each group( Load name and load type(Combination/LoadCase))
if (load.Key != null)
{
res.AppendLine(GetLoadInfoForGraph(load.Key));
}
// Iterate over all results in the current group
foreach (LineGraph lineGraph in load)
{
res.AppendLine();
// Get and add result type
res.AppendLine("Results: " +lineGraph.ResultType.ToString());
// Add all values for the current result
foreach( double value in lineGraph.Points.Select(s=>s.V))
{
res.Append( String.Format("{0:0.000},", value));
}
}
}
return res.ToString();
}
/// <summary>
/// Reads surface analitical results for a specific element, for a set of load cases
/// </summary>
/// <param name="resultsPackage">Package from which to results are to be read</param>
/// <param name="elementId">Revit Element id</param>
/// <param name="loadCaseIds">Collection of load case Ids</param>
/// <returns>Results formatted into a string</returns>
private String ReadSurfaceResults( ResultsPackage resultsPackage, ElementId elementId, ElementId []loadCaseIds)
{
// Set a list of result type elements
SurfaceResultType[] surfaceResultTypes = { SurfaceResultType.Fxx, SurfaceResultType.Fyy, SurfaceResultType.Fxy, SurfaceResultType.Mxx, SurfaceResultType.Myy, SurfaceResultType.Mxy };
List<ElementId> elementIds = new List<ElementId>() { elementId };
// Read results from the package
IList<SurfaceGraph> graphs = resultsPackage.GetSurfaceGraphs(elementIds, loadCaseIds, surfaceResultTypes, new SurfaceGraphParameters(UnitsSystem.Metric));
// Format results
return FormatSurfaceResultsOutput( "Surface results", graphs);
}
/// <summary>
/// Reads surface arbitrary results for a specific element in a similar way to analitical results
/// </summary>
/// <param name="resultsPackage">Package from which to results are to be read</param>
/// <param name="elementId">Revit Element id</param>
/// <returns>Results formatted into a string</returns>
private String ReadArbitrarySurfaceResults( ResultsPackage resultsPackage, ElementId elementId)
{
String[] surfaceResultTypes = { "AxxBottom", "AyyBottom", "AxxTop", "AyyTop" };
List<ElementId> elementIds = new List<ElementId>() { elementId };
List<ElementId> loadCaseIds = new List<ElementId>() { null };
IList<SurfaceGraph> graphs = resultsPackage.GetSurfaceGraphs(elementIds, loadCaseIds, surfaceResultTypes, new SurfaceGraphParameters(UnitsSystem.Metric));
return FormatSurfaceResultsOutput("Linear arbitrary results", graphs);
}
/// <summary>
/// Formats surface results into a string
/// </summary>
/// <param name="title">Title of the results group</param>
/// <param name="graphs">Results - collection of SurfaceGraph elements</param>
/// <returns>String containing formatted results</returns>
private String FormatSurfaceResultsOutput( String title, IList<SurfaceGraph> graphs)
{
StringBuilder res = new StringBuilder();
res.AppendLine();
// Add header(title)
res.AppendLine("Result type: " + title);
res.AppendLine();
// Add domain
res.AppendLine("Points coordinates (x,y,z): ");
foreach (XYZ coord in graphs[0].Points )
{
res.Append("(" + String.Format("{0:0.00},", coord.X) + String.Format("{0:0.00},", coord.Y) + String.Format("{0:0.00},", coord.Z) + ") ");
}
// Group results using loadId
var loads = graphs.GroupBy(s => s.LoadId);
// Iterate over groups
foreach (IGrouping<ElementId, SurfaceGraph> load in loads)
{
res.AppendLine();
res.AppendLine();
// Get and add to the string Load info for each group( Load name and load type(Combination/LoadCase))
if (load.Key != null)
{
res.AppendLine(GetLoadInfoForGraph(load.Key));
}
// Iterate over all results in the current group
foreach (SurfaceGraph surfaceGraph in load)
{
res.AppendLine();
// Get and add result type
res.AppendLine("Results: " + surfaceGraph.ResultType.ToString());
// Add all values for the current result
foreach (double value in surfaceGraph.Values)
{
res.Append(String.Format("{0:0.00},", value));
}
}
}
return res.ToString();
}
/// <summary>
/// Gets string containg formatted load case description for a given load case Id
/// </summary>
/// <param name="loadId">Id for the given load</param>
/// <returns>Load case description formatted int a string</returns>
private String GetLoadInfoForGraph(ElementId loadId)
{
// Get revit element
Autodesk.Revit.DB.Element load = document.GetElement(loadId);
// Get load case type
String type = load is LoadCase ? "Load Case" : ( load is LoadCombination ? "Load Combination" : "Unknown");
// Get load case name
String name = load is LoadCase ? (load as LoadCase).Name : ( load is LoadCombination ? (load as LoadCombination).Name : "-");
// Format both into a string
return "Load type: " + type + ", Load name: " + name;
}
#endregion
}
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>AssemblyPath</Assembly>
<ClientId>7ead6750-de24-4ca4-b063-ba40226e8d53</ClientId>
<FullClassName>Revit.SDK.Samples.QueryingResults.CS.QueryResults</FullClassName>
<Text>Query analitycal results in Revit</Text>
<Description>Read analitycal results from Revit and output them to text file</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A532EE11-A893-4D72-8245-76D47710C206}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>QueryingResults</RootNamespace>
<AssemblyName>QueryingResults</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<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>
<Prefer32Bit>false</Prefer32Bit>
</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>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ResultsBuilder">
<HintPath>..\..\..\..\..\..\References\ResultsBuilder\ResultsBuilder.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPI">
<HintPath>..\..\..\..\..\..\References\Revit\RevitAPI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPIUI">
<HintPath>..\..\..\..\..\..\References\Revit\RevitAPIUI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="QueryResults.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="QueryingResults.addin" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if exist ..\..\..\..\..\..\..\..\Tools\BuildEvents\BuildEvents.exe (
..\..\..\..\..\..\..\..\Tools\BuildEvents\BuildEvents.exe prepare_example $(ProjectDir) $(TargetPath) ..\..\..\..\..\..\Bin\SDK\CodeChecking\VisualStudio\Examples\ResultsInRevit\$(ProjectName)
)</PostBuildEvent>
</PropertyGroup>
<!-- 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>
-->
</Project>