|
|
|
次のデモではProximityDetection_WallJoinControlというサンプルをご紹介します。
|
|
|
|
このサンプルにてElementIntersectsElementFilterとElementIntersectsSolidFilter クラスの使用方法をご紹介します。
|
|
|
|
サンプルに含まれるサンプル図面を開いて、サンプルのダイアログを表示します。
|
|
|
|
初めのオペレーションにより、柱と壁の間の交差を見つけます、更に壁の端の近くに位置する他の壁を見つけます。
|
|
|
|
それでは、デスクトップに戻ります。
|
|
|
|
SDKサンプルになります。
|
|
|
|
外部コマンドは既に登録されております。
|
|
|
|
リストより外部コマンドを実行します。ProximityDetection_WallJoinControlをクリックします。
|
|
|
|
Autodesk.Revit.ApplicationServices.Application
application = commandData.Application.Application;
|
|
Autodesk.Revit.DB.Document
document = commandData.Application.ActiveUIDocument.Document;
|
|
ブレークポイントが此処にあります。初期化ステップによりアプリケーションオブジェクトとアクティブドキュメントにアクセスします。
|
|
これにて、アプリケーションオブジェクトへのアクセスができます。
|
|
|
|
ダイアログによりオペレーションを実行します。
|
|
|
|
初めのオペレーションにより壁内の柱を見つけます。
|
|
|
|
クリックしてOKを押します。
|
|
|
|
RefreshTreeviewData("Find
columns in wall",
m_proximityDetection.findColumnsInWall(getAllWalls()));
|
|
ブレークポイントが既に設定されております。
|
|
|
|
ステップ毎に見ていきましょう。
|
|
|
|
private IEnumerable<Wall>
getAllWalls()
|
|
{
|
|
FilteredElementCollector
wallCollector = new FilteredElementCollector(m_doc);
|
|
wallCollector.OfClass(typeof(Wall));
|
|
return
wallCollector.OfType<Wall>();
|
|
}
|
|
初めにフィルターを作成します。壁のフィルターを作成する為にFilteredElementCollectorを使用します。
|
|
これにてモデルの壁全てにアクセスが可能です。
|
|
|
|
// create a
node that place all walls.
|
|
XElement
wallsNode = new XElement("Walls", new XAttribute("Name",
"Walls"));
|
|
try {
|
|
foreach (Wall wall in walls){
|
|
XElement wallNode = new
XElement("Wall", new XAttribute("Name", wall.Name));
|
|
XElement によるノードツリーを作成し、スライドのダイアログの様にアウトプットウィンドウに結果を表示します。
|
|
|
|
FilteredElementCollector
collector = new FilteredElementCollector(m_doc);
|
|
新規FilteredElementCollectorのインスタンスを作成します。
|
|
|
|
List<BuiltInCategory> columnCategories
= new List<BuiltInCategory>();
|
|
columnCategories.Add(BuiltInCategory.OST_Columns);
|
|
columnCategories.Add(BuiltInCategory.OST_StructuralColumns);
|
|
collector.WherePasses(new
ElementMulticategoryFilter(columnCategories));
|
|
柱を見つけます。
|
|
|
|
ElementIntersectsElementFilter
testElementIntersectsElementFilter = new
ElementIntersectsElementFilter(wall);
|
|
collector.WherePasses(testElementIntersectsElementFilter);
|
|
foreach
(Element column in collector){
|
|
columnsNode.Add(new
XElement("column", new XAttribute("Name", column.Name)));
|
|
}
|
|
交差要素フィルターを使用して壁と交差する柱を見つけます。
|
|
|
|
ではモデルに存在する他の壁についても行ってみましょう。
|
|
ブレークポイントを外して、コードを実行します。
|
|
全ての壁の交差する柱を見つけています。(ダイアログボックス)
|
|
|
|
|
|
サンプルコード中の他のオプションを見てみましょう。
|
|
|
|
クリックしてOKを押します。
|
|
|
|
RefreshTreeviewData("Find
walls (nearly joined to) end of walls",
m_proximityDetection.findNearbyWalls(getAllWalls()));
|
|
ブレークポイントから壁を作成していきます。
|
|
|
|
XYZ
wallEndPoint = (wall.Location as LocationCurve).Curve.get_EndPoint(0);
|
|
double
wallHeight =
wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
|
|
壁毎の開始と終了点を見てきます。
|
|
そして、壁の高さにアクセスします。
|
|
|
|
private
FilteredElementCollector nearbyWallsFilter(XYZ point, double height, double
radius)
|
|
ここでは先程ご紹介しましたGeometryCreationUtilityクラスを使用して他の壁とソリッド間の交差を見つけます。
|
|
|
|
List<CurveLoop>
curveloops = new List<CurveLoop>();
|
|
CurveLoop
circle = new CurveLoop();
|
|
circle.Append(m_app.Create.NewArc(point,
radius , 0, Math.PI, XYZ.BasisX, XYZ.BasisY));
|
|
circle.Append(m_app.Create.NewArc(point,
radius , Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY));
|
|
curveloops.Add(circle);
|
|
ここでは2つの曲線で円を作成します。
|
|
|
|
Solid
wallEndCylinder =
GeometryCreationUtilities.CreateExtrusionGeometry(curveloops, XYZ.BasisZ,
height);
|
|
GeometryCreationUtility.CreateExtrusionGeometryメソッドを使用し壁の開始と終了点にて円柱を作成します。
|
|
|
|
FilteredElementCollector
collector = new FilteredElementCollector(m_doc);
|
|
collector.OfCategory(BuiltInCategory.OST_Walls);
|
|
そしてFilteredElementCollectorクラスのインスタンスを作成し、壁のタイプを指定します。
|
|
|
|
ElementIntersectsSolidFilter
testElementIntersectsSolidFilter = new
ElementIntersectsSolidFilter(wallEndCylinder);
|
|
collector.WherePasses(testElementIntersectsSolidFilter);
|
|
ここではもう一つの新規APIであるElementIntersectsSolidFilterクラスを使用します。
|
|
|
|
FilteredElementCollector
collector = nearbyWallsFilter(wallEndPoint, wallHeight, 10.0);
|
|
ここでソリッドフィルターで円柱を渡します。
|
|
|
|
List<ElementId>
exclusions = new List<ElementId>();
|
|
exclusions.Add(wall.Id);
|
|
collector.Excluding(exclusions);
|
|
そして、もとの壁を除外します。
|
|
|
|
IEnumerable<Wall>
nearbyWalls = collector.OfType<Wall>();
|
|
最後に隣接している壁にアクセスします。
|
|
|
|
全ての壁にこの処理をおこないます。ブレークポイントは解除して実行します。
|
|
|
|
全ての隣接している壁の開始と終了点を表示します。(ダイアログボックス)
|
|
|
|
プレゼンテーションに戻ります。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|