Revit プラットフォーム API の屋根はすべて、RoofBase オブジェクトから作成します。2 つのクラスがあります。
両方に屋根のタイプを取得または設定する RoofType プロパティがあります。この例では、選択した一部の壁に基づいてフットプリント屋根を作成する方法を示します。
コード領域 11-3: フットプリント屋根を作成 |
// Before invoking this sample, select some walls to add a roof over. // Make sure there is a level named "Roof" in the document. // find the Roof level FilteredElementCollector collector = new FilteredElementCollector(document); collector.WherePasses(new ElementClassFilter(typeof(Level))); var elements = from element in collector where element.Name == "Roof" select element; Level level = elements.Cast<Level>().ElementAt<Level>(0); RoofType rooftype = null; // select the first rooftype foreach (RoofType rt in document.RoofTypes) { rooftype = rt; break; } // Get the handle of the application Autodesk.Revit.ApplicationServices.Application application = document.Application; // Define the footprint for the roof based on user selection CurveArray footprint = application.Create.NewCurveArray(); UIDocument uidoc = new UIDocument(document); if (uidoc.Selection.Elements.Size != 0) { foreach (Autodesk.Revit.DB.Element element in uidoc.Selection.Elements) { 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("You should select a curve loop, or a wall loop, or loops combination \nof walls and curves to create a footprint roof."); } ModelCurveArray footPrintToModelCurveMapping = new ModelCurveArray(); FootPrintRoof footprintRoof = document.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); } |
ExtrusionRoof の作成方法に例については、Revit API SDK に含まれる NewRoof サンプル アプリケーションを参照してください。
樋と鼻隠し要素は、屋根を表す HostedSweep クラスから作成します。これらは API から作成、削除、修正することができます。これらの要素を作成するには、Document.Create.NewFascia()または Document.Create.NewGutter()優先のいずれかを使用します。新しい鼻隠しおよび樋の作成方法の例については、SDK サンプルに含まれる NewHostedSweep アプリケーションを参照してください。以下は、樋要素のプロパティを修正できることを示すコードのスニペットです。
コード領域 11-4: 樋を修正 |
public void ModifyGutter(Autodesk.Revit.DB.Document document) { UIDocument uidoc = new UIDocument(document); ElementSet collection = uidoc.Selection.Elements; foreach (Autodesk.Revit.DB.Element elem in collection) { if (elem is Gutter) { Gutter gutter = elem as Gutter; // convert degrees to rads: gutter.Angle = 45.00 * Math.PI / 180; TaskDialog.Show("Revit","Changed gutter angle"); } } } |