カーテン パネル ガラス (下に表示) には、専門機器を交差点にスナップして適切に配置するために使用する参照面として、一連の垂直線と水平線があります。
現在、特殊な機器は、呼び出して開発しているプラグインによって配置されておりDocument.Create.NewFamilyInstance
、その位置は、ユーザーが で選択した壁の面から来ていますUIDocument.Selection.PickObject
。ただし、ユーザーが選択した場所に最も近い交点に特殊な機器を正確に配置できるように、コードでこれらの基準線を取得する必要があります。
options.View = _document.Document.ActiveView;
これらの参照面は立面図にのみ表示されることを知っています。これは、立面図ビューでAPIを割り当てて呼び出すことにより、コードでこれらのオブジェクトを探すときに使用しているものですが、作業に最も近いものです。解決策は以下のコードです。問題は、線しか取得できなかったことです (その位置のために参照面を構成していることはわかっています)が、それらを実際の ReferencePlane インスタンスにキャスト/変換する方法が見つかりません。 NewFamilyInstance を呼び出すときに使用します。
それは可能ですか?そうでない場合、特殊な機器が見つけた終値参照に確実にスナップするようにするにはどうすればよいですか?
void FindReferencePlances(ElementId elementId)
{
var fi = _docMan.Document.GetElement(elementId) as FamilyInstance;
var transforms = fi.GetTransform();
string data = string.Empty;
Options options = new Options();
options.IncludeNonVisibleObjects = true;
options.ComputeReferences = true;
options.View = _docMan.Document.ActiveView;
var r = fi.GetFamilyPointPlacementReferences();
foreach (GeometryObject go in
fi.get_Geometry(options))
{
data += " - " +go.GetType().ToString()
+ Environment.NewLine;
if (go is GeometryInstance)
{
GeometryInstance gi = go as GeometryInstance;
foreach (GeometryObject goSymbol in
gi.GetSymbolGeometry())
{
data += " -- " + goSymbol.GetType().ToString()
+ Environment.NewLine;
if (goSymbol is Line)
{
Line line = goSymbol as Line;
data += " --- " + line.GetType().ToString() + " (" + line.Origin.ToString() + ")";
}
}
}
}
TaskDialog.Show("data", data);
}
更新:これが正しい方法かどうかはわかりませんが、オブジェクトを最も近い点の近くに配置できるように、基準面の線からすべての交点を取得する方法を見つけました。以下のコードは重複を削除しません。
public static List<XYZ> FindInstersectionsInReferencePlane(Document doc, ElementId elementId)
{
var fi = doc.GetElement(elementId) as FamilyInstance;
var transforms = fi.GetTransform();
string data = string.Empty;
Options options = new Options();
options.IncludeNonVisibleObjects = true;
options.ComputeReferences = true;
options.View = doc.Document.ActiveView;
var lines = fi.get_Geometry(options)
.Select(x => x as GeometryInstance)
.SelectMany(x => x.GetSymbolGeometry().ToList())
.OfType<Line>()
.ToList();
var results = new List<Tuple<Line, Line, IntersectionResultArray>>();
foreach (var l1 in lines)
{
foreach (var l2 in lines)
{
IntersectionResultArray r = null;
if (l1.Intersect(l2, out r) == SetComparisonResult.Overlap)
results.Add(Tuple.Create(l1, l2, r));
}
}
var points = new List<XYZ>();
foreach (var result in results)
{
foreach (IntersectionResult res in result.Item3)
{
points.Add(res.XYZPoint);
}
}
return points;
}