Skip to content

Commit

Permalink
integrated CmdWallOpeningProfiles by Scott Wilson
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Tammik committed Dec 22, 2015
1 parent f8d1491 commit 7db565b
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 6 deletions.
15 changes: 12 additions & 3 deletions BcSamples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,8 @@ C:\a\lib\revit\2016\bc\BuildingCoder\BuildingCoder\bin\Debug\BuildingCoder.dll
BuildingCoder.CmdFlatten # version 2016.0.123.0

ADN Bc R-Z
Wall Openings
Report wall opening start and end points along location line
Wall Opening Side Faces
Determine wall opening side faces and report their start and end points along location line
LargeImage:
Image:
C:\a\lib\revit\2016\bc\BuildingCoder\BuildingCoder\bin\Debug\BuildingCoder.dll
Expand All @@ -1066,4 +1066,13 @@ Determine and report all project parameter GUIDs
LargeImage:
Image:
C:\a\lib\revit\2016\bc\BuildingCoder\BuildingCoder\bin\Debug\BuildingCoder.dll
BuildingCoder.CmdProjectParameterGuids # version 2016.0.125.0
BuildingCoder.CmdProjectParameterGuids # version 2016.0.125.0

ADN Bc R-Z
Wall Opening Profiles
Determine and display all wall opening edges including elevation profile lines
LargeImage:
Image:
C:\a\lib\revit\2016\bc\BuildingCoder\BuildingCoder\bin\Debug\BuildingCoder.dll
BuildingCoder.CmdWallOpeningProfiles # version 2016.0.126.0

1 change: 1 addition & 0 deletions BuildingCoder/BuildingCoder/BuildingCoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
<Compile Include="CmdWallBottomFace.cs" />
<Compile Include="CmdWallFooting.cs" />
<Compile Include="CmdWallLayerVolumes.cs" />
<Compile Include="CmdWallOpeningProfiles.cs" />
<Compile Include="CmdWallOpenings.cs" />
<Compile Include="CmdWallProfileArea.cs" />
<Compile Include="CmdListWalls.cs" />
Expand Down
181 changes: 181 additions & 0 deletions BuildingCoder/BuildingCoder/CmdWallOpeningProfiles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#region Header
//
// CmdWallOpeningProfiles.cs - determine and display all wall opening edges including elevation profile lines
//
// Copyright (C) 2015 by Jeremy Tammik, Autodesk Inc. All rights reserved.
//
#endregion // Header

#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
#endregion // Namespaces

namespace BuildingCoder
{
[Transaction( TransactionMode.Manual )]
class CmdWallOpeningProfiles
{
static List<PlanarFace> GetWallOpeningPlanarFaces(
Wall wall,
ElementId openingId )
{
List<PlanarFace> faceList = new List<PlanarFace>();

List<Solid> solidList = new List<Solid>();

Options geomOptions = wall.Document.Application.Create.NewGeometryOptions();

if( geomOptions != null )
{
geomOptions.ComputeReferences = true;
geomOptions.DetailLevel = ViewDetailLevel.Fine;
geomOptions.IncludeNonVisibleObjects = false;

GeometryElement geoElem = wall.get_Geometry( geomOptions );

if( geoElem != null )
{
foreach( GeometryObject geomObj in geoElem )
{
if( geomObj is Solid )
{
solidList.Add( geomObj as Solid );
}
}
}
}

foreach( Solid solid in solidList )
{
foreach( Face face in solid.Faces )
{
if( face is PlanarFace )
{
if( wall.GetGeneratingElementIds( face ).Any( x => x == openingId ) )
{
faceList.Add( face as PlanarFace );
}
}
}
}
return faceList;
}

public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements )
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;

Result commandResult = Result.Succeeded;

try
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document dbDoc = uiDoc.Document;

List<ElementId> selectedIds = uiDoc.Selection.GetElementIds().ToList();

using( Transaction trans = new Transaction( dbDoc ) )
{
trans.Start( "Cmd: GetOpeningProfiles" );

List<ElementId> newIds = new List<ElementId>();

foreach( ElementId selectedId in selectedIds )
{
Wall wall = dbDoc.GetElement( selectedId ) as Wall;

if( wall != null )
{
List<PlanarFace> faceList = new List<PlanarFace>();

List<ElementId> insertIds = wall.FindInserts( true, false, false, false ).ToList();

foreach( ElementId insertId in insertIds )
{
Element elem = dbDoc.GetElement( insertId );

if( elem is FamilyInstance )
{
FamilyInstance inst = elem as FamilyInstance;

CategoryType catType = inst.Category.CategoryType;
Category cat = inst.Category;

if( catType == CategoryType.Model && ( cat.Id == dbDoc.Settings.Categories.get_Item( BuiltInCategory.OST_Doors ).Id || cat.Id == dbDoc.Settings.Categories.get_Item( BuiltInCategory.OST_Windows ).Id ) )
{
faceList.AddRange( GetWallOpeningPlanarFaces( wall, insertId ) );
}
}
else if( elem is Opening )
{
faceList.AddRange( GetWallOpeningPlanarFaces( wall, insertId ) );
}
}

foreach( PlanarFace face in faceList )
{
Plane facePlane = new Plane( face.ComputeNormal( UV.Zero ), face.Origin );
SketchPlane sketchPlane = SketchPlane.Create( dbDoc, facePlane );

foreach( CurveLoop curveLoop in face.GetEdgesAsCurveLoops() )
{
foreach( Curve curve in curveLoop )
{
ModelCurve modelCurve = dbDoc.Create.NewModelCurve( curve, sketchPlane );
newIds.Add( modelCurve.Id );
}
}
}
}
}

if( newIds.Count > 0 )
{
View activeView = uiDoc.ActiveGraphicalView;
activeView.IsolateElementsTemporary( newIds );
}
trans.Commit();
}
}

#region Exception Handling

catch( Autodesk.Revit.Exceptions.ExternalApplicationException e )
{
message = e.Message;
Debug.WriteLine( "Exception Encountered (Application)\n" + e.Message + "\nStack Trace: " + e.StackTrace );

commandResult = Result.Failed;
}
catch( Autodesk.Revit.Exceptions.OperationCanceledException e )
{
Debug.WriteLine( "Operation cancelled. " + e.Message );
message = "Operation cancelled.";

commandResult = Result.Succeeded;
}
catch( Exception e )
{
message = e.Message;
Debug.WriteLine( "Exception Encountered (General)\n" + e.Message + "\nStack Trace: " + e.StackTrace );

commandResult = Result.Failed;
}

#endregion

return commandResult;
}
}
}
2 changes: 1 addition & 1 deletion BuildingCoder/BuildingCoder/CmdWallOpenings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region Header
//
// CmdWallOpenings.cs - report wall opening start and end points along location line
// CmdWallOpenings.cs - determine wall opening side faces and report their start and end points along location line
//
// Copyright (C) 2015 by Jeremy Tammik, Autodesk Inc. All rights reserved.
//
Expand Down
5 changes: 3 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
// 2015-12-17 2016.0.125.0 integrated CmdProjectParameterGuids by CoderBoy
// 2015-12-17 2016.0.125.1 cleaned up CmdWallOpenings
// 2015-12-18 2016.0.125.2 cleaned up CmdProjectParameterGuids
// 2015-12-18 2016.0.126.0 integrated CmdWallOpeningProfiles by Scott Wilson
//
[assembly: AssemblyVersion( "2016.0.125.2" )]
[assembly: AssemblyFileVersion( "2016.0.125.2" )]
[assembly: AssemblyVersion( "2016.0.126.0" )]
[assembly: AssemblyFileVersion( "2016.0.126.0" )]

0 comments on commit 7db565b

Please sign in to comment.