added Revit 2022 SDK minus except *rvt and *rfa

This commit is contained in:
Jeremy Tammik
2021-04-20 11:36:21 +02:00
parent 1133a82dc5
commit 7e327986e8
3034 changed files with 1245318 additions and 0 deletions
@@ -0,0 +1,130 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc. All rights reserved.
//
// 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 ITS FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Autodesk;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using System.Windows.Media.Imaging;
using System.Windows;
namespace Revit.SDK.Samples.FreeFormElement.CS
{
/// <summary>
/// Implements the Revit add-in interface IExternalApplication
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Application : IExternalApplication
{
#region IExternalApplication Members
/// <summary>
/// Implements the OnShutdown event
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
/// <summary>
/// Implements the OnStartup event
/// </summary>
/// <param name="application"></param>
/// <returns></returns>
public Result OnStartup(UIControlledApplication application)
{
CreateFreeformElementPanel(application);
return Result.Succeeded;
}
#endregion
/// <summary>
/// Creates the ribbon panel for the sample.
/// </summary>
/// <param name="application">The application.</param>
private void CreateFreeformElementPanel(UIControlledApplication application)
{
RibbonPanel rp = application.CreateRibbonPanel("FreeForm");
PushButtonData freeform = new PushButtonData("Negative_block", "Create negative block",
addAssemblyPath,
typeof(Revit.SDK.Samples.FreeFormElement.CS.CreateNegativeBlockCommand).FullName);
PushButton freeformPB = rp.AddItem(freeform) as PushButton;
SetIconsForPushButton(freeformPB, Revit.SDK.Samples.FreeFormElement.CS.Properties.Resources.CreateNegative);
}
/// <summary>
/// Utility for adding icons to the button.
/// </summary>
/// <param name="button">The push button.</param>
/// <param name="icon">The icon.</param>
private static void SetIconsForPushButton(PushButton button, System.Drawing.Icon icon)
{
button.LargeImage = GetStdIcon(icon);
button.Image = GetSmallIcon(icon);
}
/// <summary>
/// Gets the standard sized icon as a BitmapSource.
/// </summary>
/// <param name="icon">The icon.</param>
/// <returns>The BitmapSource.</returns>
private static BitmapSource GetStdIcon(System.Drawing.Icon icon)
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
/// <summary>
/// Gets the small sized icon as a BitmapSource.
/// </summary>
/// <param name="icon">The icon.</param>
/// <returns>The BitmapSource.</returns>
private static BitmapSource GetSmallIcon(System.Drawing.Icon icon)
{
System.Drawing.Icon smallIcon = new System.Drawing.Icon(icon, new System.Drawing.Size(16, 16));
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
smallIcon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
/// <summary>
/// The path to this add-in assembly.
/// </summary>
static String addAssemblyPath = typeof(Revit.SDK.Samples.FreeFormElement.CS.Application).Assembly.Location;
}
}
@@ -0,0 +1,142 @@
//
// (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 System.Linq;
using System.Text;
using System.Diagnostics;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.FreeFormElement.CS
{
/// <summary>
/// A command to create a new family block representing a negative of a selected element.
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
class CreateNegativeBlockCommand : IExternalCommand
{
#region IExternalCommand Members
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
// Select target element
Reference target = uiDoc.Selection.PickObject(ObjectType.Element,
new TargetElementSelectionFilter(),
"Select target");
Element targetElement = doc.GetElement(target);
// Get height for block based on target element.
BoundingBoxXYZ bbox = targetElement.get_BoundingBox(null);
double height = bbox.Max.Z - bbox.Min.Z + 1;
// Select boundaries
IList<Reference> boundaries = uiDoc.Selection.PickObjects(ObjectType.Element,
new BoundarySelectionFilter(),
"Select boundary");
String familyPath = FreeFormElementUtils.FindGenericModelTemplate(doc.Application.FamilyTemplatePath);
if (String.IsNullOrEmpty(familyPath))
{
message = "Unable to find a template named 'GenericModel.rft' in family template path.";
return Result.Failed;
}
FreeFormElementUtils.FailureCondition condition = FreeFormElementUtils.CreateNegativeBlock(targetElement, boundaries, UIDocument.GetRevitUIFamilyLoadOptions(), familyPath);
// Show error message for failure condition
if (condition != FreeFormElementUtils.FailureCondition.Success)
{
switch (condition)
{
case FreeFormElementUtils.FailureCondition.CurvesNotContigous:
message = "Could not create the block as the boundary curves do not make a contiguous closed boundary.";
break;
case FreeFormElementUtils.FailureCondition.CurveLoopAboveTarget:
message = "Could not create the block as the boundary curves lie above their target element.";
break;
case FreeFormElementUtils.FailureCondition.NoIntersection:
message = "Could not create the block as the curves and the target element does not intersect.";
break;
}
return Result.Failed;
}
return Result.Succeeded;
}
#endregion
}
/// <summary>
/// Selection filter for selection of a target object to use as a template for the negative block.
/// </summary>
class TargetElementSelectionFilter : ISelectionFilter
{
public bool AllowElement(Element element)
{
// Element must have at least one usable solid
IList<Solid> solids = FreeFormElementUtils.GetTargetSolids(element);
return solids.Count > 0;
}
public bool AllowReference(Reference refer, XYZ point)
{
return true;
}
}
/// <summary>
/// Selection filter for selection of the boundary curves for the block extents.
/// </summary>
class BoundarySelectionFilter : ISelectionFilter
{
public bool AllowElement(Element element)
{
// Allow only curve elements
CurveElement curveElement = element as CurveElement;
if (curveElement == null)
return false;
Curve curve = curveElement.GeometryCurve;
// Curves must support the utilities used by the tool (e.g. ReverseCurve)
if (!FreeFormElementUtils.SupportsLoopUtilities(curve))
return false;
// Curves must be in XY plane
return FreeFormElementUtils.IsCurveInXYPlane(curve);
}
public bool AllowReference(Reference refer, XYZ point)
{
return true;
}
}
}
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Application">
<Name>FreeFormElement</Name>
<Assembly>FreeFormElement.dll</Assembly>
<ClientId>bd16f85d-baa4-4b02-84d6-87ecd6361d5f</ClientId>
<FullClassName>Revit.SDK.Samples.FreeFormElement.CS.Application</FullClassName>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,114 @@
<?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>{B0D3B3DA-011A-4215-B06D-E83914C2C237}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Revit.SDK.Samples.FreeFormElement.CS</RootNamespace>
<AssemblyName>FreeFormElement</AssemblyName>
<StartupObject>
</StartupObject>
<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>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Debug\FreeFormElement.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\FreeFormElement.XML</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<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="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="CreateNegativeBlockCommand.cs" />
<Compile Include="FreeFormElementUtils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="..\Generic Model.rft">
<Link>Generic Model.rft</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\CreateNegative.ico" />
</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,353 @@
//
// (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 System.Linq;
using System.Text;
using System.IO;
using Autodesk.Revit.DB;
using RevitFreeFormElement = Autodesk.Revit.DB.FreeFormElement;
namespace Revit.SDK.Samples.FreeFormElement.CS
{
/// <summary>
/// Utilities supporting the creation of a family containing a FreeFormElement which is cut out from existing geometry
/// </summary>
class FreeFormElementUtils
{
public enum FailureCondition
{
Success,
CurvesNotContigous,
CurveLoopAboveTarget,
NoIntersection
};
/// <summary>
/// Creates a negative block family from the geometry of the target element and boundaries.
/// </summary>
/// <remarks>This is the main implementation of the sample command.</remarks>
/// <param name="targetElement">The target solid element.</param>
/// <param name="boundaries">The selected curve element boundaries.</param>
/// <param name="familyLoadOptions">The family load options when loading the new family.</param>
/// <param name="familyTemplate">The family template.</param>
public static FailureCondition CreateNegativeBlock(Element targetElement, IList<Reference> boundaries, IFamilyLoadOptions familyLoadOptions, String familyTemplate)
{
Document doc = targetElement.Document;
Autodesk.Revit.ApplicationServices.Application app = doc.Application;
// Get curve loop for boundary
IList<Curve> curves = GetContiguousCurvesFromSelectedCurveElements(doc, boundaries);
CurveLoop loop = null;
try
{
loop = CurveLoop.Create(curves);
}
catch (Autodesk.Revit.Exceptions.ArgumentException)
{
// Curves are not contiguous
return FailureCondition.CurvesNotContigous;
}
List<CurveLoop> loops = new List<CurveLoop>();
loops.Add(loop);
// Get elevation of loop
double elevation = curves[0].GetEndPoint(0).Z;
// Get height for extrusion
BoundingBoxXYZ bbox = targetElement.get_BoundingBox(null);
double height = bbox.Max.Z - elevation;
if (height <= 1e-5)
return FailureCondition.CurveLoopAboveTarget;
height += 1;
// Create family
Document familyDoc = app.NewFamilyDocument(familyTemplate);
// Create block from boundaries
Solid block = GeometryCreationUtilities.CreateExtrusionGeometry(loops, XYZ.BasisZ, height);
// Subtract target element
IList<Solid> fromElement = GetTargetSolids(targetElement);
int solidCount = fromElement.Count;
// Merge all found solids into single one
Solid toSubtract = null;
if (solidCount == 1)
{
toSubtract = fromElement[0];
}
else if (solidCount > 1)
{
toSubtract =
BooleanOperationsUtils.ExecuteBooleanOperation(fromElement[0], fromElement[1], BooleanOperationsType.Union);
}
if (solidCount > 2)
{
for (int i = 2; i < solidCount; i++)
{
toSubtract = BooleanOperationsUtils.ExecuteBooleanOperation(toSubtract, fromElement[i],
BooleanOperationsType.Union);
}
}
// Subtract merged solid from overall block
try
{
BooleanOperationsUtils.ExecuteBooleanOperationModifyingOriginalSolid(block, toSubtract,
BooleanOperationsType.Difference);
}
catch (Autodesk.Revit.Exceptions.InvalidOperationException)
{
return FailureCondition.NoIntersection;
}
// Create freeform element
using (Transaction t = new Transaction(familyDoc, "Add element"))
{
t.Start();
RevitFreeFormElement element = Autodesk.Revit.DB.FreeFormElement.Create(familyDoc, block);
t.Commit();
}
// Load family into document
Family family = familyDoc.LoadFamily(doc, familyLoadOptions);
familyDoc.Close(false);
// Get symbol as first symbol of loaded family
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.WherePasses(new FamilySymbolFilter(family.Id));
FamilySymbol fs = collector.FirstElement() as FamilySymbol;
// Place instance at location of original curves
using (Transaction t2 = new Transaction(doc, "Place instance"))
{
t2.Start();
if (!fs.IsActive)
fs.Activate();
doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
t2.Commit();
}
return FailureCondition.Success;
}
/// <summary>
/// Gets a list of curves which are ordered correctly and oriented correctly to form a closed loop.
/// </summary>
/// <param name="doc">The document.</param>
/// <param name="boundaries">The list of curve element references which are the boundaries.</param>
/// <returns>The list of curves.</returns>
public static IList<Curve> GetContiguousCurvesFromSelectedCurveElements(Document doc, IList<Reference> boundaries)
{
List<Curve> curves = new List<Curve>();
// Build a list of curves from the curve elements
foreach (Reference reference in boundaries)
{
CurveElement curveElement = doc.GetElement(reference) as CurveElement;
curves.Add(curveElement.GeometryCurve.Clone());
}
// Walk through each curve (after the first) to match up the curves in order
for (int i = 0; i < curves.Count; i++)
{
Curve curve = curves[i];
XYZ endPoint = curve.GetEndPoint(1);
// find curve with start point = end point
for (int j = i + 1; j < curves.Count; j++)
{
// Is there a match end->start, if so this is the next curve
if (curves[j].GetEndPoint(0).IsAlmostEqualTo(endPoint, 1e-05))
{
Curve tmpCurve = curves[i + 1];
curves[i + 1] = curves[j];
curves[j] = tmpCurve;
continue;
}
// Is there a match end->end, if so, reverse the next curve
else if (curves[j].GetEndPoint(1).IsAlmostEqualTo(endPoint, 1e-05))
{
Curve tmpCurve = curves[i + 1];
curves[i + 1] = CreateReversedCurve(curves[j]);
curves[j] = tmpCurve;
continue;
}
}
}
return curves;
}
/// <summary>
/// Utility to create a new curve with the same geometry but in the reverse direction.
/// </summary>
/// <param name="orig">The original curve.</param>
/// <returns>The reversed curve.</returns>
/// <throws cref="NotImplementedException">If the curve type is not supported by this utility.</throws>
private static Curve CreateReversedCurve(Curve orig)
{
if (!SupportsLoopUtilities(orig))
{
throw new NotImplementedException("CreateReversedCurve for type " + orig.GetType().Name);
}
if (orig is Line)
{
return Line.CreateBound(orig.GetEndPoint(1), orig.GetEndPoint(0));
}
else if (orig is Arc)
{
return Arc.Create(orig.GetEndPoint(1), orig.GetEndPoint(0), orig.Evaluate(0.5, true));
}
else
{
throw new Exception("CreateReversedCurve - Unreachable");
}
}
/// <summary>
/// Identifies if the curve type is supported in these utilities.
/// </summary>
/// <param name="curve">The curve.</param>
/// <returns>True if the curve type is supported, false otherwise.</returns>
public static bool SupportsLoopUtilities(Curve curve)
{
return curve is Line || curve is Arc;
}
/// <summary>
/// Identifies if the curve lies entirely in an XY plane (Z = constant)
/// </summary>
/// <param name="curve">The curve.</param>
/// <returns>True if the curve lies in an XY plane, false otherwise.</returns>
public static bool IsCurveInXYPlane(Curve curve)
{
// quick reject - are endpoints at same Z
double zDelta = curve.GetEndPoint(1).Z - curve.GetEndPoint(0).Z;
if (Math.Abs(zDelta) > 1e-05)
return false;
if (!(curve is Line) && !curve.IsCyclic)
{
// Create curve loop from curve and connecting line to get plane
List<Curve> curves = new List<Curve>();
curves.Add(curve);
curves.Add(Line.CreateBound(curve.GetEndPoint(1), curve.GetEndPoint(0)));
CurveLoop curveLoop = CurveLoop.Create(curves);
XYZ normal = curveLoop.GetPlane().Normal.Normalize();
if (!normal.IsAlmostEqualTo(XYZ.BasisZ) && !normal.IsAlmostEqualTo(XYZ.BasisZ.Negate()))
return false;
}
return true;
}
/// <summary>
/// Gets all target solids in a given element.
/// </summary>
/// <remarks>Includes solids and solids in first level instances only. Deeper levels are ignored. Empty solids are not returned.</remarks>
/// <param name="element">The element.</param>
/// <returns>The list of solids.</returns>
public static IList<Solid> GetTargetSolids(Element element)
{
List<Solid> solids = new List<Solid>();
Options options = new Options();
options.DetailLevel = ViewDetailLevel.Fine;
GeometryElement geomElem = element.get_Geometry(options);
foreach (GeometryObject geomObj in geomElem)
{
if (geomObj is Solid)
{
Solid solid = (Solid)geomObj;
if (solid.Faces.Size > 0 && solid.Volume > 0.0)
{
solids.Add(solid);
}
// Single-level recursive check of instances. If viable solids are more than
// one level deep, this example ignores them.
}
else if (geomObj is GeometryInstance)
{
GeometryInstance geomInst = (GeometryInstance)geomObj;
GeometryElement instGeomElem = geomInst.GetInstanceGeometry();
foreach (GeometryObject instGeomObj in instGeomElem)
{
if (instGeomObj is Solid)
{
Solid solid = (Solid)instGeomObj;
if (solid.Faces.Size > 0 && solid.Volume > 0.0)
{
solids.Add(solid);
}
}
}
}
}
return solids;
}
/// <summary>
/// Finds the Generic Model template from the family template directory path, if it exists.
/// </summary>
/// <param name="familyPath">The family template directory path.</param>
/// <returns>The template path, or empty string if not found.</returns>
public static String FindGenericModelTemplate(String familyPath)
{
string hardCodedResult = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(CreateNegativeBlockCommand).Assembly.Location), "Generic Model.rft");
try
{
IEnumerable<string> files = Directory.EnumerateFiles(familyPath, "Generic Model.rft", SearchOption.AllDirectories);
string result = files.FirstOrDefault<string>();
if (!String.IsNullOrEmpty(result))
return result;
files = Directory.EnumerateFiles(familyPath, "Metric Generic Model.rft", SearchOption.AllDirectories);
result = files.FirstOrDefault<string>();
if (!String.IsNullOrEmpty(result))
return result;
return hardCodedResult;
}
catch (Exception)
{
return hardCodedResult;
}
}
}
}
@@ -0,0 +1,55 @@
//
// (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("FreeFormElement")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc. 2014")]
[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("54154732-fc82-415a-ab23-32c4f4672b55")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Revit.SDK.Samples.FreeFormElement.CS.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Revit.SDK.Samples.FreeFormElement.CS.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon CreateNegative {
get {
object obj = ResourceManager.GetObject("CreateNegative", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
}
}
@@ -0,0 +1,124 @@
<?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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="CreateNegative" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\CreateNegative.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.