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
+91
View File
@@ -0,0 +1,91 @@
//
// (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;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.ReferencePlane.CS
{
/// <summary>
/// The entry of this sample, that supports the IExternalCommand interface.
/// </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>
/// 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)
{
Transaction trans = new Transaction(commandData.Application.ActiveUIDocument.Document, "Revit.SDK.Samples.ReferencePlane");
trans.Start();
try
{
// Generate an object of Revit reference plane management.
ReferencePlaneMgr refPlaneMgr = new ReferencePlaneMgr(commandData);
using (ReferencePlaneForm dlg = new ReferencePlaneForm(refPlaneMgr))
{
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Done some actions, ask revit to execute it.
trans.Commit();
return Autodesk.Revit.UI.Result.Succeeded;
}
else
{
// Revit need to do nothing.
trans.RollBack();
return Autodesk.Revit.UI.Result.Cancelled;
}
}
}
catch (Exception e)
{
// Exception raised, report it by revit error reporting mechanism.
message = e.ToString();
trans.RollBack();
return Autodesk.Revit.UI.Result.Failed;
}
}
}
}
+198
View File
@@ -0,0 +1,198 @@
//
// (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 Element = Autodesk.Revit.DB.Element;
using GElement = Autodesk.Revit.DB.GeometryElement;
namespace Revit.SDK.Samples.ReferencePlane.CS
{
/// <summary>
/// A object to help locating with geometry data.
/// </summary>
public class GeoHelper
{
//Defined the precision.
private const double Precision = 0.0001;
/// <summary>
/// Find the bottom face of a face array.
/// </summary>
/// <param name="faces">A face array.</param>
/// <returns>The bottom face of a face array.</returns>
static public Face GetBottomFace(FaceArray faces)
{
Face face = null;
double elevation = 0;
double tempElevation = 0;
Mesh mesh = null;
foreach (Face f in faces)
{
if (IsVerticalFace(f))
{
// If this is a vertical face, it cannot be a bottom face to a certainty.
continue;
}
tempElevation = 0;
mesh = f.Triangulate();
foreach (Autodesk.Revit.DB.XYZ xyz in mesh.Vertices)
{
tempElevation = tempElevation + xyz.Z;
}
tempElevation = tempElevation / mesh.Vertices.Count;
if (elevation > tempElevation || null == face)
{
// Update the bottom face to which's elevation is the lowest.
face = f;
elevation = tempElevation;
}
}
// The bottom face is consider as which's average elevation is the lowest, except vertical
// face.
return face;
}
/// <summary>
/// Find out the three points which made of a plane.
/// </summary>
/// <param name="mesh">A mesh contains many points.</param>
/// <param name="startPoint">Create a new instance of ReferencePlane.</param>
/// <param name="endPoint">The free end apply to reference plane.</param>
/// <param name="thirdPnt">A third point needed to define the reference plane.</param>
static public void Distribute(Mesh mesh, ref Autodesk.Revit.DB.XYZ startPoint, ref Autodesk.Revit.DB.XYZ endPoint, ref Autodesk.Revit.DB.XYZ thirdPnt)
{
int count = mesh.Vertices.Count;
startPoint = mesh.Vertices[0];
endPoint = mesh.Vertices[(int)(count / 3)];
thirdPnt = mesh.Vertices[(int)(count / 3 * 2)];
}
/// <summary>
/// Calculate the length between two points.
/// </summary>
/// <param name="startPoint">The start point.</param>
/// <param name="endPoint">The end point.</param>
/// <returns>The length between two points.</returns>
static public double GetLength(Autodesk.Revit.DB.XYZ startPoint, Autodesk.Revit.DB.XYZ endPoint)
{
return Math.Sqrt(Math.Pow((endPoint.X - startPoint.X), 2) +
Math.Pow((endPoint.Y - startPoint.Y), 2) +
Math.Pow((endPoint.Z - startPoint.Z), 2));
}
/// <summary>
/// The distance between two value in a same axis.
/// </summary>
/// <param name="start">start value.</param>
/// <param name="end">end value.</param>
/// <returns>The distance between two value.</returns>
static public double GetDistance(double start, double end)
{
return Math.Abs(start - end);
}
/// <summary>
/// Get the vector between two points.
/// </summary>
/// <param name="startPoint">The start point.</param>
/// <param name="endPoint">The end point.</param>
/// <returns>The vector between two points.</returns>
static public Autodesk.Revit.DB.XYZ GetVector(Autodesk.Revit.DB.XYZ startPoint, Autodesk.Revit.DB.XYZ endPoint)
{
return new Autodesk.Revit.DB.XYZ (endPoint.X - startPoint.X,
endPoint.Y - startPoint.Y, endPoint.Z - startPoint.Z);
}
/// <summary>
/// Determines whether a face is vertical.
/// </summary>
/// <param name="face">The face to be determined.</param>
/// <returns>Return true if this face is vertical, or else return false.</returns>
static private bool IsVerticalFace(Face face)
{
foreach (EdgeArray ea in face.EdgeLoops)
{
foreach (Edge e in ea)
{
if (IsVerticalEdge(e))
{
return true;
}
}
}
return false;
}
/// <summary>
/// Determines whether a edge is vertical.
/// </summary>
/// <param name="edge">The edge to be determined.</param>
/// <returns>Return true if this edge is vertical, or else return false.</returns>
static private bool IsVerticalEdge(Edge edge)
{
List<XYZ> polyline = edge.Tessellate() as List<XYZ>;
Autodesk.Revit.DB.XYZ verticalVct = new Autodesk.Revit.DB.XYZ (0, 0, 1);
Autodesk.Revit.DB.XYZ pointBuffer = polyline[0];
for (int i = 1; i < polyline.Count; i = i + 1)
{
Autodesk.Revit.DB.XYZ temp = polyline[i];
Autodesk.Revit.DB.XYZ vector = GetVector(pointBuffer, temp);
if (Equal(vector, verticalVct))
{
return true;
}
else
{
continue;
}
}
return false;
}
/// <summary>
/// Determines whether two vector are equal in x and y axis.
/// </summary>
/// <param name="vectorA">The vector A.</param>
/// <param name="vectorB">The vector B.</param>
/// <returns>Return true if two vector are equals, or else return false.</returns>
static private bool Equal(Autodesk.Revit.DB.XYZ vectorA, Autodesk.Revit.DB.XYZ vectorB)
{
bool isNotEqual = (Precision < Math.Abs(vectorA.X - vectorB.X)) ||
(Precision < Math.Abs(vectorA.Y - vectorB.Y));
return isNotEqual ? false : true;
}
}
}
@@ -0,0 +1,56 @@
//
// (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("ReferencePlane")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReferencePlane")]
[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("25f38c45-c979-4235-9f23-164517a137c9")]
// 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")]
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>ReferencePlane.dll</Assembly>
<ClientId>7b9cac98-fb50-4ecd-a966-da3f0d06a144</ClientId>
<FullClassName>Revit.SDK.Samples.ReferencePlane.CS.Command</FullClassName>
<Text>ReferencePlane</Text>
<Description>Allow user to create a reference plane at the left face of the wall or at the bottom of slab which is selected first.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,107 @@
<?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>{1B954375-6B21-48A9-B301-38BAE35673AD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Revit.SDK.Samples.ReferencePlane.CS</RootNamespace>
<AssemblyName>ReferencePlane</AssemblyName>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<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.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Command.cs" />
<Compile Include="GeoHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReferencePlaneForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ReferencePlaneForm.Designer.cs">
<DependentUpon>ReferencePlaneForm.cs</DependentUpon>
</Compile>
<Compile Include="ReferencePlaneMgr.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ReferencePlaneForm.resx">
<SubType>Designer</SubType>
<DependentUpon>ReferencePlaneForm.cs</DependentUpon>
</EmbeddedResource>
</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,130 @@
//
// (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.
//
namespace Revit.SDK.Samples.ReferencePlane.CS
{
partial class ReferencePlaneForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.refPlanesDataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.refPlanesDataGridView)).BeginInit();
this.SuspendLayout();
//
// okButton
//
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.okButton.Location = new System.Drawing.Point(214, 236);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 1;
this.okButton.Text = "&Create";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(295, 236);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 2;
this.cancelButton.Text = "C&ancel";
this.cancelButton.UseVisualStyleBackColor = true;
//
// refPlanesDataGridView
//
this.refPlanesDataGridView.AllowUserToAddRows = false;
this.refPlanesDataGridView.AllowUserToDeleteRows = false;
this.refPlanesDataGridView.AllowUserToOrderColumns = true;
this.refPlanesDataGridView.AllowUserToResizeRows = false;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.refPlanesDataGridView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.refPlanesDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.refPlanesDataGridView.Location = new System.Drawing.Point(12, 12);
this.refPlanesDataGridView.Name = "refPlanesDataGridView";
this.refPlanesDataGridView.RowHeadersVisible = false;
this.refPlanesDataGridView.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.refPlanesDataGridView.Size = new System.Drawing.Size(358, 213);
this.refPlanesDataGridView.StandardTab = true;
this.refPlanesDataGridView.TabIndex = 0;
//
// ReferencePlaneForm
//
this.AcceptButton = this.okButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(382, 266);
this.Controls.Add(this.refPlanesDataGridView);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.okButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ReferencePlaneForm";
this.ShowInTaskbar = false;
this.Text = "Reference Plane";
((System.ComponentModel.ISupportInitialize)(this.refPlanesDataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.DataGridView refPlanesDataGridView;
}
}
@@ -0,0 +1,72 @@
//
// (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.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Revit.SDK.Samples.ReferencePlane.CS
{
/// <summary>
/// A form display all reference planes, and allow user to create
/// reference plane with a button.
/// </summary>
public partial class ReferencePlaneForm : System.Windows.Forms.Form
{
//A object to manage reference plane.
private ReferencePlaneMgr m_refPlaneMgr;
/// <summary>
/// A form object constructor.
/// </summary>
/// <param name="refPlaneMgr">A ReferencePlaneMgr buffer.</param>
public ReferencePlaneForm(ReferencePlaneMgr refPlaneMgr)
{
Debug.Assert(null != refPlaneMgr);
InitializeComponent();
m_refPlaneMgr = refPlaneMgr;
// Set up the data source.
refPlanesDataGridView.DataSource = m_refPlaneMgr.ReferencePlanes;
refPlanesDataGridView.Columns[0].Width = (int)(refPlanesDataGridView.Width * 0.13);
refPlanesDataGridView.Columns[1].Width = (int)(refPlanesDataGridView.Width * 0.29);
refPlanesDataGridView.Columns[2].Width = (int)(refPlanesDataGridView.Width * 0.29);
refPlanesDataGridView.Columns[3].Width = (int)(refPlanesDataGridView.Width * 0.29);
}
/// <summary>
/// Notify revit to generate a reference plane.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void okButton_Click(object sender, EventArgs e)
{
m_refPlaneMgr.Create();
}
}
}
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,324 @@
//
// (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.Diagnostics;
using System.Data;
using System.Collections.Generic;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Element = Autodesk.Revit.DB.Element;
using GElement = Autodesk.Revit.DB.GeometryElement;
namespace Revit.SDK.Samples.ReferencePlane.CS
{
/// <summary>
/// A object to manage reference plane.
/// </summary>
public class ReferencePlaneMgr
{
private UIDocument m_document; //the currently active project
private Options m_options; //User preferences for parsing of geometry.
//The datasource for a DataGridView control.
private DataTable m_referencePlanes;
//A dictionary for create reference plane with different host element.
private Dictionary<Type, CreateDelegate> m_createHandler;
/// <summary>
/// The datasource for a DataGridView control.
/// </summary>
public DataTable ReferencePlanes
{
get
{
GetAllReferencePlanes();
return m_referencePlanes;
}
}
//A delegate for create reference plane with different host element.
private delegate void CreateDelegate(Element host);
/// <summary>
/// A ReferencePlaneMgr object constructor.
/// </summary>
/// <param name="commandData">The ExternalCommandData object for the active
/// instance of Autodesk Revit.</param>
public ReferencePlaneMgr(ExternalCommandData commandData)
{
Debug.Assert(null != commandData);
m_document = commandData.Application.ActiveUIDocument;
//Get an instance of this class from Application. Create
m_options = commandData.Application.Application.Create.NewGeometryOptions();
//Set your preferences and pass it to Element.Geometry or Instance.Geometry.
m_options.ComputeReferences = true;
//m_options.DetailLevel = DetailLevels.Fine;
m_options.View = m_document.Document.ActiveView;
m_createHandler = new Dictionary<Type, CreateDelegate>();
m_createHandler.Add(typeof(Wall), new CreateDelegate(OperateWall));
m_createHandler.Add(typeof(Floor), new CreateDelegate(OperateSlab));
InitializeDataTable();
}
/// <summary>
/// Create reference plane with the selected element.
/// the selected element must be wall or slab at this sample code.
/// </summary>
public void Create()
{
foreach (ElementId eId in m_document.Selection.GetElementIds())
{
Element e = m_document.Document.GetElement(eId);
try
{
CreateDelegate createDelegate = m_createHandler[e.GetType()];
createDelegate(e);
}
catch (Exception)
{
continue;
}
}
}
/// <summary>
/// Initialize a DataTable object which is datasource of a DataGridView control.
/// </summary>
private void InitializeDataTable()
{
m_referencePlanes = new DataTable("ReferencePlanes");
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ID";
// Add the Column to the DataColumnCollection.
m_referencePlanes.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "BubbleEnd";
// Add the column to the table.
m_referencePlanes.Columns.Add(column);
// Create third column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "FreeEnd";
// Add the column to the table.
m_referencePlanes.Columns.Add(column);
// Create fourth column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Normal";
// Add the column to the table.
m_referencePlanes.Columns.Add(column);
// Make the ID column the primary key column.
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = m_referencePlanes.Columns["ID"];
m_referencePlanes.PrimaryKey = PrimaryKeyColumns;
}
/// <summary>
/// Format the output string for a point.
/// </summary>
/// <param name="point">A point to show in UI.</param>
/// <returns>The display string for a point.</returns>
private string Format(Autodesk.Revit.DB.XYZ point)
{
return "(" + Math.Round(point.X, 2).ToString() +
", " + Math.Round(point.Y, 2).ToString() +
", " + Math.Round(point.Z, 2).ToString() + ")";
}
/// <summary>
/// Get all reference planes in current revit project.
/// </summary>
/// <returns>The number of all reference planes.</returns>
private int GetAllReferencePlanes()
{
m_referencePlanes.Clear();
DataRow row;
FilteredElementIterator itor = (new FilteredElementCollector(m_document.Document)).OfClass(typeof(Autodesk.Revit.DB.ReferencePlane)).GetElementIterator();
Autodesk.Revit.DB.ReferencePlane refPlane = null;
itor.Reset();
while (itor.MoveNext())
{
refPlane = itor.Current as Autodesk.Revit.DB.ReferencePlane;
if (null == refPlane)
{
continue;
}
else
{
row = m_referencePlanes.NewRow();
row["ID"] = refPlane.Id.IntegerValue;
row["BubbleEnd"] = Format(refPlane.BubbleEnd);
row["FreeEnd"] = Format(refPlane.FreeEnd);
row["Normal"] = Format(refPlane.Normal);
m_referencePlanes.Rows.Add(row);
}
}
return m_referencePlanes.Rows.Count;
}
/// <summary>
/// Create reference plane for a wall.
/// </summary>
/// <param name="host">A wall element.</param>
private void OperateWall(Element host)
{
Wall wall = host as Wall;
Autodesk.Revit.DB.XYZ bubbleEnd = new Autodesk.Revit.DB.XYZ();
Autodesk.Revit.DB.XYZ freeEnd = new Autodesk.Revit.DB.XYZ();
Autodesk.Revit.DB.XYZ cutVec = new Autodesk.Revit.DB.XYZ();
LocateWall(wall, ref bubbleEnd, ref freeEnd, ref cutVec);
m_document.Document.Create.NewReferencePlane(bubbleEnd, freeEnd, cutVec, m_document.Document.ActiveView);
}
/// <summary>
/// Create reference plane for a slab.
/// </summary>
/// <param name="host">A floor element.</param>
private void OperateSlab(Element host)
{
Floor floor = host as Floor;
Autodesk.Revit.DB.XYZ bubbleEnd = new Autodesk.Revit.DB.XYZ();
Autodesk.Revit.DB.XYZ freeEnd = new Autodesk.Revit.DB.XYZ();
Autodesk.Revit.DB.XYZ thirdPnt = new Autodesk.Revit.DB.XYZ();
LocateSlab(floor, ref bubbleEnd, ref freeEnd, ref thirdPnt);
m_document.Document.Create.NewReferencePlane2(bubbleEnd, freeEnd, thirdPnt, m_document.Document.ActiveView);
}
/// <summary>
/// Located the exterior of a wall object.
/// </summary>
/// <param name="wall">A wall object</param>
/// <param name="bubbleEnd">The bubble end of new reference plane.</param>
/// <param name="freeEnd">The free end of new reference plane.</param>
/// <param name="cutVec">The cut vector of new reference plane.</param>
private void LocateWall(Wall wall, ref Autodesk.Revit.DB.XYZ bubbleEnd, ref Autodesk.Revit.DB.XYZ freeEnd, ref Autodesk.Revit.DB.XYZ cutVec)
{
LocationCurve location = wall.Location as LocationCurve;
Curve locaCurve = location.Curve;
//Not work for wall without location.
if (null == locaCurve)
{
throw new Exception("This wall has no location.");
}
//Not work for arc wall.
Line line = locaCurve as Line;
if (null == line)
{
throw new Exception("Just work for straight wall.");
}
//Calculate offset by law of cosines.
double halfThickness = wall.Width / 2;
double length = GeoHelper.GetLength(locaCurve.GetEndPoint(0), locaCurve.GetEndPoint(1));
double xAxis = GeoHelper.GetDistance(locaCurve.GetEndPoint(0).X, locaCurve.GetEndPoint(1).X);
double yAxis = GeoHelper.GetDistance(locaCurve.GetEndPoint(0).Y, locaCurve.GetEndPoint(1).Y);
double xOffset = yAxis * halfThickness / length;
double yOffset = xAxis * halfThickness / length;
if (locaCurve.GetEndPoint(0).X < locaCurve.GetEndPoint(1).X
&& locaCurve.GetEndPoint(0).Y < locaCurve.GetEndPoint(1).Y)
{
xOffset = -xOffset;
}
if (locaCurve.GetEndPoint(0).X > locaCurve.GetEndPoint(1).X
&& locaCurve.GetEndPoint(0).Y > locaCurve.GetEndPoint(1).Y)
{
yOffset = -yOffset;
}
if (locaCurve.GetEndPoint(0).X > locaCurve.GetEndPoint(1).X
&& locaCurve.GetEndPoint(0).Y < locaCurve.GetEndPoint(1).Y)
{
xOffset = -xOffset;
yOffset = -yOffset;
}
//Three necessary parameters for generate a reference plane.
bubbleEnd = new Autodesk.Revit.DB.XYZ(locaCurve.GetEndPoint(0).X + xOffset,
locaCurve.GetEndPoint(0).Y + yOffset, locaCurve.GetEndPoint(0).Z);
freeEnd = new Autodesk.Revit.DB.XYZ(locaCurve.GetEndPoint(1).X + xOffset,
locaCurve.GetEndPoint(1).Y + yOffset, locaCurve.GetEndPoint(1).Z);
cutVec = new Autodesk.Revit.DB.XYZ(0, 0, 1);
}
/// <summary>
/// Located the buttom of a slab object.
/// </summary>
/// <param name="floor">A floor object.</param>
/// <param name="bubbleEnd">The bubble end of new reference plane.</param>
/// <param name="freeEnd">The free end of new reference plane.</param>
/// <param name="thirdPnt">The third point of new reference plane.</param>
private void LocateSlab(Floor floor, ref Autodesk.Revit.DB.XYZ bubbleEnd, ref Autodesk.Revit.DB.XYZ freeEnd, ref Autodesk.Revit.DB.XYZ thirdPnt)
{
//Obtain the geometry data of the floor.
GElement geometry = floor.get_Geometry(m_options);
Face buttomFace = null;
//foreach (GeometryObject go in geometry.Objects)
IEnumerator<GeometryObject> Objects = geometry.GetEnumerator();
while (Objects.MoveNext())
{
GeometryObject go = Objects.Current;
Solid solid = go as Solid;
if (null == solid)
{
continue;
}
else
{
//Get the bottom face of this floor.
buttomFace = GeoHelper.GetBottomFace(solid.Faces);
}
}
Mesh mesh = buttomFace.Triangulate();
GeoHelper.Distribute(mesh, ref bubbleEnd, ref freeEnd, ref thirdPnt);
}
}
}