在墙表面创建开关插座
题:NewFamilyInstance Method (XYZ, FamilySymbol, XYZ, Element, StructuralType) 这个函数是否可以控制插入的FamilyInstance位于host对象的哪一侧?为什么我设置了不能成功呢?类似如附件中的插入开关,如果想要把开关放在墙体的不同侧是否可以通过这个函数实现?
答:
不能用这个重载来创建开关等。因为开关等与面相关,所以需要指定一个面,还要制定位置。建议用这两个重载函数中的一个:
NewFamilyInstance(Face, XYZ, XYZ, FamilySymbol)
NewFamilyInstance(Reference, XYZ, XYZ, FamilySymbol)
下面的代码使用第二个函数创建。根据我的测试结果,第三个参数(方向向量)现在只能为(1,0,0),其它的方向向量很可能无法成功。
view plaincopy
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
usingAutodesk.Revit .DB;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;
public class RevitCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc, "ExComm");
trans.Start();
//find one switch.
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfCategory(BuiltInCategory.OST_ElectricalFixtures).OfClass(typeof(FamilySymbol));
FamilySymbol symbol = null;
if (collector.ToElementIds().Count > 0)
symbol = collector.FirstElement() as FamilySymbol;
//pick face on the wall
Reference refFace = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Face, "pick a face to insert fixture");
Wall hostWall = refFace.Element as Wall;
FamilyInstance instance = doc.Create.NewFamilyInstance(refFace, new XYZ(-32.8382897812364, 27.0035035908784, 13.7299633847192), new XYZ(1, 0, 0), symbol);
trans.Commit();
return Result.Succeeded ;
}
}
作者:叶雄进文章来源:http://blog.csdn.net/joexiongjin/article/category/782739
顶!!!!!!!!!!
页:
[1]