//TODO: host railings, where possible private RevitRailing RailingToSpeckle(Railing revitRailing) { var railingType = Doc.GetElement(revitRailing.GetTypeId()) as RailingType; var speckleRailing = new RevitRailing(); //speckleRailing.family = railingType.FamilyName; speckleRailing.type = railingType.Name; speckleRailing.level = ConvertAndCacheLevel(revitRailing, BuiltInParameter.STAIRS_RAILING_BASE_LEVEL_PARAM); speckleRailing.path = CurveListToSpeckle(revitRailing.GetPath()); GetAllRevitParamsAndIds(speckleRailing, revitRailing, new List <string> { "STAIRS_RAILING_BASE_LEVEL_PARAM" }); var mesh = new Geometry.Mesh(); (mesh.faces, mesh.vertices) = GetFaceVertexArrayFromElement(revitRailing, new Options() { DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false }); speckleRailing["@displayMesh"] = mesh; return(speckleRailing); }
private static IList <ElementId> CollectSubElements(Railing railingElem) { IList <ElementId> subElementIds = new List <ElementId>(); if (railingElem != null) { ElementId topRailId = railingElem.TopRail; if (topRailId != ElementId.InvalidElementId) { subElementIds.Add(topRailId); } IList <ElementId> handRailIds = railingElem.GetHandRails(); if (handRailIds != null) { foreach (ElementId handRailId in handRailIds) { HandRail handRail = railingElem.Document.GetElement(handRailId) as HandRail; if (handRail != null) { subElementIds.Add(handRailId); IList <ElementId> supportIds = handRail.GetSupports(); foreach (ElementId supportId in supportIds) { subElementIds.Add(supportId); } } } } } return(subElementIds); }
/// <summary> /// Exports a railing to IFC railing /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="railing"> /// The ceiling element to be exported. /// </param> /// <param name="geomElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The ProductWrapper. /// </param> public static void ExportRailingElement(ExporterIFC exporterIFC, Railing railing, ProductWrapper productWrapper) { if (railing == null) { return; } Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); GeometryElement geomElement = GeometryUtil.GetOneLevelGeometryElement(railing.get_Geometry(geomOptions), 0); // If this is a multistory railing, the geometry will contain all of the levels of railing. We only want one. if (geomElement == null) { return; } string ifcEnumType; IFCExportInfoPair exportType = ExporterUtil.GetProductExportType(exporterIFC, railing, out ifcEnumType); if (exportType.IsUnKnown) { ifcEnumType = ExporterUtil.GetIFCTypeFromExportTable(exporterIFC, railing); } ExportRailing(exporterIFC, railing, geomElement, ifcEnumType, productWrapper); }
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)); }
/// <summary> /// Collects the sub-elements of a Railing, to prevent double export. /// </summary> /// <param name="railingElem"> /// The railing. /// </param> public static void AddSubElementsToCache(Railing railingElem) { IList <ElementId> subElementIds = CollectSubElements(railingElem); foreach (ElementId subElementId in subElementIds) { ExporterCacheManager.RailingSubElementCache.Add(subElementId); } }
/// <summary> /// Exports a railing to IFC railing /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="railing"> /// The ceiling element to be exported. /// </param> /// <param name="geomElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The IFCProductWrapper. /// </param> public static void ExportRailingElement(ExporterIFC exporterIFC, Railing railing, IFCProductWrapper productWrapper) { if (railing == null) { return; } Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); GeometryElement geomElement = GeometryUtil.GetOneLevelGeometryElement(railing.get_Geometry(geomOptions)); // If this is a multistory railing, the geometry will contain all of the levels of railing. We only want one. if (geomElement == null) { return; } string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, railing); ExportRailing(exporterIFC, railing, geomElement, ifcEnumType, productWrapper); }
//TODO: host railings, where possible private RevitRailing RailingToSpeckle(Railing revitRailing) { var railingType = Doc.GetElement(revitRailing.GetTypeId()) as RailingType; var speckleRailing = new RevitRailing(); //speckleRailing.family = railingType.FamilyName; speckleRailing.type = railingType.Name; speckleRailing.level = ConvertAndCacheLevel(revitRailing, BuiltInParameter.STAIRS_RAILING_BASE_LEVEL_PARAM); speckleRailing.path = CurveListToSpeckle(revitRailing.GetPath()); GetAllRevitParamsAndIds(speckleRailing, revitRailing, new List <string> { "STAIRS_RAILING_BASE_LEVEL_PARAM" }); speckleRailing.displayMesh = GetElementDisplayMesh(revitRailing, new Options() { DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false }); //Report.Log($"Converted Railing {revitRailing.Id}"); return(speckleRailing); }
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); }
private static ElementId GetStairOrRampHostId(ExporterIFC exporterIFC, Railing railingElem) { ElementId returnHostId = ElementId.InvalidElementId; if (railingElem == null) { return(returnHostId); } ElementId hostId = railingElem.HostId; if (hostId == ElementId.InvalidElementId) { return(returnHostId); } if (!ExporterCacheManager.StairRampContainerInfoCache.ContainsStairRampContainerInfo(hostId)) { return(returnHostId); } Element host = railingElem.Document.GetElement(hostId); if (host == null) { return(returnHostId); } if (!(host is Stairs) && !StairsExporter.IsLegacyStairs(host) && !RampExporter.IsRamp(host)) { return(returnHostId); } returnHostId = hostId; return(returnHostId); }
private static ElementId GetStairOrRampHostId(ExporterIFC exporterIFC, Railing railingElem) { ElementId returnHostId = ElementId.InvalidElementId; if (railingElem == null) return returnHostId; ElementId hostId = railingElem.HostId; if (hostId == ElementId.InvalidElementId) return returnHostId; if (!ExporterCacheManager.StairRampContainerInfoCache.ContainsStairRampContainerInfo(hostId)) return returnHostId; Element host = railingElem.Document.GetElement(hostId); if (host == null) return returnHostId; if (!(host is Stairs) && !StairsExporter.IsLegacyStairs(host) && !RampExporter.IsRamp(host)) return returnHostId; returnHostId = hostId; return returnHostId; }
/// <summary> /// Collects the sub-elements of a Railing, to prevent double export. /// </summary> /// <param name="railingElem"> /// The railing. /// </param> public static void AddSubElementsToCache(Railing railingElem) { IList<ElementId> subElementIds = CollectSubElements(railingElem); foreach (ElementId subElementId in subElementIds) ExporterCacheManager.RailingSubElementCache.Add(subElementId); }
private static IList<ElementId> CollectSubElements(Railing railingElem) { IList<ElementId> subElementIds = new List<ElementId>(); if (railingElem != null) { ElementId topRailId = railingElem.TopRail; if (topRailId != ElementId.InvalidElementId) subElementIds.Add(topRailId); IList<ElementId> handRailIds = railingElem.GetHandRails(); if (handRailIds != null) { foreach (ElementId handRailId in handRailIds) { HandRail handRail = railingElem.Document.GetElement(handRailId) as HandRail; if (handRail != null) { subElementIds.Add(handRailId); IList<ElementId> supportIds = handRail.GetSupports(); foreach (ElementId supportId in supportIds) { subElementIds.Add(supportId); } } } } } return subElementIds; }
/// <summary> /// Exports a railing to IFC railing /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="railing"> /// The ceiling element to be exported. /// </param> /// <param name="geomElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The ProductWrapper. /// </param> public static void ExportRailingElement(ExporterIFC exporterIFC, Railing railing, ProductWrapper productWrapper) { if (railing == null) return; Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); GeometryElement geomElement = GeometryUtil.GetOneLevelGeometryElement(railing.get_Geometry(geomOptions)); // If this is a multistory railing, the geometry will contain all of the levels of railing. We only want one. if (geomElement == null) return; string ifcEnumType = ExporterUtil.GetIFCTypeFromExportTable(exporterIFC, railing); ExportRailing(exporterIFC, railing, geomElement, ifcEnumType, productWrapper); }
/// <summary> /// Exports an element as IFC railing. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="element"> /// The element to be exported. /// </param> /// <param name="geometryElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The ProductWrapper. /// </param> public static void ExportRailing(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, ProductWrapper productWrapper) { // Check the intended IFC entity or type name is in the exclude list specified in the UI Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcRailing; if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } ElementType elemType = element.Document.GetElement(element.GetTypeId()) as ElementType; IFCFile file = exporterIFC.GetFile(); Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); using (IFCTransaction transaction = new IFCTransaction(file)) { using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element)) { using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData()) { IFCAnyHandle localPlacement = setter.LocalPlacement; StairRampContainerInfo stairRampInfo = null; ElementId hostId = GetStairOrRampHostId(exporterIFC, element as Railing); Transform inverseTrf = Transform.Identity; if (hostId != ElementId.InvalidElementId) { stairRampInfo = ExporterCacheManager.StairRampContainerInfoCache.GetStairRampContainerInfo(hostId); IFCAnyHandle stairRampLocalPlacement = stairRampInfo.LocalPlacements[0]; Transform relTrf = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(stairRampLocalPlacement, localPlacement); inverseTrf = relTrf.Inverse; IFCAnyHandle railingLocalPlacement = ExporterUtil.CreateLocalPlacement(file, stairRampLocalPlacement, inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX); localPlacement = railingLocalPlacement; } ecData.SetLocalPlacement(localPlacement); SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geomElem); IList <Solid> solids = solidMeshInfo.GetSolids(); IList <Mesh> meshes = solidMeshInfo.GetMeshes(); Railing railingElem = element as Railing; IList <ElementId> subElementIds = CollectSubElements(railingElem); foreach (ElementId subElementId in subElementIds) { Element subElement = railingElem.Document.GetElement(subElementId); if (subElement != null) { GeometryElement subElementGeom = GeometryUtil.GetOneLevelGeometryElement(subElement.get_Geometry(geomOptions), 0); SolidMeshGeometryInfo subElementSolidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(subElementGeom); IList <Solid> subElementSolids = subElementSolidMeshInfo.GetSolids(); IList <Mesh> subElementMeshes = subElementSolidMeshInfo.GetMeshes(); foreach (Solid subElementSolid in subElementSolids) { solids.Add(subElementSolid); } foreach (Mesh subElementMesh in subElementMeshes) { meshes.Add(subElementMesh); } } } ElementId catId = CategoryUtil.GetSafeCategoryId(element); BodyData bodyData = null; BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.Medium); //bodyExporterOptions.UseGroupsIfPossible = true; //bodyExporterOptions.UseMappedGeometriesIfPossible = true; if (solids.Count > 0 || meshes.Count > 0) { bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, solids, meshes, bodyExporterOptions, ecData); } else { IList <GeometryObject> geomlist = new List <GeometryObject>(); geomlist.Add(geomElem); bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, geomlist, bodyExporterOptions, ecData); } IFCAnyHandle bodyRep = bodyData.RepresentationHnd; if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep)) { if (ecData != null) { ecData.ClearOpenings(); } return; } IList <IFCAnyHandle> representations = new List <IFCAnyHandle>(); representations.Add(bodyRep); IList <GeometryObject> geomObjects = new List <GeometryObject>(); foreach (Solid solid in solids) { geomObjects.Add(solid); } foreach (Mesh mesh in meshes) { geomObjects.Add(mesh); } Transform boundingBoxTrf = (bodyData.OffsetTransform != null) ? bodyData.OffsetTransform.Inverse : Transform.Identity; boundingBoxTrf = inverseTrf.Multiply(boundingBoxTrf); IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geomObjects, boundingBoxTrf); if (boundingBoxRep != null) { representations.Add(boundingBoxRep); } IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; string instanceGUID = GUIDUtil.CreateGUID(element); //string railingType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType); IFCAnyHandle railing = IFCInstanceExporter.CreateRailing(exporterIFC, element, instanceGUID, ownerHistory, ecData.GetLocalPlacement(), prodRep, ifcEnumType); bool associateToLevel = (hostId == ElementId.InvalidElementId); productWrapper.AddElement(element, railing, setter, ecData, associateToLevel); OpeningUtil.CreateOpeningsIfNecessary(railing, element, ecData, bodyData.OffsetTransform, exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper); CategoryUtil.CreateMaterialAssociation(exporterIFC, railing, bodyData.MaterialIds); // Create multi-story duplicates of this railing. if (stairRampInfo != null) { stairRampInfo.AddComponent(0, railing); List <IFCAnyHandle> stairHandles = stairRampInfo.StairOrRampHandles; for (int ii = 1; ii < stairHandles.Count; ii++) { IFCAnyHandle railingLocalPlacement = stairRampInfo.LocalPlacements[ii]; if (!IFCAnyHandleUtil.IsNullOrHasNoValue(railingLocalPlacement)) { IFCAnyHandle railingHndCopy = CopyRailingHandle(exporterIFC, element, catId, railingLocalPlacement, railing); stairRampInfo.AddComponent(ii, railingHndCopy); productWrapper.AddElement(element, railingHndCopy, (IFCLevelInfo)null, ecData, false); CategoryUtil.CreateMaterialAssociation(exporterIFC, railingHndCopy, bodyData.MaterialIds); } } ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(hostId, stairRampInfo); } } transaction.Commit(); } } }
void BtnApplyClick(object sender, EventArgs e) { Level curLevel = m_levels.ElementAt(cbLevel.SelectedIndex); //cbLevel.Text; // TaskDialog.Show("Current selected Level", curLevel.Name); IEnumerable <Element> Allelem = JtElementExtensionMethods.SelectAllPhysicalElements(m_doc); List <ElementId> eIds = new List <ElementId>(); Parameter a1, a2, a3, a4, a5, a6, a7; IEnumerator <Element> a = Allelem.GetEnumerator(); while (a.MoveNext()) { Element e1 = a.Current; a1 = e1.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM); a2 = e1.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM); a3 = e1.get_Parameter(BuiltInParameter.LEVEL_PARAM); a4 = e1.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT); a5 = e1.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM); a6 = e1.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM); a7 = e1.get_Parameter(BuiltInParameter.STAIRS_RAILING_BASE_LEVEL_PARAM); try { if (null != a1) { Level a1_Level = m_doc.GetElement(a1.AsElementId()) as Level; if (a1_Level.Id != curLevel.Id) { //m_uidoc.ActiveView.HideElementTemporary(e1.Id); eIds.Add(e1.Id); } } if (null != a2) { Level a2_Level = m_doc.GetElement(a2.AsElementId()) as Level; if (a2_Level.Id != curLevel.Id) { //m_uidoc.ActiveView.HideElementTemporary(e1.Id); eIds.Add(e1.Id); } } if (null != a3) { Level a3_Level = m_doc.GetElement(a3.AsElementId()) as Level; if (a3_Level.Id != curLevel.Id) { //m_uidoc.ActiveView.HideElementTemporary(e1.Id); eIds.Add(e1.Id); } } if (null != a4) { Level a4_Level = m_doc.GetElement(a4.AsElementId()) as Level; if (a4_Level.Id != curLevel.Id) { //m_uidoc.ActiveView.HideElementTemporary(e1.Id); eIds.Add(e1.Id); } } if (null != a5) { Level a5_Level = m_doc.GetElement(a5.AsElementId()) as Level; if (a5_Level.Id != curLevel.Id) { //m_uidoc.ActiveView.HideElementTemporary(e1.Id); eIds.Add(e1.Id); } } if (null != a6) { Level a6_Level = m_doc.GetElement(a6.AsElementId()) as Level; if (a6_Level.Id != curLevel.Id) { //m_uidoc.ActiveView.HideElementTemporary(e1.Id); eIds.Add(e1.Id); } } if (null != a7) { Railing e2 = e1 as Railing; if (e2.HasHost) { Element e3 = m_doc.GetElement(e2.HostId); a7 = e3.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM); } Level a7_Level = m_doc.GetElement(a7.AsElementId()) as Level; if (a7_Level.Id != curLevel.Id) { //m_uidoc.ActiveView.HideElementTemporary(e1.Id); eIds.Add(e1.Id); } } // try // { } catch (Exception) { //TaskDialog.Show("Exception", ex.ToString()); } } m_uidoc.ActiveView.HideElements(eIds); m_uidoc.RefreshActiveView(); this.Close(); }
/// <summary> /// Exports an element as IFC railing. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="element"> /// The element to be exported. /// </param> /// <param name="geometryElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The IFCProductWrapper. /// </param> public static void ExportRailing(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, IFCProductWrapper productWrapper) { ElementType elemType = element.Document.GetElement(element.GetTypeId()) as ElementType; IFCFile file = exporterIFC.GetFile(); Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); using (IFCTransaction transaction = new IFCTransaction(file)) { using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element)) { using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData()) { ecData.SetLocalPlacement(setter.GetPlacement()); SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSolidMeshGeometry(geomElem, Transform.Identity); IList <Solid> solids = solidMeshInfo.GetSolids(); IList <Mesh> meshes = solidMeshInfo.GetMeshes(); Railing railingElem = element as Railing; IList <ElementId> subElementIds = CollectSubElements(railingElem); foreach (ElementId subElementId in subElementIds) { Element subElement = railingElem.Document.GetElement(subElementId); if (subElement != null) { GeometryElement subElementGeom = GeometryUtil.GetOneLevelGeometryElement(subElement.get_Geometry(geomOptions)); SolidMeshGeometryInfo subElementSolidMeshInfo = GeometryUtil.GetSolidMeshGeometry(subElementGeom, Transform.Identity); IList <Solid> subElementSolids = subElementSolidMeshInfo.GetSolids(); IList <Mesh> subElementMeshes = subElementSolidMeshInfo.GetMeshes(); foreach (Solid subElementSolid in subElementSolids) { solids.Add(subElementSolid); } foreach (Mesh subElementMesh in subElementMeshes) { meshes.Add(subElementMesh); } } } ElementId catId = CategoryUtil.GetSafeCategoryId(element); BodyData bodyData = null; BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true); //bodyExporterOptions.UseGroupsIfPossible = true; //bodyExporterOptions.UseMappedGeometriesIfPossible = true; bodyExporterOptions.TessellationLevel = BodyExporterOptions.BodyTessellationLevel.Coarse; if (solids.Count > 0 || meshes.Count > 0) { bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId, solids, meshes, bodyExporterOptions, ecData); } else { IList <GeometryObject> geomlist = new List <GeometryObject>(); geomlist.Add(geomElem); bodyData = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, catId, geomlist, bodyExporterOptions, ecData); } IFCAnyHandle bodyRep = bodyData.RepresentationHnd; if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep)) { if (ecData != null) { ecData.ClearOpenings(); } return; } IList <IFCAnyHandle> representations = new List <IFCAnyHandle>(); representations.Add(bodyRep); IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations); IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle(); string instanceGUID = ExporterIFCUtils.CreateGUID(element); string origInstanceName = exporterIFC.GetName(); string instanceName = NamingUtil.GetNameOverride(element, origInstanceName); string instanceDescription = NamingUtil.GetDescriptionOverride(element, null); string instanceObjectType = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName()); string instanceElemId = NamingUtil.CreateIFCElementId(element); Toolkit.IFCRailingType railingType = GetIFCRailingType(element, ifcEnumType); IFCAnyHandle railing = IFCInstanceExporter.CreateRailing(file, instanceGUID, ownerHistory, instanceName, instanceDescription, instanceObjectType, ecData.GetLocalPlacement(), prodRep, instanceElemId, railingType); ElementId hostId = GetStairOrRampHostId(exporterIFC, element as Railing); bool associateToLevel = (hostId == ElementId.InvalidElementId) && LevelUtil.AssociateElementToLevel(element); productWrapper.AddElement(railing, setter, ecData, associateToLevel); OpeningUtil.CreateOpeningsIfNecessary(railing, element, ecData, exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper); CategoryUtil.CreateMaterialAssociations(element.Document, exporterIFC, railing, bodyData.MaterialIds); // Create multi-story duplicates of this railing. if (hostId != ElementId.InvalidElementId) { StairRampContainerInfo stairRampInfo = ExporterCacheManager.StairRampContainerInfoCache.GetStairRampContainerInfo(hostId); stairRampInfo.AddComponent(0, railing); List <IFCAnyHandle> stairHandles = stairRampInfo.StairOrRampHandles; for (int ii = 1; ii < stairHandles.Count; ii++) { IFCAnyHandle railingLocalPlacement = stairRampInfo.LocalPlacements[ii]; if (!IFCAnyHandleUtil.IsNullOrHasNoValue(railingLocalPlacement)) { IFCAnyHandle railingHndCopy = CopyRailingHandle(exporterIFC, element, catId, railingLocalPlacement, railing); stairRampInfo.AddComponent(ii, railingHndCopy); productWrapper.AddElement(railingHndCopy, (IFCLevelInfo)null, ecData, false); CategoryUtil.CreateMaterialAssociations(element.Document, exporterIFC, railingHndCopy, bodyData.MaterialIds); } } ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(hostId, stairRampInfo); } PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper); } transaction.Commit(); } } }
/// <summary> /// Exports an element as IFC railing. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="element"> /// The element to be exported. /// </param> /// <param name="geometryElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The ProductWrapper. /// </param> public static void ExportRailing(ExporterIFC exporterIFC, Element element, GeometryElement geomElem, string ifcEnumType, ProductWrapper productWrapper) { // Check the intended IFC entity or type name is in the exclude list specified in the UI Common.Enums.IFCEntityType elementClassTypeEnum = Common.Enums.IFCEntityType.IfcRailing; if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } ElementType elemType = element.Document.GetElement(element.GetTypeId()) as ElementType; IFCFile file = exporterIFC.GetFile(); Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); using (IFCTransaction transaction = new IFCTransaction(file)) { // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd)) { using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData()) { IFCAnyHandle localPlacement = setter.LocalPlacement; StairRampContainerInfo stairRampInfo = null; ElementId hostId = GetStairOrRampHostId(exporterIFC, element as Railing); Transform inverseTrf = Transform.Identity; if (hostId != ElementId.InvalidElementId) { stairRampInfo = ExporterCacheManager.StairRampContainerInfoCache.GetStairRampContainerInfo(hostId); IFCAnyHandle stairRampLocalPlacement = stairRampInfo.LocalPlacements[0]; Transform relTrf = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(stairRampLocalPlacement, localPlacement); inverseTrf = relTrf.Inverse; IFCAnyHandle railingLocalPlacement = ExporterUtil.CreateLocalPlacement(file, stairRampLocalPlacement, inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX); localPlacement = railingLocalPlacement; } ecData.SetLocalPlacement(localPlacement); SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geomElem); IList <Solid> solids = solidMeshInfo.GetSolids(); IList <Mesh> meshes = solidMeshInfo.GetMeshes(); IList <GeometryObject> gObjs = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(element.Document, exporterIFC, ref solids, ref meshes); Railing railingElem = element as Railing; IList <ElementId> subElementIds = CollectSubElements(railingElem); foreach (ElementId subElementId in subElementIds) { Element subElement = railingElem.Document.GetElement(subElementId); if (subElement != null) { GeometryElement allLevelsGeometry = subElement.get_Geometry(geomOptions); var oneLevelGeom = GeometryUtil.GetOneLevelGeometryElement(allLevelsGeometry, 0); GeometryElement subElementGeom = oneLevelGeom.element; // Get rail terminations geometry List <GeometryElement> overallGeometry = GeometryUtil.GetAdditionalOneLevelGeometry(allLevelsGeometry, oneLevelGeom.symbolId); overallGeometry.Add(subElementGeom); foreach (GeometryElement subGeomentry in overallGeometry) { SolidMeshGeometryInfo subElementSolidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(subGeomentry); IList <Solid> subElemSolids = subElementSolidMeshInfo.GetSolids(); IList <Mesh> subElemMeshes = subElementSolidMeshInfo.GetMeshes(); IList <GeometryObject> partGObjs = FamilyExporterUtil.RemoveInvisibleSolidsAndMeshes(element.Document, exporterIFC, ref subElemSolids, ref subElemMeshes); foreach (Solid subElSolid in subElemSolids) { solids.Add(subElSolid); } foreach (Mesh subElMesh in subElemMeshes) { meshes.Add(subElMesh); } } } } ElementId catId = CategoryUtil.GetSafeCategoryId(element); BodyData bodyData = null; BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.Medium); if (solids.Count > 0 || meshes.Count > 0) { bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, solids, meshes, bodyExporterOptions, ecData); } else { IList <GeometryObject> geomlist = new List <GeometryObject>(); geomlist.Add(geomElem); bodyData = BodyExporter.ExportBody(exporterIFC, element, catId, ElementId.InvalidElementId, geomlist, bodyExporterOptions, ecData); } IFCAnyHandle bodyRep = bodyData.RepresentationHnd; if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep)) { if (ecData != null) { ecData.ClearOpenings(); } return; } IList <IFCAnyHandle> representations = new List <IFCAnyHandle>(); representations.Add(bodyRep); IList <GeometryObject> geomObjects = new List <GeometryObject>(solids); foreach (Mesh mesh in meshes) { geomObjects.Add(mesh); } Transform boundingBoxTrf = (bodyData.OffsetTransform != null) ? bodyData.OffsetTransform.Inverse : Transform.Identity; boundingBoxTrf = inverseTrf.Multiply(boundingBoxTrf); IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geomObjects, boundingBoxTrf); if (boundingBoxRep != null) { representations.Add(boundingBoxRep); } IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; string instanceGUID = GUIDUtil.CreateGUID(element); IFCExportInfoPair exportInfo = ExporterUtil.GetProductExportType(exporterIFC, element, out ifcEnumType); IFCAnyHandle railing = IFCInstanceExporter.CreateGenericIFCEntity(exportInfo, exporterIFC, element, instanceGUID, ownerHistory, ecData.GetLocalPlacement(), prodRep); bool associateToLevel = (hostId == ElementId.InvalidElementId); productWrapper.AddElement(element, railing, setter, ecData, associateToLevel, exportInfo); OpeningUtil.CreateOpeningsIfNecessary(railing, element, ecData, bodyData.OffsetTransform, exporterIFC, ecData.GetLocalPlacement(), setter, productWrapper); IFCAnyHandle singleMaterialOverrideHnd = null; IList <ElementId> matIds = null; ElementId defaultMatId = ElementId.InvalidElementId; ElementId matId = CategoryUtil.GetBaseMaterialIdForElement(element); // Get IfcSingleMaterialOverride to work for railing singleMaterialOverrideHnd = ExporterUtil.GetSingleMaterial(exporterIFC, element, matId); if (singleMaterialOverrideHnd != null) { matIds = new List <ElementId> { matId }; } else { matIds = bodyData.MaterialIds; defaultMatId = matIds[0]; // Check if all the items are the same, then get the first material id if (matIds.All(x => x == defaultMatId)) { matIds = new List <ElementId> { defaultMatId }; } } CategoryUtil.CreateMaterialAssociationWithShapeAspect(exporterIFC, element, railing, bodyData.RepresentationItemInfo); // Create multi-story duplicates of this railing. if (stairRampInfo != null) { stairRampInfo.AddComponent(0, railing); List <IFCAnyHandle> stairHandles = stairRampInfo.StairOrRampHandles; int levelCount = stairHandles.Count; if (levelCount > 0 && railingElem != null) { Stairs stairs = railingElem.Document.GetElement(railingElem.HostId) as Stairs; if ((stairs?.MultistoryStairsId ?? ElementId.InvalidElementId) != ElementId.InvalidElementId) { // If the railing is hosted by stairs, don't use stairHandles.Count, // use ids (count) of levels the railing is placed on. ISet <ElementId> multistoryStairsPlacementLevels = railingElem.GetMultistoryStairsPlacementLevels(); if (multistoryStairsPlacementLevels != null) { levelCount = multistoryStairsPlacementLevels.Count; } } } for (int ii = 1; ii < levelCount; ii++) { IFCAnyHandle railingLocalPlacement = stairRampInfo.LocalPlacements[ii]; if (!IFCAnyHandleUtil.IsNullOrHasNoValue(railingLocalPlacement)) { IFCAnyHandle railingHndCopy = CopyRailingHandle(exporterIFC, element, catId, railingLocalPlacement, railing, ii); stairRampInfo.AddComponent(ii, railingHndCopy); productWrapper.AddElement(element, railingHndCopy, (IFCLevelInfo)null, ecData, false, exportInfo); CategoryUtil.CreateMaterialAssociationWithShapeAspect(exporterIFC, element, railingHndCopy, bodyData.RepresentationItemInfo); } } ExporterCacheManager.StairRampContainerInfoCache.AddStairRampContainerInfo(hostId, stairRampInfo); } } transaction.Commit(); } } }
void BtnApplyClick(object sender, EventArgs e) { Level curLevel = m_levels.ElementAt(cbLevel.SelectedIndex); IEnumerable <Element> Allelem = JtElementExtensionMethods.SelectAllPhysicalElements(m_doc); List <ElementId> eIds = new List <ElementId>(); Parameter p; IEnumerator <Element> a = Allelem.GetEnumerator(); List <BuiltInParameter> bip1 = new List <BuiltInParameter>() { BuiltInParameter.FAMILY_BASE_LEVEL_PARAM, BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM, BuiltInParameter.SCHEDULE_LEVEL_PARAM, BuiltInParameter.WALL_BASE_CONSTRAINT, BuiltInParameter.FAMILY_LEVEL_PARAM, BuiltInParameter.STAIRS_BASE_LEVEL_PARAM, BuiltInParameter.ROOF_BASE_LEVEL_PARAM }; List <BuiltInParameter> bip2 = new List <BuiltInParameter>() { BuiltInParameter.STAIRS_RAILING_BASE_LEVEL_PARAM //Should set host in bip3 }; List <BuiltInParameter> bip3 = new List <BuiltInParameter>() { BuiltInParameter.STAIRS_BASE_LEVEL_PARAM //Hosts for bip2 }; while (a.MoveNext()) { Element e1 = a.Current; try { foreach (BuiltInParameter bip in bip1) { p = e1.get_Parameter(bip); if (null != p) { Level p_Level = m_doc.GetElement(p.AsElementId()) as Level; if (null != p_Level) { if (p_Level.Id != curLevel.Id) { eIds.Add(e1.Id); } } } } for (int i = 0; i < bip2.Count; i++) { p = e1.get_Parameter(bip2[i]); if (null != p) { Railing e2 = e1 as Railing; if (e2.HasHost) { Element e3 = m_doc.GetElement(e2.HostId); p = e3.get_Parameter(bip3[i]); } Level a7_Level = m_doc.GetElement(p.AsElementId()) as Level; if (null != a7_Level) { if (a7_Level.Id != curLevel.Id) { eIds.Add(e1.Id); } } } } } catch (Exception ex) { TaskDialog.Show("Exception", ex.ToString()); } } BtnShowAllClick(sender, e); using (Transaction t = new Transaction(m_doc, "Hide element")) { t.Start(); this.Hide(); m_uidoc.ActiveView.HideElements(eIds); m_uidoc.RefreshActiveView(); t.Commit(); } this.Show(); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; //因為樓層數會影響一些標準的高度,所以先把樓層高度找出來 FilteredElementCollector levelCollector = new FilteredElementCollector(doc); ElementCategoryFilter levelFilter = new ElementCategoryFilter(BuiltInCategory.OST_Levels); List <Element> levels = levelCollector.WherePasses(levelFilter).ToElements().ToList(); int floor_count = 0; foreach (Element elem in levels) { if (elem.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString() == "樓層") { //在地表的樓層才算,Elevation>=0,屋突好像也不算,名字P開頭的不行 Level level = elem as Level; if (level.Name.ToList()[0] != 'P' & level.Name.ToList()[0] != 'G') { if (level.Elevation >= 0) { floor_count += 1; } } } } if (floor_count >= 10) { regulation_railing_height = 120; } else { regulation_railing_height = 110; } string newFileName = @"C:\Users\8014\Desktop\BIM模型檢核.csv"; StringBuilder sb = new StringBuilder(); sb.AppendLine("5.樓梯垂直淨空高度檢核"); sb.AppendLine("規範:樓梯之垂直淨空距離不得小於 190 公分"); sb.AppendLine("樓梯名稱\t樓梯高度(cm)\t規範高度(cm)\t是否符合規範"); form_list5.Add(new string[] { "5.樓梯垂直淨空高度檢核" }); form_list5.Add(new string[] { "規範:樓梯之垂直淨空距離不得小於 190 公分" }); //先把全部的樓梯抓出來,有分室外梯以及室內梯,不過好像不用特別分室外跟室內耶 FilteredElementCollector stairsCollector = new FilteredElementCollector(doc); ElementCategoryFilter stairsFilter = new ElementCategoryFilter(BuiltInCategory.OST_Stairs); List <Element> all_stairs = stairsCollector.WherePasses(stairsFilter).WhereElementIsNotElementType().ToElements().ToList(); //List<Element> indoor_stairs = new List<Element>(); //foreach(Element elem in all_stairs) //{ // if (elem.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString().Contains("室內RC")) // indoor_stairs.Add(elem); //} foreach (Element elem in all_stairs) { Stairs stairs = elem as Stairs; double stairs_height = Convert.ToDouble(stairs.get_Parameter(BuiltInParameter.STAIRS_STAIRS_HEIGHT).AsValueString()); string s = stairs.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString() + "\t" + stairs_height.ToString() + "\t" + regulation_stairs_height.ToString() + "\t" + (stairs_height >= regulation_stairs_height).ToString(); sb.AppendLine(s); string[] row = new string[] { stairs.Id.ToString(), stairs.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString(), stairs_height.ToString(), regulation_stairs_height.ToString(), "無", (stairs_height >= regulation_stairs_height).ToString() }; form_list5.Add(row); } sb.AppendLine(); sb.AppendLine(); File.AppendAllText(newFileName, sb.ToString(), Encoding.Unicode); form_list5.Add(new string[] { }); form_list5.Add(new string[] { }); StringBuilder sb2 = new StringBuilder(); sb2.AppendLine("6.欄杆扶手高度檢核:"); sb2.AppendLine("規範:設置於露臺、陽臺、室外走廊、室外樓梯、平屋頂及室內天井部 分等之欄桿扶手高度欄桿扶手高度,不得小於1.1公尺,十層以上者,不得小於1.2公尺"); sb2.AppendLine("欄杆名稱\t欄杆高度(cm)\t規範高度(cm)\t是否符合規範"); form_list6.Add(new string[] { "6.欄杆扶手高度檢核:" }); form_list6.Add(new string[] { "規範:設置於露臺、陽臺、室外走廊、室外樓梯、平屋頂及室內天井部 分等之欄桿扶手高度欄桿扶手高度,不得小於1.1公尺,十層以上者,不得小於1.2公尺" }); //接下來要取欄杆高度 //樓梯用的扶手、欄杆是900mm的,跟女兒牆的布一樣 //要扣除掉女兒牆的欄杆的 FilteredElementCollector railingCollector = new FilteredElementCollector(doc); ElementCategoryFilter railingFilter = new ElementCategoryFilter(BuiltInCategory.OST_StairsRailing); List <Element> railings = railingCollector.WherePasses(railingFilter).WhereElementIsNotElementType().ToElements().ToList(); foreach (Element elem in railings) { if (!(elem.Name.Contains("900mm"))) { continue; } Railing railing = elem as Railing; ElementType elementType = doc.GetElement(railing.GetTypeId()) as ElementType; double railing_height = Convert.ToDouble(elementType.get_Parameter(BuiltInParameter.STAIRS_RAILING_HEIGHT).AsValueString()); string s = railing.Name + "\t" + railing_height.ToString() + "\t" + regulation_railing_height.ToString() + "\t" + (railing_height >= regulation_railing_height).ToString(); sb2.AppendLine(s); string[] row = new string[] { railing.Id.ToString(), railing.Name, railing_height.ToString(), regulation_railing_height.ToString(), "無", (railing_height >= regulation_railing_height).ToString() }; form_list6.Add(row); } sb2.AppendLine(); sb2.AppendLine(); File.AppendAllText(newFileName, sb2.ToString(), Encoding.Unicode); form_list6.Add(new string[] { }); form_list6.Add(new string[] { }); 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); }
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Add an EventLogTraceListener object System.Diagnostics.Trace.Listeners.Add( new System.Diagnostics.EventLogTraceListener("Application")); // Lay the hands on the active document UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; // Set up a timer Timing myTimer = new Timing(); myTimer.StartTime(); try { Reference r = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element); Railing railing = doc.GetElement(r) as Railing; GeometryElement geomElem = railing.get_Geometry(new Options { IncludeNonVisibleObjects = true }); RvtRailing rvtRailing = new RvtRailing(); RailingType railingType = doc.GetElement(railing.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsElementId()) as RailingType; // Extract and sort out the railign's parts foreach (GeometryObject geomObj in geomElem) { if (geomObj is GeometryInstance) { GetRailingParts((GeometryInstance)geomObj, rvtRailing); } } #region Tracing // Just a check on the number of total solids // obtained from the railing IList <Solid> allSolids = new List <Solid>(); // Get all solids from the revit railing element GetSolid(railing.get_Geometry(new Options { IncludeNonVisibleObjects = true }), allSolids); StringBuilder strBld = new StringBuilder(); for (int i = 0; i < allSolids.Count; ++i) { strBld.AppendFormat("s{0}.Volume = {1}\n", i, allSolids[i].Volume); } System.Diagnostics.Trace.Write(strBld.ToString()); #endregion TaskDialog.Show("Parts", string.Format("Top Rails: {0}; Length = {1:F2}\nRails: {2}; Length = {1:F2}; Area = {6:F2}sq ft\nBalusters: {3}; Length = {4:F2}\nAllSolids: {5}", rvtRailing.TopRails.Count, UnitUtils.ConvertFromInternalUnits(rvtRailing.TopRailLength, DisplayUnitType.DUT_MILLIMETERS), rvtRailing.Rails.Count, rvtRailing.Balusters.Count, UnitUtils.ConvertFromInternalUnits(rvtRailing.BalusterLength, DisplayUnitType.DUT_MILLIMETERS), allSolids.Count, rvtRailing.Rails[0].Volume / rvtRailing.TopRailLength)); return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception ex) { TaskDialog.Show("Exception", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); System.Diagnostics.Trace.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } finally { myTimer.StopTime(); System.Diagnostics.Trace .Write(string.Format("Time elapsed: {0}s", myTimer.Duration.TotalSeconds)); } }