public Element CreatePolygonRailing(XYZ[] pts, ElementId baseLevelId, ElementId familyId) { ElementId RailingTypeId = new FilteredElementCollector(doc) .OfClass(typeof(RailingType)) .ToElementIds().First(); return(Railing.Create(doc, PolygonCurveLoop(pts), RailingTypeId, baseLevelId)); }
private static bool MyCreateRailing(ElementId rId, Document doc, IList <Curve> curs, ElementId leveId) { if (rId != null) { Transaction tr = new Transaction(doc); //创建对象必须添加事务 tr.Start("Railing"); foreach (Curve c in curs) { CurveLoop loop = new CurveLoop(); loop.Append(c); Railing rail = Railing.Create(doc, loop, rId, leveId); } tr.Commit(); return(true); } else { return(false); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; Transaction tran = new Transaction(doc, "ExCom"); tran.Start(); Selection select = uiDoc.Selection; Reference r = select.PickObject(ObjectType.Element, "选择需要检查的墙"); Element column = doc.GetElement(r); FilteredElementCollector collector = new FilteredElementCollector(doc); //使用ElementIntersectFilter冲突检查 ElementIntersectsElementFilter iFilter = new ElementIntersectsElementFilter(column, false); collector.WherePasses(iFilter); List <ElementId> excludes = new List <ElementId> { column.Id }; collector.Excluding(excludes); List <ElementId> ids = new List <ElementId>(); select.SetElementIds(ids); foreach (Element element in collector) { ids.Add(element.Id); } select.SetElementIds(ids); tran.Commit(); CurveLoop curs = null; ElementId rId = null; ElementId leveId = null; Railing rail = Railing.Create(doc, curs, rId, leveId); return(Result.Succeeded); }
public List <ApplicationPlaceholderObject> RailingToNative(BuiltElements.Revit.RevitRailing speckleRailing) { if (speckleRailing.path == null) { throw new Exception("Only line based Railings are currently supported."); } var revitRailing = GetExistingElementByApplicationId(speckleRailing.applicationId) as Railing; var railingType = GetElementType <RailingType>(speckleRailing); Level level = LevelToNative(speckleRailing.level);; var baseCurve = CurveArrayToCurveLoop(CurveToNative(speckleRailing.path)); //if it's a new element, we don't need to update certain properties bool isUpdate = true; if (revitRailing == null) { isUpdate = false; revitRailing = Railing.Create(Doc, baseCurve, railingType.Id, level.Id); } if (revitRailing == null) { ConversionErrors.Add(new Error { message = $"Failed to create railing ${speckleRailing.applicationId}." }); return(null); } if (revitRailing.GetTypeId() != railingType.Id) { revitRailing.ChangeTypeId(railingType.Id); } if (isUpdate) { revitRailing.SetPath(baseCurve); TrySetParam(revitRailing, BuiltInParameter.WALL_BASE_CONSTRAINT, level); } if (speckleRailing.flipped != revitRailing.Flipped) { revitRailing.Flip(); } SetInstanceParameters(revitRailing, speckleRailing); var placeholders = new List <ApplicationPlaceholderObject>() { new ApplicationPlaceholderObject { applicationId = speckleRailing.applicationId, ApplicationGeneratedId = revitRailing.UniqueId, NativeObject = revitRailing } }; Doc.Regenerate(); return(placeholders); }