FamilyItemFactory クラスには、ファミリ内にフォーム要素(押し出し、回転、スイープ、ブレンドなど)を作成する機能があります。これらの 3D スケッチ フォームの詳細については、「3D スケッチ」のセクションを参照してください。
次の例では、新しい押し出し要素を作成する方法を紹介します。単純な長方形のプロファイルを作成してから、新しく作成した押し出しを新しい位置に移動します。
|
コード領域: 新しい押し出しを作成 |
private Extrusion CreateExtrusion(Autodesk.Revit.DB.Document document, SketchPlane sketchPlane)
{
Extrusion rectExtrusion = null;
// make sure we have a family document
if (true == document.IsFamilyDocument)
{
// define the profile for the extrusion
CurveArrArray curveArrArray = new CurveArrArray();
CurveArray curveArray1 = new CurveArray();
CurveArray curveArray2 = new CurveArray();
CurveArray curveArray3 = new CurveArray();
// create a rectangular profile
XYZ p0 = XYZ.Zero;
XYZ p1 = new XYZ(10, 0, 0);
XYZ p2 = new XYZ(10, 10, 0);
XYZ p3 = new XYZ(0, 10, 0);
Line line1 = Line.CreateBound(p0, p1);
Line line2 = Line.CreateBound(p1, p2);
Line line3 = Line.CreateBound(p2, p3);
Line line4 = Line.CreateBound(p3, p0);
curveArray1.Append(line1);
curveArray1.Append(line2);
curveArray1.Append(line3);
curveArray1.Append(line4);
curveArrArray.Append(curveArray1);
// create solid rectangular extrusion
rectExtrusion = document.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, 10);
if (null != rectExtrusion)
{
// move extrusion to proper place
XYZ transPoint1 = new XYZ(-16, 0, 0);
ElementTransformUtils.MoveElement(document, rectExtrusion.Id, transPoint1);
}
else
{
throw new Exception("Create new Extrusion failed.");
}
}
else
{
throw new Exception("Please open a Family document before invoking this command.");
}
return rectExtrusion;
}
|
次の例では、ファミリ ドキュメントにソリッド卵形プロファイルから新しいスイープを作成する方法を紹介します。
|
コード領域: 新しいスイープを作成 |
private Sweep CreateSweep(Autodesk.Revit.DB.Document document, SketchPlane sketchPlane)
{
Sweep sweep = null;
// make sure we have a family document
if (true == document.IsFamilyDocument)
{
// Define a profile for the sweep
CurveArrArray arrarr = new CurveArrArray();
CurveArray arr = new CurveArray();
// Create an ovoid profile
XYZ pnt1 = new XYZ(0, 0, 0);
XYZ pnt2 = new XYZ(2, 0, 0);
XYZ pnt3 = new XYZ(1, 1, 0);
arr.Append(Arc.Create(pnt2, 1.0d, 0.0d, 180.0d, XYZ.BasisX, XYZ.BasisY));
arr.Append(Arc.Create(pnt1, pnt3, pnt2));
arrarr.Append(arr);
SweepProfile profile = document.Application.Create.NewCurveLoopsProfile(arrarr);
// Create a path for the sweep
XYZ pnt4 = new XYZ(10, 0, 0);
XYZ pnt5 = new XYZ(0, 10, 0);
Curve curve = Line.CreateBound(pnt4, pnt5);
CurveArray curves = new CurveArray();
curves.Append(curve);
// create a solid ovoid sweep
sweep = document.FamilyCreate.NewSweep(true, curves, sketchPlane, profile, 0, ProfilePlaneLocation.Start);
if (null != sweep)
{
// move to proper place
XYZ transPoint1 = new XYZ(11, 0, 0);
ElementTransformUtils.MoveElement(document, sweep.Id, transPoint1);
}
else
{
throw new Exception("Failed to create a new Sweep.");
}
}
else
{
throw new Exception("Please open a Family document before invoking this command.");
}
return sweep;
}
|
図 50: 前の例で作成した卵形スイープ
FreeFormElement クラスを使用すると、入力したソリッドのアウトラインから、非パラメトリック ジオメトリを作成できます。FreeFormElement は、他の組み合わせ可能な要素とともに結合やボイド切り取りに使用できます。要素の平面は、プログラムによってインタラクティブに面の法線方向にオフセットすることができます。ファミリに新しいフォームを作成した後、フォームのサブカテゴリを変更することができます。たとえば、ドア ファミリがある場合に、ドアの複数のサブカテゴリを作成して、ファミリのさまざまなドア タイプに異なるサブカテゴリを割り当てることができます。
次の例では、新しいサブカテゴリを作成し、それにマテリアルを割り当て、最後にそのサブカテゴリをフォームに割り当てる方法を紹介します。
|
コード領域: サブカテゴリを割り当て |
public void AssignSubCategory(Document document, GenericForm extrusion)
{
// create a new subcategory
Category cat = document.OwnerFamily.FamilyCategory;
Category subCat = document.Settings.Categories.NewSubcategory(cat, "NewSubCat");
// create a new material and assign it to the subcategory
ElementId materialId = Material.Create(document, "Wood Material");
subCat.Material = document.GetElement(materialId) as Material;
// assign the subcategory to the element
extrusion.Subcategory = subCat;
}
|