public void Stream(Type type) { var part = _elem as Part; if (type == typeof(Element) && _elem is Element element) { _data.Add(new MemberSeparatorWithOffset(nameof(PartUtils))); _data.Add(new Bool(nameof(PartUtils.AreElementsValidForCreateParts), PartUtils.AreElementsValidForCreateParts(element.Document, new[] { element.Id }))); _data.Add(new Object(nameof(PartUtils.GetAssociatedPartMaker), PartUtils.GetAssociatedPartMaker(element.Document, element.Id))); _data.Add(new Bool(nameof(PartUtils.HasAssociatedParts), PartUtils.HasAssociatedParts(element.Document, element.Id))); _data.Add(new Bool(nameof(PartUtils.IsValidForCreateParts), PartUtils.IsValidForCreateParts(element.Document, new LinkElementId(element.Id)))); } if (type == typeof(Part) && part != null) { _data.Add(new MemberSeparatorWithOffset(nameof(PartUtils))); _data.Add(new Bool(nameof(PartUtils.ArePartsValidForDivide), PartUtils.ArePartsValidForDivide(part.Document, new[] { part.Id }))); _data.Add(new Bool(nameof(PartUtils.ArePartsValidForMerge), PartUtils.ArePartsValidForMerge(part.Document, new[] { part.Id }))); _data.Add(new Int(nameof(PartUtils.GetChainLengthToOriginal), PartUtils.GetChainLengthToOriginal(part))); var isMergedPart = PartUtils.IsMergedPart(part); _data.Add(new Enumerable(nameof(PartUtils.GetMergedParts), isMergedPart ? PartUtils.GetMergedParts(part) : Array.Empty <ElementId>(), part.Document)); _data.Add(new Bool(nameof(PartUtils.IsMergedPart), isMergedPart)); _data.Add(new Bool(nameof(PartUtils.IsPartDerivedFromLink), PartUtils.IsPartDerivedFromLink(part))); _data.Add(new MemberSeparatorWithOffset(nameof(Part))); _data.Add(new String(nameof(Part.OriginalCategoryId), ((BuiltInCategory)part.OriginalCategoryId.IntegerValue).ToString())); var sourceElementIds = part.GetSourceElementIds().Where(e => e.HostElementId != ElementId.InvalidElementId).Select(e => e.HostElementId).ToList(); _data.Add(new Enumerable(nameof(Part.GetSourceElementIds), sourceElementIds, part.Document)); var sourceCategoryIds = part.GetSourceElementOriginalCategoryIds().Select(e => (BuiltInCategory)e.IntegerValue).ToList(); _data.Add(new EnumerableAsString(nameof(Part.GetSourceElementOriginalCategoryIds), sourceCategoryIds)); } }
/// <summary> /// Identifies if the host element can export the associated parts. /// </summary> /// <param name="hostElement">The host element.</param> /// <returns>True if host element can export the parts and have any associated parts, false otherwise.</returns> public static bool CanExportParts(Element hostElement) { if (hostElement != null && ExporterCacheManager.ExportOptionsCache.ExportParts) { return(PartUtils.HasAssociatedParts(hostElement.Document, hostElement.Id)); } return(false); }
public Result Execute( ExternalCommandData cmdData, ref string msg, ElementSet elems) { Result result = Result.Failed; UIApplication uiApp = cmdData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; Document doc = uiDoc.Document; Transaction transaction = new Transaction(doc); try { string strMsg = "Select walls"; ISelectionFilter filter = new WallSelectionFilter(); IList <Reference> walls = uiDoc.Selection.PickObjects( ObjectType.Element, filter, strMsg); if (walls.Count == 0) { return(result); } List <ElementId> ids = new List <ElementId>(); foreach (Reference reference in walls) { ids.Add(reference.ElementId); } if (!PartUtils.AreElementsValidForCreateParts( doc, ids)) { return(result); } transaction.Start("parts"); // Split walls into parts PartUtils.CreateParts(doc, ids); // Regenerate document to get the part geometry doc.Regenerate(); // Retrieve points from bottom faces of parts List <List <XYZ> > bottomFacesPts = new List <List <XYZ> >(); foreach (ElementId id in ids) { if (!PartUtils.HasAssociatedParts(doc, id)) { continue; } ICollection <ElementId> partIds = PartUtils.GetAssociatedParts( doc, id, true, true); foreach (ElementId partId in partIds) { Element part = doc.GetElement(partId); bottomFacesPts.Add( GetBottomFacePoints(part)); } } // Do not affect the original state of walls transaction.RollBack(); // Draw lines to show the bottom faces of parts transaction.Start(); ModelLineCreator model = new ModelLineCreator(doc); foreach (List <XYZ> bottomFacePts in bottomFacesPts) { for (int i = 1; i < bottomFacePts.Count; ++i) { model.CreateLine(bottomFacePts[i - 1], bottomFacePts[i], true); } if (bottomFacePts.Count > 3) { model.CreateLine(bottomFacePts[0], bottomFacePts[bottomFacePts.Count - 1], true); } } transaction.Commit(); result = Result.Succeeded; } catch (System.Exception e) { msg = e.Message; result = Result.Failed; } return(result); }