From d9c1ba9e6943e4557b26992166599a561d28b1b4 Mon Sep 17 00:00:00 2001 From: Jeremy Tammik Date: Mon, 28 Sep 2015 16:19:19 +0200 Subject: [PATCH] added revit online help roof creation sample code --- .../BuildingCoder/CmdNewExtrusionRoof.cs | 81 +++++++++++++++++++ .../BuildingCoder/Properties/AssemblyInfo.cs | 5 +- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/BuildingCoder/BuildingCoder/CmdNewExtrusionRoof.cs b/BuildingCoder/BuildingCoder/CmdNewExtrusionRoof.cs index 6c98b6a7..96793399 100644 --- a/BuildingCoder/BuildingCoder/CmdNewExtrusionRoof.cs +++ b/BuildingCoder/BuildingCoder/CmdNewExtrusionRoof.cs @@ -23,6 +23,87 @@ namespace BuildingCoder [Transaction( TransactionMode.Manual )] class CmdNewExtrusionRoof : IExternalCommand { + #region Revit Online Help sample code from the section on Roofs + void f( Document doc ) + { + // Before invoking this sample, select some walls + // to add a roof over. Make sure there is a level + // named "Roof" in the document. + + Level level + = new FilteredElementCollector( doc ) + .OfClass( typeof( Level ) ) + .Where( e => + !string.IsNullOrEmpty( e.Name ) + && e.Name.Equals( "Roof" ) ) + .FirstOrDefault() as Level; + + RoofType roofType + = new FilteredElementCollector( doc ) + .OfClass( typeof( RoofType ) ) + .FirstOrDefault() as RoofType; + + // Get the handle of the application + Application application = doc.Application; + + // Define the footprint for the roof based on user selection + CurveArray footprint = application.Create + .NewCurveArray(); + + UIDocument uidoc = new UIDocument( doc ); + + ICollection selectedIds + = uidoc.Selection.GetElementIds(); + + if( selectedIds.Count != 0 ) + { + foreach( ElementId id in selectedIds ) + { + Element element = doc.GetElement( id ); + Wall wall = element as Wall; + if( wall != null ) + { + LocationCurve wallCurve = wall.Location as LocationCurve; + footprint.Append( wallCurve.Curve ); + continue; + } + + ModelCurve modelCurve = element as ModelCurve; + if( modelCurve != null ) + { + footprint.Append( modelCurve.GeometryCurve ); + } + } + } + else + { + throw new Exception( + "Please select a curve loop, wall loop or " + + "combination of walls and curves to " + + "create a footprint roof." ); + } + + ModelCurveArray footPrintToModelCurveMapping + = new ModelCurveArray(); + + FootPrintRoof footprintRoof + = doc.Create.NewFootPrintRoof( + footprint, level, roofType, + out footPrintToModelCurveMapping ); + + ModelCurveArrayIterator iterator + = footPrintToModelCurveMapping.ForwardIterator(); + + iterator.Reset(); + while( iterator.MoveNext() ) + { + ModelCurve modelCurve = iterator.Current as ModelCurve; + footprintRoof.set_DefinesSlope( modelCurve, true ); + footprintRoof.set_SlopeAngle( modelCurve, 0.5 ); + } + } + #endregion // Revit Online Help sample code from the section on Roofs + public Result Execute( ExternalCommandData commandData, ref string message, diff --git a/BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs b/BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs index 2fb245c1..d962d4c2 100644 --- a/BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs +++ b/BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs @@ -108,6 +108,7 @@ // 2015-09-04 2016.0.120.12 in EditFilledRegion: use MoveElements instead of MoveElement // 2015-09-14 2016.0.120.14 implemented GetAllModelElements // 2015-09-14 2016.0.120.15 implemented IterateOverCollector +// 2015-09-28 2016.0.120.16 added rof creation sample code from Revit online help sample // -[assembly: AssemblyVersion( "2016.0.120.15" )] -[assembly: AssemblyFileVersion( "2016.0.120.15" )] +[assembly: AssemblyVersion( "2016.0.120.16" )] +[assembly: AssemblyFileVersion( "2016.0.120.16" )]