© 2010 Autodesk
Introduction to Revit 2011 API
Model Creation
Create a Wall
<VB.NET>
    ''  add a door to the center of the given wall.
    Sub AddDoor(ByVal hostWall As Wall)
 
        ''  get the door type to use.
        Dim doorType As FamilySymbol = _
          ElementFiltering.FindFamilyType(m_rvtDoc, GetType(FamilySymbol), _
          "片開", "w900h2000", BuiltInCategory.OST_Doors)
 
        ''  get the start and end points of the wall.
        Dim locCurve As LocationCurve = hostWall.Location
        Dim pt1 As XYZ = locCurve.Curve.EndPoint(0)
        Dim pt2 As XYZ = locCurve.Curve.EndPoint(1)
        ''  calculate the mid point.
        Dim pt As XYZ = (pt1 + pt2) / 2.0
 
        ''  we want to set the reference as a bottom of the wall or level1.
        Dim idLevel1 As ElementId = _
        hostWall.Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId
        Dim level1 As Level = m_rvtDoc.Element(idLevel1)
 
        ''  finally, create a door.
        Dim aDoor As FamilyInstance = m_rvtDoc.Create.NewFamilyInstance( _
        pt, doorType, hostWall, level1, StructuralType.NonStructural)
    End Sub
</VB.NET>
モデルの作成
 ドアの作成
次は、一つの壁の中央にドアを作成します。

このサンプルのAddDoor関数はドアのホストとなる壁を引数としてとります。

先にご紹介したサンプルコードのFindFamilyTypeメソッドで目的のドアのタイプを見つけます。

壁のLocationCurveからドアの配置場所を算出し、壁の“下部の拘束” を組み込みパラメータIDで取得し、NewFamilyInstanceメソッドでドアを作成します。

<モデルの作成デモ>

ではここからはサンプルプロジェクトを見ていきます

次にAddWindow関数で残りの壁に窓をつかします。AddRoof関数では壁の沿って屋根を作成します。

では、実際にこの外部コマンドを実行してみましょう。(“モデルを作成”)

表示>3Dで 3Dビューでみてみます。