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,114 @@
//
// (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.IO;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
namespace Revit.SDK.Samples.PanelSchedule.CS
{
/// <summary>
/// Translate the panel schedule view data from Revit to CSV.
/// </summary>
class CSVTranslator : Translator
{
/// <summary>
/// create a CSVTranslator instance for a PanelScheduleView instance.
/// </summary>
/// <param name="psView">the exporting panel schedule view instance.</param>
public CSVTranslator(PanelScheduleView psView)
{
m_psView = psView;
}
/// <summary>
/// export to a CSV file that contains the PanelScheduleView instance data.
/// </summary>
/// <returns>the exported file path</returns>
public override string Export()
{
string asemblyName = System.Reflection.Assembly.GetExecutingAssembly().Location;
string panelScheduleCSVFile = asemblyName.Replace("PanelSchedule.dll", ReplaceIllegalCharacters(m_psView.Name) + ".csv");
if (File.Exists(panelScheduleCSVFile))
{
File.Delete(panelScheduleCSVFile);
}
using (StreamWriter sw = File.CreateText(panelScheduleCSVFile))
{
//sw.WriteLine("This is my file.");
DumpPanelScheduleData(sw);
sw.Close();
}
return panelScheduleCSVFile;
}
/// <summary>
/// dump PanelScheduleData to comma delimited.
/// </summary>
/// <param name="sw"></param>
private void DumpPanelScheduleData(StreamWriter sw)
{
DumpSectionData(sw, m_psView, SectionType.Header);
DumpSectionData(sw, m_psView, SectionType.Body);
DumpSectionData(sw, m_psView, SectionType.Summary);
DumpSectionData(sw, m_psView, SectionType.Footer);
}
/// <summary>
/// dump SectionData to comma delimited.
/// </summary>
/// <param name="sw">exporting file stream</param>
/// <param name="psView">the PanelScheduleView instance is exporting.</param>
/// <param name="sectionType">which section is exporting, it can be Header, Body, Summary or Footer.</param>
private void DumpSectionData(StreamWriter sw, PanelScheduleView psView, SectionType sectionType)
{
int nRows_Section = 0;
int nCols_Section = 0;
getNumberOfRowsAndColumns(m_psView.Document, m_psView, sectionType, ref nRows_Section, ref nCols_Section);
for (int ii = 0; ii < nRows_Section; ++ii)
{
StringBuilder oneRow = new StringBuilder();
for (int jj = 0; jj < nCols_Section; ++jj)
{
try
{
oneRow.AppendFormat("{0},", m_psView.GetCellText(sectionType, ii, jj));
}
catch (Exception)
{
// do nothing.
}
}
sw.WriteLine(oneRow.ToString());
}
}
}
}
@@ -0,0 +1,132 @@
//
// (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.Xml;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.PanelSchedule.CS
{
/// <summary>
/// Translate the panel schedule view data from Revit to HTML table.
/// </summary>
class HTMLTranslator : Translator
{
/// <summary>
/// create a Translator instance for a PanelScheduleView instance.
/// </summary>
/// <param name="psView">the exporting panel schedule view instance.</param>
public HTMLTranslator(PanelScheduleView psView)
{
m_psView = psView;
}
/// <summary>
/// export to a HTML page that contains the PanelScheduleView instance data.
/// </summary>
/// <returns>the exported file path</returns>
public override string Export()
{
string asemblyName = System.Reflection.Assembly.GetExecutingAssembly().Location;
string tempFile = asemblyName.Replace("PanelSchedule.dll", "template.html");
if (!System.IO.File.Exists(tempFile))
{
TaskDialog messageDlg = new TaskDialog("Warnning Message");
messageDlg.MainIcon = TaskDialogIcon.TaskDialogIconWarning;
messageDlg.MainContent = "Can not find 'template.html', please make sure the 'template.html' file is in the same folder as the external command assembly.";
messageDlg.Show();
return null;
}
string panelScheduleFile = asemblyName.Replace("PanelSchedule.dll", ReplaceIllegalCharacters(m_psView.Name) + ".html");
XmlDocument doc = new XmlDocument();
XmlTextWriter tw = new XmlTextWriter(panelScheduleFile, null);
doc.Load(tempFile);
XmlNode psTable = doc.DocumentElement.SelectSingleNode("//div/table[1]");
DumpPanelScheduleData(psTable, doc);
doc.Save(tw);
return panelScheduleFile;
}
/// <summary>
/// dump PanelScheduleData to a 'table' node in HTML.
/// </summary>
/// <param name="panelScheduleDataNode">a 'table' node in HTML.</param>
/// <param name="doc"></param>
private void DumpPanelScheduleData(XmlNode panelScheduleDataNode, XmlDocument doc)
{
DumpSectionData(panelScheduleDataNode, doc, m_psView, SectionType.Header);
DumpSectionData(panelScheduleDataNode, doc, m_psView, SectionType.Body);
DumpSectionData(panelScheduleDataNode, doc, m_psView, SectionType.Summary);
DumpSectionData(panelScheduleDataNode, doc, m_psView, SectionType.Footer);
}
/// <summary>
/// dump SectionData to the 'tr' nodes in HTML.
/// </summary>
/// <param name="panelScheduleDataNode">a 'table' node in HTML.</param>
/// <param name="doc">HTML page</param>
/// <param name="psView">the PanelScheduleView instance is exporting.</param>
/// <param name="sectionType">which section is exporting, it can be Header, Body, Summary or Footer.</param>
private void DumpSectionData(XmlNode panelScheduleDataNode, XmlDocument doc, PanelScheduleView psView, SectionType sectionType)
{
int nRows_Section = 0;
int nCols_Section = 0;
getNumberOfRowsAndColumns(m_psView.Document, m_psView, sectionType, ref nRows_Section, ref nCols_Section);
for (int ii = 0; ii < nRows_Section; ++ii)
{
// add a <tr> node for each row
XmlElement trNode = doc.CreateElement("tr");
panelScheduleDataNode.AppendChild(trNode);
for (int jj = 0; jj < nCols_Section; ++jj)
{
// add <td> node for each cell
XmlElement tdNode = doc.CreateElement("td");
try
{
tdNode.InnerText = m_psView.GetCellText(sectionType, ii, jj);
}
catch (Exception)
{
// do nothing.
}
trNode.AppendChild(tdNode);
}
}
}
}
}
@@ -0,0 +1,82 @@
//
// (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.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace Revit.SDK.Samples.PanelSchedule.CS
{
/// <summary>
/// Create view instance for an electrical panel.
/// </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 InstanceViewCreation : 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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
Reference selected = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element);
Transaction newInstanceView = new Transaction(doc, "Create instance view for an electrical panel.");
newInstanceView.Start();
PanelScheduleView instanceView = PanelScheduleView.CreateInstanceView(doc, doc.GetElement(selected).Id);
if (null == instanceView)
{
newInstanceView.RollBack();
message = "Please select one electrical panel.";
return Result.Failed;
}
else
{
newInstanceView.Commit();
return Result.Succeeded;
}
}
}
}
@@ -0,0 +1,33 @@
<?xml version="1.0"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>PanelSchedule.dll</Assembly>
<ClientId>D8B90E03-C357-47a0-9F03-A9560DAE57BA</ClientId>
<FullClassName>Revit.SDK.Samples.PanelSchedule.CS.PanelScheduleExport</FullClassName>
<Text>Panel Schedule Sample - Export Data</Text>
<Description>Exoport Revit Panle Schedule(s) to CSV file(s) or HTML page(s).</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
<AddIn Type="Command">
<Assembly>PanelSchedule.dll</Assembly>
<ClientId>B19F4B29-BA8E-408b-AD2B-9C6269DBE2DB</ClientId>
<FullClassName>Revit.SDK.Samples.PanelSchedule.CS.InstanceViewCreation</FullClassName>
<Text>Panel Schedule Sample - View Instance Creation</Text>
<Description>Create Panel Schedule View instance for a panel.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
<AddIn Type="Command">
<Assembly>PanelSchedule.dll</Assembly>
<ClientId>19E4C839-3DB2-4baa-BF0F-66A912B329D7</ClientId>
<FullClassName>Revit.SDK.Samples.PanelSchedule.CS.SheetImport</FullClassName>
<Text>Panel Schedule Sample - Sheet Instance Creation</Text>
<Description>Place Panel Schedule View instance on a sheet view.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,106 @@
<?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.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7049E1C8-65DE-4D14-99EA-68DBC94ECEAB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Revit.SDK.Samples.PanelSchedule.CS</RootNamespace>
<AssemblyName>PanelSchedule</AssemblyName>
<TargetFrameworkVersion>v4.8</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>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Debug\PanelSchedule.XML</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>
<DocumentationFile>bin\Release\PanelSchedule.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\PanelSchedule.XML</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<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>
<DocumentationFile>bin\Release\PanelSchedule.XML</DocumentationFile>
<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.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="InstanceViewCreation.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="PanelScheduleExport.cs" />
<Compile Include="CSVTranslator.cs" />
<Compile Include="SheetImport.cs" />
<Compile Include="Translator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="HTMLTranslator.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="template.html" />
</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>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>set FILEFORSAMPLEREG="$(SolutionDir)..\..\..\..\Regression\API\SDKSamples\UpdateSampleDllForRegression.pl"
if exist %25FILEFORSAMPLEREG%25 perl %25FILEFORSAMPLEREG%25 $(ProjectExt) "$(ProjectPath)" "$(TargetPath)" "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
</Project>
@@ -0,0 +1,113 @@
//
// (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.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.PanelSchedule.CS
{
/// <summary>
/// Export Panel Schedule View form Revit to CSV or HTML file.
/// </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 PanelScheduleExport : 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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
// get all PanelScheduleView instances in the Revit document.
FilteredElementCollector fec = new FilteredElementCollector(doc);
ElementClassFilter PanelScheduleViewsAreWanted = new ElementClassFilter(typeof(PanelScheduleView));
fec.WherePasses(PanelScheduleViewsAreWanted);
List<Element> psViews = fec.ToElements() as List<Element>;
bool noPanelScheduleInstance = true;
foreach (Element element in psViews)
{
PanelScheduleView psView = element as PanelScheduleView;
if (psView.IsPanelScheduleTemplate())
{
// ignore the PanelScheduleView instance which is a template.
continue;
}
else
{
noPanelScheduleInstance = false;
}
// choose what format export to, it can be CSV or HTML.
TaskDialog alternativeDlg = new TaskDialog("Choose Format to export");
alternativeDlg.MainContent = "Click OK to export in .CSV format, Cancel to export in HTML format.";
alternativeDlg.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel;
alternativeDlg.AllowCancellation = true;
TaskDialogResult exportToCSV = alternativeDlg.Show();
Translator translator = TaskDialogResult.Cancel == exportToCSV ? new HTMLTranslator(psView) : new CSVTranslator(psView) as Translator;
string exported = translator.Export();
// open the file if export successfully.
if (!string.IsNullOrEmpty(exported))
{
System.Diagnostics.Process.Start(exported);
}
}
if (noPanelScheduleInstance)
{
TaskDialog messageDlg = new TaskDialog("Warnning Message");
messageDlg.MainIcon = TaskDialogIcon.TaskDialogIconWarning;
messageDlg.MainContent = "No panel schedule view is in the current document.";
messageDlg.Show();
return Result.Cancelled;
}
return Result.Succeeded;
}
}
}
@@ -0,0 +1,58 @@
//
// (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.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("PanelSchedule")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Autodesk, Inc.")]
[assembly: AssemblyProduct("PanelSchedule")]
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc. 2010")]
[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("accd429a-7c7c-42b2-b3ee-ada66c018431")]
// 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")]
+102
View File
@@ -0,0 +1,102 @@
//
// (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.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.PanelSchedule.CS
{
/// <summary>
/// Import the panel scheduel view to place on a sheet view.
/// </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 SheetImport : 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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;
// get one sheet view to place panel schedule.
ViewSheet sheet = doc.ActiveView as ViewSheet;
if (null == sheet)
{
message = "please go to a sheet view.";
return Result.Failed;
}
// get all PanelScheduleView instances in the Revit document.
FilteredElementCollector fec = new FilteredElementCollector(doc);
ElementClassFilter PanelScheduleViewsAreWanted = new ElementClassFilter(typeof(PanelScheduleView));
fec.WherePasses(PanelScheduleViewsAreWanted);
List<Element> psViews = fec.ToElements() as List<Element>;
Transaction placePanelScheduleOnSheet = new Transaction(doc, "placePanelScheduleOnSheet");
placePanelScheduleOnSheet.Start();
XYZ nextOrigin = new XYZ(0.0, 0.0, 0.0);
foreach (Element element in psViews)
{
PanelScheduleView psView = element as PanelScheduleView;
if (psView.IsPanelScheduleTemplate())
{
// ignore the PanelScheduleView instance which is a template.
continue;
}
PanelScheduleSheetInstance onSheet = PanelScheduleSheetInstance.Create(doc, psView.Id, sheet);
onSheet.Origin = nextOrigin;
BoundingBoxXYZ bbox = onSheet.get_BoundingBox(doc.ActiveView);
double width = bbox.Max.X - bbox.Min.X;
nextOrigin = new XYZ(onSheet.Origin.X + width, onSheet.Origin.Y, onSheet.Origin.Z);
}
placePanelScheduleOnSheet.Commit();
return Result.Succeeded;
}
}
}
@@ -0,0 +1,81 @@
//
// (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 Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.PanelSchedule.CS
{
/// <summary>
/// Translate the panel schedule view data from Revit to some formats, HTML, CSV etc.
/// </summary>
abstract class Translator
{
/// <summary>
/// the panel schedule view instance to be exported.
/// </summary>
protected PanelScheduleView m_psView;
public abstract string Export();
/// <summary>
/// An utility method to replace illegal characters of the Panel Schedule view name.
/// </summary>
/// <param name="stringWithIllegalChar">the Panel Schedule view name.</param>
/// <returns>the updated string without illegal characters.</returns>
protected string ReplaceIllegalCharacters(string stringWithIllegalChar)
{
char[] illegalChars = System.IO.Path.GetInvalidFileNameChars();
string updated = stringWithIllegalChar;
foreach (char ch in illegalChars)
{
updated = updated.Replace(ch, '_');
}
return updated;
}
/// <summary>
/// An utility method to get the number of rows and columns of the section which is exporting.
/// </summary>
/// <param name="doc">Revit document.</param>
/// <param name="psView">the exporting panel schedule view</param>
/// <param name="sectionType">the exporting section of the panel schedule.</param>
/// <param name="nRows">the number of rows.</param>
/// <param name="nCols">the number of columns.</param>
protected void getNumberOfRowsAndColumns(Autodesk.Revit.DB.Document doc, PanelScheduleView psView, SectionType sectionType, ref int nRows, ref int nCols)
{
Transaction openSectionData = new Transaction(doc, "openSectionData");
openSectionData.Start();
TableSectionData sectionData = psView.GetSectionData(sectionType);
nRows = sectionData.NumberOfRows;
nCols = sectionData.NumberOfColumns;
openSectionData.RollBack();
}
}
}
@@ -0,0 +1,13 @@
<html>
<head>
<title>Autodesk Revit MEP 2011</title>
</head>
<body>
<div>
<table>
</table>
</div>
</body>
</html>