窗户和门都是FamilyInstance类的实例,FamilyInstance.Host返回它所在墙的Id。
所以可以通过遍历整个模型中的所有窗户,如果当前窗户的Host值和墙的Id相等,那么这个窗户就是我们要获得的。
下面是代码示例(For Revit 2010,如需要请升级代码,需要改动些)。
<code_begin>
//在执行本命令之前,请选择一堵墙,然后执行本命令
public class GetWallFromWindow : IExternalCommand
{
public IExternalCommand.Result Execute(ExternalCommandData revit,
ref string message,
ElementSet elements)
{
string strMsg = "/nElement IDs:/n";
Document doc = revit.Application.ActiveDocument;
Wall wall1 = null;
if (doc.Selection.Elements.Size < 1)
{
message = "请选择一个墙";
return IExternalCommand.Result.Failed;
}
ElementSetIterator iter = doc.Selection.Elements.ForwardIterator();
iter.MoveNext();
wall1 = iter.Current as Wall;
if (wall1 == null)
{
message = "选择的对象不是墙!";
return IExternalCommand.Result.Failed;
}
ElementFilterIterator eIter = doc.get_Elements(typeof(FamilyInstance));
Element eCur = null;
FamilyInstance insWindow = null;
while (eIter.MoveNext())
{
eCur = eIter.Current as Element;
if (eCur.Category.Equals(doc.Settings.Categories.get_Item(BuiltInCategory.OST_Windows)))
{
insWindow = eCur as FamilyInstance;
if (insWindow.Host.UniqueId.Equals(wall1.UniqueId))
{
elements.Insert(insWindow);
strMsg = strMsg + insWindow.Id.Value.ToString() + "/n";
}
}
}
// 找到窗子后,对话框中显示找到的窗户数量。
strMsg = elements.Size.ToString() + " 个窗户在选中的墙中:/n" + strMsg;
MessageBox.Show(strMsg);
return IExternalCommand.Result.Succeeded;
}
}
<code_end>
作者:叶雄进文章来源:http://blog.csdn.net/joexiongjin/article/category/782739
欢迎光临 EaBIM (https://eabim.net/) | Powered by Discuz! X3.2 |