一、思路
1)在revit中创建一个基于墙的公制常规模型 的族

讯享网
2)为族添加实例参数
我这里只添加了直径参数。

3)将族载入项目中
4)创建族实例
5)修改直径参数

二、代码
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) {
try {
UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; Selection sel = uiDoc.Selection; Autodesk.Revit.Creation.Application acreation = commandData.Application.Application.Create; var creation = doc.Create; Transaction ts = new Transaction(doc, "loadrfa"); ts.Start(); var rfaname = "空心圆";//族类型的名字 FamilySymbol circle = LoadRfa(doc, rfaname); XYZ p0 = new XYZ(30, 0, 0); XYZ p1 = new XYZ(30, 10, 0); XYZ p3 = new XYZ(30, 0, 50); XYZ p2 = new XYZ(30, 10, 50); Curve l1 = Line.CreateBound(p0, p1); Curve l2 = Line.CreateBound(p1, p2); Curve l3 = Line.CreateBound(p2, p3); Curve l4 = Line.CreateBound(p3, p0); var profile = new List<Curve>(); profile.Add(l1); profile.Add(l2); profile.Add(l3); profile.Add(l4); var wall = Wall.Create(doc, profile, true); XYZ insertP = new XYZ(30, 5, 25);//插入的中心点 int d = 1000;//直径 Level lv = Level.Create(doc, 0); CreateCirleHole(doc, insertP, d, lv, wall, circle, "2020"); ts.Commit(); return Result.Succeeded; } catch (Exception ex) {
var r = 0; return Result.Succeeded; } } private FamilySymbol LoadRfa(Document doc, string rfaname) {
FamilySymbol familySymbol = null; var isLoad = CheckLoadRfa(doc, rfaname, out familySymbol); if (!isLoad) {
string familyPath = @"C:\Users\xxx\Desktop\空心圆族.rfa"; Family family = null; bool flag = doc.LoadFamily(familyPath, out family); if (!flag) {
return null; } else {
foreach (ElementId s in family.GetFamilySymbolIds()) {
familySymbol = doc.GetElement(s) as FamilySymbol; if (!familySymbol.IsActive) familySymbol.Activate(); break; } } } return familySymbol; } private bool CheckLoadRfa(Document RevitDoc, string rfaName, out FamilySymbol familySymbol) {
FamilySymbol type = null; ElementFilter categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel); ElementFilter familySymbolFilter = new ElementClassFilter(typeof(FamilySymbol)); LogicalAndFilter andFilter = new LogicalAndFilter(categoryFilter, familySymbolFilter); FilteredElementCollector symbols = new FilteredElementCollector(RevitDoc); symbols = symbols.WherePasses(andFilter); bool symbolFound = false; foreach (FamilySymbol element in symbols) {
if (element.Name == rfaName) {
symbolFound = true; type = element; break; } } familySymbol = type; return symbolFound; } //创建族实例,并修改直径参数 public FamilyInstance CreateCirleHole(Document doc, XYZ insertPt, int d, Level level, Wall wall, FamilySymbol circle) {
try {
FamilyInstance airhole = doc.Create.NewFamilyInstance(insertPt, circle, wall, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); var paramD = airhole.LookupParameter("空心圆直径"); paramD.Set(ConvertToDecimalFeet(d)); return airhole; } catch (Exception ex) {
return null; } }
讯享网
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/68133.html