添加项目文件。
This commit is contained in:
77
DotNet.Revit.GeometryObject/CmdGeometryObject.cs
Normal file
77
DotNet.Revit.GeometryObject/CmdGeometryObject.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
using DotNet.Revit;
|
||||
|
||||
namespace DotNet.Revit.GeometryObject
|
||||
{
|
||||
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
public class CmdGeometryObject : IExternalCommand
|
||||
{
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
{
|
||||
var uiDoc = commandData.Application.ActiveUIDocument;
|
||||
var doc = uiDoc.Document;
|
||||
|
||||
try
|
||||
{
|
||||
// 选取一个门
|
||||
var refer = uiDoc.Selection.PickObject(ObjectType.Element,
|
||||
new SelectionFilterCommon(m => m.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors));
|
||||
|
||||
var elem = doc.GetElement(refer);
|
||||
var geomObjects = elem.GetGeometryObjects(new Options() { IncludeNonVisibleObjects = true });
|
||||
|
||||
// 获取门的所有有效Solid
|
||||
|
||||
var solids = geomObjects.OfType<Solid>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Result.Failed;
|
||||
}
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通用元素交互选择过滤器.
|
||||
/// </summary>
|
||||
/// <seealso cref="Autodesk.Revit.UI.Selection.ISelectionFilter"/>
|
||||
public class SelectionFilterCommon : ISelectionFilter
|
||||
{
|
||||
private readonly Func<Element, bool> m_Func;
|
||||
|
||||
private readonly Func<Reference, XYZ, bool> m_Func2;
|
||||
|
||||
public SelectionFilterCommon(Func<Element, bool> match, Func<Reference, XYZ, bool> func2)
|
||||
{
|
||||
m_Func = match;
|
||||
|
||||
m_Func2 = func2;
|
||||
}
|
||||
|
||||
public SelectionFilterCommon(Func<Element, bool> match)
|
||||
: this(match, null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool AllowElement(Element elem)
|
||||
{
|
||||
return m_Func == null ? true : m_Func(elem);
|
||||
}
|
||||
|
||||
public bool AllowReference(Reference reference, XYZ position)
|
||||
{
|
||||
return m_Func2 == null ? true : m_Func2(reference, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{61F38117-EB54-46B6-96BB-D62B3E0E599A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DotNet.Revit.GeometryObject</RootNamespace>
|
||||
<AssemblyName>DotNet.Revit.GeometryObject</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</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>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="RevitAPI">
|
||||
<HintPath>..\..\..\..\CYBIM\CYCommons\References\Revit\16\RevitAPI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RevitAPIUI">
|
||||
<HintPath>..\..\..\..\CYBIM\CYCommons\References\Revit\16\RevitAPIUI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CmdGeometryObject.cs" />
|
||||
<Compile Include="GeometryObjectHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
|
||||
-->
|
||||
</Project>
|
||||
74
DotNet.Revit.GeometryObject/GeometryObjectHelper.cs
Normal file
74
DotNet.Revit.GeometryObject/GeometryObjectHelper.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DotNet.Revit
|
||||
{
|
||||
public static class GeometryObjectHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取元素的所有GeomObjects
|
||||
/// </summary>
|
||||
/// <param name="elem">The elem.</param>
|
||||
/// <param name="options">The options.</param>
|
||||
/// <returns></returns>
|
||||
|
||||
public static List<Autodesk.Revit.DB.GeometryObject> GetGeometryObjects(this Element elem, Options options = default(Options))
|
||||
{
|
||||
var result = new List<Autodesk.Revit.DB.GeometryObject>();
|
||||
|
||||
options = options ?? new Options();
|
||||
|
||||
GeometryObjectHelper.RecursionObject(elem.get_Geometry(options), ref result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归遍历所有GeometryObject.
|
||||
/// </summary>
|
||||
/// <param name="geometryElement">初始GeometryElement.</param>
|
||||
/// <param name="geometryObjects">递归结果.</param>
|
||||
|
||||
private static void RecursionObject(this GeometryElement geometryElement, ref List<Autodesk.Revit.DB.GeometryObject> geometryObjects)
|
||||
{
|
||||
if (geometryElement == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var eum = geometryElement.GetEnumerator();
|
||||
|
||||
while (eum.MoveNext())
|
||||
{
|
||||
var current = eum.Current;
|
||||
|
||||
switch (current)
|
||||
{
|
||||
case GeometryInstance instance:
|
||||
instance.SymbolGeometry.RecursionObject(ref geometryObjects);
|
||||
break;
|
||||
|
||||
case GeometryElement elemlemt:
|
||||
elemlemt.RecursionObject(ref geometryObjects);
|
||||
break;
|
||||
|
||||
case Solid solid:
|
||||
if (solid.Edges.Size == 0 || solid.Faces.Size == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
geometryObjects.Add(current);
|
||||
break;
|
||||
|
||||
default:
|
||||
geometryObjects.Add(current);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
DotNet.Revit.GeometryObject/Properties/AssemblyInfo.cs
Normal file
36
DotNet.Revit.GeometryObject/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
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("DotNet.Revit.GeometryObject")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DotNet.Revit.GeometryObject")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[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("9d5b8f0e-fe57-472e-ae69-189201cde20b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user