mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-09-17 01:52:14 +00:00
added Revit 2022 SDK minus except *rvt and *rfa
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// (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.CreateComplexAreaRein.CS
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.ComponentModel;
|
||||
|
||||
using Autodesk.Revit;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
|
||||
using GeoElement = Autodesk.Revit.DB.GeometryElement;
|
||||
using Element = Autodesk.Revit.DB.Element;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// data and data manager of the AreaReinforcement
|
||||
/// </summary>
|
||||
public class AreaReinData
|
||||
{
|
||||
private Document m_doc;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
public AreaReinData(Document doc)
|
||||
{
|
||||
m_doc = doc;
|
||||
}
|
||||
|
||||
private LayoutRules m_layoutRule = LayoutRules.Maximum_Spacing;
|
||||
|
||||
/// <summary>
|
||||
/// Parameter LayoutRule of AreaReinforcement
|
||||
/// </summary>
|
||||
public LayoutRules LayoutRule
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_layoutRule;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_layoutRule = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set the parameters to given AreaReinforcement
|
||||
/// </summary>
|
||||
/// <param name="areaRein"></param>
|
||||
public virtual void FillIn(AreaReinforcement areaRein)
|
||||
{
|
||||
int temp = (int)m_layoutRule;
|
||||
bool flag = ParameterUtil.SetParaInt(areaRein,
|
||||
BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE, temp);
|
||||
//if BuiltInParameter doesn't work
|
||||
if (!flag)
|
||||
{
|
||||
Parameter paraLayout = ParameterUtil.FindParaByName(
|
||||
areaRein.Parameters, "Layout Rule");
|
||||
if (null != paraLayout)
|
||||
{
|
||||
paraLayout.Set(temp);
|
||||
}
|
||||
}
|
||||
ChangeAreaReinCurves(areaRein);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On the interior 4 curves, set the override flag
|
||||
/// and flip the hooks on the top 2 layers to "up"
|
||||
/// </summary>
|
||||
/// <param name="areaRein"></param>
|
||||
private void ChangeAreaReinCurves(AreaReinforcement areaRein)
|
||||
{
|
||||
//interior 4 curves are listed in the back of the curves,
|
||||
//this order is decided when we create it
|
||||
IList<ElementId> curveIds = areaRein.GetBoundaryCurveIds();
|
||||
for (int i = 4; i < 8; i++)
|
||||
{
|
||||
AreaReinforcementCurve areaReinCurve =
|
||||
m_doc.GetElement(curveIds[i]) as AreaReinforcementCurve;
|
||||
//remove hooks, set the hook the top 2 layers to 'up'
|
||||
ParameterUtil.SetParaInt(areaReinCurve,
|
||||
BuiltInParameter.REBAR_SYSTEM_OVERRIDE, -1);
|
||||
ParameterUtil.SetParaInt(areaReinCurve,
|
||||
BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_1,
|
||||
(int)HookOrientation.Up);
|
||||
ParameterUtil.SetParaInt(areaReinCurve,
|
||||
BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_2,
|
||||
(int)HookOrientation.Up);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RevitAddIns>
|
||||
<AddIn Type="Command">
|
||||
<Assembly>CreateComplexAreaRein.dll</Assembly>
|
||||
<ClientId>94ea8791-f8fd-44c6-9bcd-aa3c49170ba3</ClientId>
|
||||
<FullClassName>Revit.SDK.Samples.CreateComplexAreaRein.CS.Command</FullClassName>
|
||||
<Text>Create Complex Area Reinforcement</Text>
|
||||
<Description>Create complex AreaReinforcement on selected slab.</Description>
|
||||
<VisibilityMode>AlwaysVisible</VisibilityMode>
|
||||
<VendorId>ADSK</VendorId>
|
||||
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
|
||||
</AddIn>
|
||||
</RevitAddIns>
|
||||
@@ -0,0 +1,178 @@
|
||||
//
|
||||
// (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 Autodesk.Revit.UI;
|
||||
|
||||
namespace Revit.SDK.Samples.CreateComplexAreaRein.CS
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Autodesk.Revit;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
|
||||
using DocCreator = Autodesk.Revit.Creation.Document;
|
||||
|
||||
|
||||
[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
|
||||
{
|
||||
private UIDocument m_currentDoc;
|
||||
private static ExternalCommandData m_revit;
|
||||
private AreaReinData m_data;
|
||||
|
||||
///<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 revit,
|
||||
ref string message, Autodesk.Revit.DB.ElementSet elements)
|
||||
{
|
||||
Transaction trans = new Transaction(revit.Application.ActiveUIDocument.Document, "Revit.SDK.Samples.CreateComplexAreaRein");
|
||||
trans.Start();
|
||||
//initialize members
|
||||
m_revit = revit;
|
||||
m_currentDoc = revit.Application.ActiveUIDocument;
|
||||
m_data = new AreaReinData(revit.Application.ActiveUIDocument.Document);
|
||||
|
||||
try
|
||||
{
|
||||
//check precondition and prepare necessary data to create AreaReinforcement.
|
||||
Reference refer = null;
|
||||
IList<Curve> curves = new List<Curve>();
|
||||
Floor floor = InitFloor(ref refer, ref curves);
|
||||
|
||||
//ask for user's input
|
||||
AreaReinData dataOnFloor = new AreaReinData(revit.Application.ActiveUIDocument.Document);
|
||||
CreateComplexAreaReinForm createForm = new
|
||||
CreateComplexAreaReinForm(dataOnFloor);
|
||||
if (createForm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
//define the Major Direction of AreaReinforcement,
|
||||
//we get direction of first Line on the Floor as the Major Direction
|
||||
Line firstLine = (Line)(curves[0]);
|
||||
Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ(
|
||||
firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X,
|
||||
firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y,
|
||||
firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z);
|
||||
|
||||
//create AreaReinforcement by AreaReinforcement.Create() function
|
||||
DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create;
|
||||
ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(revit.Application.ActiveUIDocument.Document);
|
||||
ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(revit.Application.ActiveUIDocument.Document);
|
||||
ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(revit.Application.ActiveUIDocument.Document);
|
||||
AreaReinforcement areaRein = AreaReinforcement.Create(revit.Application.ActiveUIDocument.Document, floor, curves, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId);
|
||||
|
||||
//set AreaReinforcement and it's AreaReinforcementCurves parameters
|
||||
dataOnFloor.FillIn(areaRein);
|
||||
trans.Commit();
|
||||
return Autodesk.Revit.UI.Result.Succeeded;
|
||||
}
|
||||
}
|
||||
catch (ApplicationException appEx)
|
||||
{
|
||||
message = appEx.Message;
|
||||
trans.RollBack();
|
||||
return Autodesk.Revit.UI.Result.Failed;
|
||||
}
|
||||
catch
|
||||
{
|
||||
message = "Unknow Errors.";
|
||||
trans.RollBack();
|
||||
return Autodesk.Revit.UI.Result.Failed;
|
||||
}
|
||||
trans.RollBack();
|
||||
return Autodesk.Revit.UI.Result.Cancelled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ExternalCommandData
|
||||
/// </summary>
|
||||
public static ExternalCommandData CommandData
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_revit;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// initialize member data, judge simple precondition
|
||||
/// </summary>
|
||||
private Floor InitFloor(ref Reference refer, ref IList<Curve> curves)
|
||||
{
|
||||
ElementSet elems = new ElementSet();
|
||||
foreach (ElementId elementId in m_currentDoc.Selection.GetElementIds())
|
||||
{
|
||||
elems.Insert(m_currentDoc.Document.GetElement(elementId));
|
||||
}
|
||||
//selected 0 or more than 1 element
|
||||
if (elems.Size != 1)
|
||||
{
|
||||
string msg = "Please select exactly one slab.";
|
||||
ApplicationException appEx = new ApplicationException(msg);
|
||||
throw appEx;
|
||||
}
|
||||
Floor floor = null;
|
||||
foreach (object o in elems)
|
||||
{
|
||||
//selected one floor
|
||||
floor = o as Floor;
|
||||
if (null == floor)
|
||||
{
|
||||
string msg = "Please select exactly one slab.";
|
||||
ApplicationException appEx = new ApplicationException(msg);
|
||||
throw appEx;
|
||||
}
|
||||
}
|
||||
//check the shape is rectangular and get its edges
|
||||
GeomHelper helper = new GeomHelper();
|
||||
if (!helper.GetFloorGeom(floor, ref refer, ref curves))
|
||||
{
|
||||
ApplicationException appEx = new
|
||||
ApplicationException(
|
||||
"Your selection is not a structural rectangular horizontal slab.");
|
||||
throw appEx;
|
||||
}
|
||||
|
||||
return floor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?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>{4F88FC9C-304E-4102-A280-6BB92BE21DB6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Revit.SDK.Samples.CreateComplexAreaRein.CS</RootNamespace>
|
||||
<AssemblyName>CreateComplexAreaRein</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="AreaReinData.cs" />
|
||||
<Compile Include="CreateComplexAreaRein.cs" />
|
||||
<Compile Include="CreateComplexAreaReinForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CreateComplexAreaReinForm.Designer.cs">
|
||||
<DependentUpon>CreateComplexAreaReinForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="GeomHelper.cs" />
|
||||
<Compile Include="GeomUtil.cs" />
|
||||
<Compile Include="ParameterUtil.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="CreateComplexAreaReinForm.resx">
|
||||
<DependentUpon>CreateComplexAreaReinForm.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</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,128 @@
|
||||
//
|
||||
// (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.CreateComplexAreaRein.CS
|
||||
{
|
||||
partial class CreateComplexAreaReinForm
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
this.okButton = new System.Windows.Forms.Button();
|
||||
this.cancelButton = new System.Windows.Forms.Button();
|
||||
this.layoutRuleComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.Location = new System.Drawing.Point(229, 62);
|
||||
this.okButton.Name = "okButton";
|
||||
this.okButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.okButton.TabIndex = 2;
|
||||
this.okButton.Text = "C&reate";
|
||||
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(310, 62);
|
||||
this.cancelButton.Name = "cancelButton";
|
||||
this.cancelButton.Size = new System.Drawing.Size(75, 23);
|
||||
this.cancelButton.TabIndex = 3;
|
||||
this.cancelButton.Text = "&Cancel";
|
||||
this.cancelButton.UseVisualStyleBackColor = true;
|
||||
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
|
||||
//
|
||||
// layoutRuleComboBox
|
||||
//
|
||||
this.layoutRuleComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.layoutRuleComboBox.FormattingEnabled = true;
|
||||
this.layoutRuleComboBox.Location = new System.Drawing.Point(85, 18);
|
||||
this.layoutRuleComboBox.Name = "layoutRuleComboBox";
|
||||
this.layoutRuleComboBox.Size = new System.Drawing.Size(300, 21);
|
||||
this.layoutRuleComboBox.TabIndex = 1;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(12, 21);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(67, 13);
|
||||
this.label2.TabIndex = 6;
|
||||
this.label2.Text = "Layout Rule:";
|
||||
//
|
||||
// CreateComplexAreaReinForm
|
||||
//
|
||||
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(394, 95);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.layoutRuleComboBox);
|
||||
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 = "CreateComplexAreaReinForm";
|
||||
this.ShowInTaskbar = false;
|
||||
this.Text = "Create Complex AreaReinforcement";
|
||||
this.Load += new System.EventHandler(this.CreateComplexAreaReinForm_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button okButton;
|
||||
private System.Windows.Forms.Button cancelButton;
|
||||
private System.Windows.Forms.ComboBox layoutRuleComboBox;
|
||||
private System.Windows.Forms.Label label2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// (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.CreateComplexAreaRein.CS
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// simple business process of UI
|
||||
/// </summary>
|
||||
public partial class CreateComplexAreaReinForm : System.Windows.Forms.Form
|
||||
{
|
||||
private AreaReinData m_dataBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// constructor; initialize member data
|
||||
/// </summary>
|
||||
/// <param name="dataBuffer"></param>
|
||||
public CreateComplexAreaReinForm(AreaReinData dataBuffer)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
m_dataBuffer = dataBuffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// bind data to controls
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void CreateComplexAreaReinForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
layoutRuleComboBox.DataSource = Enum.GetNames(typeof(LayoutRules));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to create
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
m_dataBuffer.LayoutRule = (LayoutRules)Enum.Parse(typeof(LayoutRules),
|
||||
layoutRuleComboBox.SelectedItem.ToString());
|
||||
this.DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// cancel the command
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,139 @@
|
||||
//
|
||||
// (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.CreateComplexAreaRein.CS
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Autodesk.Revit;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
|
||||
using GeoElement = Autodesk.Revit.DB.GeometryElement;
|
||||
using Element = Autodesk.Revit.DB.Element;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// provide utility method to get geometry data for
|
||||
/// creating AreaReinforcement on wall or floor
|
||||
/// </summary>
|
||||
class GeomHelper
|
||||
{
|
||||
private Document m_currentDoc; //active document
|
||||
|
||||
/// <summary>
|
||||
/// constructor, initialize m_currentDoc
|
||||
/// </summary>
|
||||
public GeomHelper()
|
||||
{
|
||||
m_currentDoc = Command.CommandData.Application.ActiveUIDocument.Document;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get necessary data when create AreaReinforcement on a horizontal floor
|
||||
/// </summary>
|
||||
/// <param name="floor">floor on which to create AreaReinforcemen</param>
|
||||
/// <param name="refer">reference of the horizontal face on the floor</param>
|
||||
/// <param name="curves">curves compose the horizontal face of the floor</param>
|
||||
/// <returns>is successful</returns>
|
||||
public bool GetFloorGeom(Floor floor, ref Reference refer, ref IList<Curve> curves)
|
||||
{
|
||||
//get horizontal face's reference
|
||||
FaceArray faces = GeomUtil.GetFaces(floor);
|
||||
foreach (Face face in faces)
|
||||
{
|
||||
if (GeomUtil.IsHorizontalFace(face))
|
||||
{
|
||||
refer = face.Reference;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (null == refer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//get analytical model profile
|
||||
AnalyticalModel model = floor.GetAnalyticalModel();
|
||||
if (null == model)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
curves = model.GetCurves(AnalyticalCurveType.ActiveCurves);
|
||||
|
||||
if (!GeomUtil.IsRectangular(curves))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
curves = AddInlaidCurves(curves, 0.5);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// create CurveArray which contain 8 curves, 4 is exterior lines and 4 is interior lines
|
||||
/// </summary>
|
||||
/// <param name="curves"></param>
|
||||
/// <param name="scale"></param>
|
||||
/// <returns></returns>
|
||||
private IList<Curve> AddInlaidCurves(IList<Curve> curves, double scale)
|
||||
{
|
||||
//because curves is readonly, can't use method Curve.Append(Curve)
|
||||
List<Line> lines = new List<Line>();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Line temp = curves[i] as Line;
|
||||
lines.Add(temp);
|
||||
}
|
||||
|
||||
//length and width of the rectangle
|
||||
double length = GeomUtil.GetLength(lines[0]);
|
||||
double width = GeomUtil.GetLength(lines[1]);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
//height line
|
||||
Line tempLine1 = lines[i * 2];
|
||||
Line scaledLine1 = GeomUtil.GetScaledLine(tempLine1, scale);
|
||||
double distance1 = scale / 2 * width;
|
||||
Line movedLine1 = GeomUtil.GetXYParallelLine(scaledLine1, distance1);
|
||||
lines.Add(movedLine1);
|
||||
|
||||
//width line
|
||||
Line tempLine2 = lines[i * 2 + 1];
|
||||
Line scaledLine2 = GeomUtil.GetScaledLine(tempLine2, scale);
|
||||
double distance2 = scale / 2 * length;
|
||||
Line movedLine2 = GeomUtil.GetXYParallelLine(scaledLine2, distance2);
|
||||
lines.Add(movedLine2);
|
||||
}
|
||||
|
||||
//add all 8 lines into return array
|
||||
IList<Curve> allLines = new List<Curve>();
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
allLines.Add(lines[i]);
|
||||
}
|
||||
return allLines;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
//
|
||||
// (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.CreateComplexAreaRein.CS
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Autodesk.Revit;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
|
||||
using GeoElement = Autodesk.Revit.DB.GeometryElement;
|
||||
using GeoSolid = Autodesk.Revit.DB.Solid;
|
||||
using Element = Autodesk.Revit.DB.Element;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// provide some common geometry judgement and calculate method
|
||||
/// </summary>
|
||||
class GeomUtil
|
||||
{
|
||||
const double PRECISION = 0.00001; //precision when judge whether two doubles are equal
|
||||
|
||||
/// <summary>
|
||||
/// get all faces that compose the geometry solid of given element
|
||||
/// </summary>
|
||||
/// <param name="elem">element to be calculated</param>
|
||||
/// <returns>all faces</returns>
|
||||
public static FaceArray GetFaces(Element elem)
|
||||
{
|
||||
List<Face> faces = new List<Face>();
|
||||
|
||||
Autodesk.Revit.DB.Options geoOptions = Command.CommandData.Application.Application.Create.NewGeometryOptions();
|
||||
geoOptions.ComputeReferences = true;
|
||||
|
||||
GeoElement geoElem = elem.get_Geometry(geoOptions);
|
||||
//GeometryObjectArray geoElems = geoElem.Objects;
|
||||
IEnumerator<GeometryObject> Objects = geoElem.GetEnumerator();
|
||||
//foreach (object o in geoElems)
|
||||
while (Objects.MoveNext())
|
||||
{
|
||||
object o = Objects.Current;
|
||||
|
||||
GeoSolid geoSolid = o as GeoSolid;
|
||||
if (null == geoSolid)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return geoSolid.Faces;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get all points proximate to the given face
|
||||
/// </summary>
|
||||
/// <param name="face">face to be calculated</param>
|
||||
/// <returns></returns>
|
||||
public static List<Autodesk.Revit.DB.XYZ> GetPoints(Face face)
|
||||
{
|
||||
List<Autodesk.Revit.DB.XYZ> points = new List<Autodesk.Revit.DB.XYZ>();
|
||||
List<Autodesk.Revit.DB.XYZ> XYZs = face.Triangulate().Vertices as List<Autodesk.Revit.DB.XYZ>;
|
||||
|
||||
|
||||
|
||||
foreach (Autodesk.Revit.DB.XYZ point in XYZs)
|
||||
{
|
||||
points.Add(point);
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// judge whether the given face is horizontal
|
||||
/// </summary>
|
||||
/// <param name="face">face to be judged</param>
|
||||
/// <returns>is horizontal</returns>
|
||||
public static bool IsHorizontalFace(Face face)
|
||||
{
|
||||
List<Autodesk.Revit.DB.XYZ> points = GetPoints(face);
|
||||
double z1 = points[0].Z;
|
||||
double z2 = points[1].Z;
|
||||
double z3 = points[2].Z;
|
||||
double z4 = points[3].Z;
|
||||
bool flag = IsEqual(z1, z2);
|
||||
flag = flag && IsEqual(z2, z3);
|
||||
flag = flag && IsEqual(z3, z4);
|
||||
flag = flag && IsEqual(z4, z1);
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// judge whether a face and a line are parallel
|
||||
/// </summary>
|
||||
/// <param name="face"></param>
|
||||
/// <param name="line"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsParallel(Face face, Line line)
|
||||
{
|
||||
List<Autodesk.Revit.DB.XYZ> points = GetPoints(face);
|
||||
Autodesk.Revit.DB.XYZ vector1 = SubXYZ(points[0], points[1]);
|
||||
Autodesk.Revit.DB.XYZ vector2 = SubXYZ(points[1], points[2]);
|
||||
Autodesk.Revit.DB.XYZ refer = SubXYZ(line.GetEndPoint(0), line.GetEndPoint(1));
|
||||
|
||||
Autodesk.Revit.DB.XYZ cross = CrossMatrix(vector1, vector2);
|
||||
double result = DotMatrix(cross, refer);
|
||||
|
||||
if (result < PRECISION)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// judge whether given 4 lines can form a rectangular
|
||||
/// </summary>
|
||||
/// <param name="lines"></param>
|
||||
/// <returns>is rectangular</returns>
|
||||
public static bool IsRectangular(IList<Curve> curves)
|
||||
{
|
||||
//make sure the CurveArray contains 4 line
|
||||
if (curves.Count != 4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Line[] lines = new Line[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
lines[i] = curves[i] as Line;
|
||||
if (null == lines[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//make sure the first line is vertical to 2 lines and parallel to another line
|
||||
Line iniLine = lines[0];
|
||||
Line[] verticalLines = new Line[2];
|
||||
Line paraLine = null;
|
||||
int index = 0;
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
if (IsVertical(lines[0], lines[i]))
|
||||
{
|
||||
verticalLines[index] = lines[i];
|
||||
index++;
|
||||
}
|
||||
else
|
||||
{
|
||||
paraLine = lines[i];
|
||||
}
|
||||
}
|
||||
if (index != 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool flag = IsVertical(paraLine, verticalLines[0]);
|
||||
return flag;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get the length of the given line
|
||||
/// </summary>
|
||||
/// <param name="line"></param>
|
||||
/// <returns>length</returns>
|
||||
public static double GetLength(Line line)
|
||||
{
|
||||
Autodesk.Revit.DB.XYZ sub = SubXYZ(line.GetEndPoint(0), line.GetEndPoint(1));
|
||||
double length = Math.Sqrt(sub.X * sub.X + sub.Y * sub.Y + sub.Z * sub.Z);
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get parallel line with give distance with given line in XY plane
|
||||
/// </summary>
|
||||
/// <param name="inLine">given line</param>
|
||||
/// <param name="distance">distance from given line</param>
|
||||
/// <returns>paralleled line</returns>
|
||||
public static Line GetXYParallelLine(Line inLine, double distance)
|
||||
{
|
||||
Autodesk.Revit.DB.XYZ direct = SubXYZ(inLine.GetEndPoint(1), inLine.GetEndPoint(0));
|
||||
double length = Math.Sqrt((-direct.Y) * (-direct.Y) + direct.X * direct.X);
|
||||
double temp = distance / length;
|
||||
|
||||
Autodesk.Revit.DB.XYZ dPerp = new XYZ(-direct.Y * temp,
|
||||
direct.X * temp, 0.0);
|
||||
|
||||
Autodesk.Revit.DB.XYZ startPoint = AddXYZ(inLine.GetEndPoint(0), dPerp);
|
||||
Autodesk.Revit.DB.XYZ endPoint = AddXYZ(inLine.GetEndPoint(1), dPerp);
|
||||
Line outLine = Line.CreateBound(startPoint, endPoint);
|
||||
//Line outLine = new Line(ref startPoint, ref endPoint);
|
||||
|
||||
return outLine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get scaled line which has both the same center and direction with give line
|
||||
/// </summary>
|
||||
/// <param name="inLine">given line</param>
|
||||
/// <param name="scale">scale value</param>
|
||||
/// <returns>scaled line</returns>
|
||||
public static Line GetScaledLine(Line inLine, double scale)
|
||||
{
|
||||
Autodesk.Revit.DB.XYZ startPoint = inLine.GetEndPoint(0);
|
||||
Autodesk.Revit.DB.XYZ endPoint = inLine.GetEndPoint(1);
|
||||
|
||||
Autodesk.Revit.DB.XYZ temp1 = SubXYZ(endPoint, startPoint);
|
||||
Autodesk.Revit.DB.XYZ temp2 = MultiXYZ(temp1, (scale - 1) / 2);
|
||||
Autodesk.Revit.DB.XYZ startPoint2 = SubXYZ(startPoint, temp2);
|
||||
Autodesk.Revit.DB.XYZ endPoint2 = AddXYZ(endPoint, temp2);
|
||||
|
||||
Line outLine = Line.CreateBound(startPoint2, endPoint2);
|
||||
//Line outLine = new Line(ref startPoint2, ref endPoint2);
|
||||
return outLine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// judge whether two lines are vertical
|
||||
/// </summary>
|
||||
/// <param name="line1"></param>
|
||||
/// <param name="line2"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsVertical(Line line1, Line line2)
|
||||
{
|
||||
Autodesk.Revit.DB.XYZ vector1 = SubXYZ(line1.GetEndPoint(0), line1.GetEndPoint(1));
|
||||
Autodesk.Revit.DB.XYZ vector2 = SubXYZ(line2.GetEndPoint(0), line2.GetEndPoint(1));
|
||||
|
||||
double result = DotMatrix(vector1, vector2);
|
||||
|
||||
if (Math.Abs(result) < PRECISION)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// subtraction of two Autodesk.Revit.DB.XYZ as Matrix
|
||||
/// </summary>
|
||||
/// <param name="p1"></param>
|
||||
/// <param name="p2"></param>
|
||||
/// <returns></returns>
|
||||
private static Autodesk.Revit.DB.XYZ SubXYZ(Autodesk.Revit.DB.XYZ p1, Autodesk.Revit.DB.XYZ p2)
|
||||
{
|
||||
double x = p1.X - p2.X;
|
||||
double y = p1.Y - p2.Y;
|
||||
double z = p1.Z - p2.Z;
|
||||
|
||||
Autodesk.Revit.DB.XYZ result = new Autodesk.Revit.DB.XYZ(x, y, z);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add two XYZ
|
||||
/// </summary>
|
||||
/// <param name="p1"></param>
|
||||
/// <param name="p2"></param>
|
||||
/// <returns></returns>
|
||||
private static Autodesk.Revit.DB.XYZ AddXYZ(Autodesk.Revit.DB.XYZ p1, Autodesk.Revit.DB.XYZ p2)
|
||||
{
|
||||
double x = p1.X + p2.X;
|
||||
double y = p1.Y + p2.Y;
|
||||
double z = p1.Z + p2.Z;
|
||||
|
||||
Autodesk.Revit.DB.XYZ result = new Autodesk.Revit.DB.XYZ(x, y, z);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// multiply Autodesk.Revit.DB.XYZ with a double
|
||||
/// </summary>
|
||||
/// <param name="p1"></param>
|
||||
/// <param name="para"></param>
|
||||
/// <returns></returns>
|
||||
private static Autodesk.Revit.DB.XYZ MultiXYZ(Autodesk.Revit.DB.XYZ p1, double para)
|
||||
{
|
||||
double x = p1.X * para;
|
||||
double y = p1.Y * para;
|
||||
double z = p1.Z * para;
|
||||
|
||||
Autodesk.Revit.DB.XYZ result = new Autodesk.Revit.DB.XYZ(x, y, z);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// multiplication cross of two Autodesk.Revit.DB.XYZ as Matrix
|
||||
/// </summary>
|
||||
/// <param name="p1"></param>
|
||||
/// <param name="p2"></param>
|
||||
/// <returns></returns>
|
||||
private static Autodesk.Revit.DB.XYZ CrossMatrix(Autodesk.Revit.DB.XYZ p1, Autodesk.Revit.DB.XYZ p2)
|
||||
{
|
||||
double v1 = p1.X;
|
||||
double v2 = p1.Y;
|
||||
double v3 = p1.Z;
|
||||
|
||||
double u1 = p2.X;
|
||||
double u2 = p2.Y;
|
||||
double u3 = p2.Z;
|
||||
|
||||
double x = v3 * u2 - v2 * u3;
|
||||
double y = -v3 * u1 + v1 * u3;
|
||||
double z = v2 * u1 - v1 * u2;
|
||||
|
||||
Autodesk.Revit.DB.XYZ point = new Autodesk.Revit.DB.XYZ(x, y, z);
|
||||
return point;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// dot product of two Autodesk.Revit.DB.XYZ as Matrix
|
||||
/// </summary>
|
||||
/// <param name="p1"></param>
|
||||
/// <param name="p2"></param>
|
||||
/// <returns></returns>
|
||||
private static double DotMatrix(Autodesk.Revit.DB.XYZ p1, Autodesk.Revit.DB.XYZ p2)
|
||||
{
|
||||
double v1 = p1.X;
|
||||
double v2 = p1.Y;
|
||||
double v3 = p1.Z;
|
||||
|
||||
double u1 = p2.X;
|
||||
double u2 = p2.Y;
|
||||
double u3 = p2.Z;
|
||||
|
||||
double result = v1 * u1 + v2 * u2 + v3 * u3;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// judge whether the subtraction of two doubles is less than the internal decided precision
|
||||
/// </summary>
|
||||
/// <param name="d1"></param>
|
||||
/// <param name="d2"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsEqual(double d1, double d2)
|
||||
{
|
||||
double diff = Math.Abs(d1 - d2);
|
||||
if (diff < PRECISION)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// (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.CreateComplexAreaRein.CS
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.ComponentModel;
|
||||
|
||||
using Autodesk.Revit;
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using GeoElement = Autodesk.Revit.DB.GeometryElement;
|
||||
using Element = Autodesk.Revit.DB.Element;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// enum of AreaReinforcement's parameter Layout Rules
|
||||
/// </summary>
|
||||
public enum LayoutRules
|
||||
{
|
||||
Fixed_Number = 2,
|
||||
Maximum_Spacing = 3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// enum of AreaReinforcementCurve's parameter Hook Orientation
|
||||
/// </summary>
|
||||
public enum HookOrientation
|
||||
{
|
||||
Up = 0,
|
||||
Down = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// contain utility methods find or set certain parameter
|
||||
/// </summary>
|
||||
public class ParameterUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// find certain parameter in a set
|
||||
/// </summary>
|
||||
/// <param name="paras"></param>
|
||||
/// <param name="name">find by name</param>
|
||||
/// <returns>found parameter</returns>
|
||||
public static Parameter FindParaByName(ParameterSet paras, string name)
|
||||
{
|
||||
Parameter findPara = null;
|
||||
|
||||
foreach (Parameter para in paras)
|
||||
{
|
||||
if (para.Definition.Name == name)
|
||||
{
|
||||
findPara = para;
|
||||
}
|
||||
}
|
||||
|
||||
return findPara;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set certain parameter of given element to int value
|
||||
/// </summary>
|
||||
/// <param name="elem">given element</param>
|
||||
/// <param name="paraIndex">BuiltInParameter</param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SetParaInt(Element elem, BuiltInParameter paraIndex, int value)
|
||||
{
|
||||
Parameter para = elem.get_Parameter(paraIndex);
|
||||
if (null == para)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
para.Set(value);
|
||||
return 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("CreateComplexAreaRein")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CreateComplexAreaRein")]
|
||||
[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("5b28e4a0-8ba8-482b-86a7-0d67b1887594")]
|
||||
|
||||
// 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")]
|
||||
Binary file not shown.
Reference in New Issue
Block a user