/// <summary> /// Create the transverse reinforcement, according to the transverse reinforcement location /// </summary> /// <param name="location">location of rebar which need to be created</param> /// <returns>the created reinforcement, return null if the creation is unsuccessful</returns> public RebarContainerItem FillTransverseItem(RebarContainer cont, TransverseRebarLocation location) { // Get the geometry information which support reinforcement creation RebarGeometry geomInfo = new RebarGeometry(); RebarBarType barType = null; switch (location) { case TransverseRebarLocation.Start: // start transverse reinforcement case TransverseRebarLocation.End: // end transverse reinforcement geomInfo = m_geometry.GetTransverseRebar(location, m_transverseEndSpacing); barType = m_transverseEndType; break; case TransverseRebarLocation.Center:// center transverse reinforcement geomInfo = m_geometry.GetTransverseRebar(location, m_transverseCenterSpacing); barType = m_transverseCenterType; break; default: break; } // create the container item return(PlaceContainerItem(cont, barType, m_transverseHookType, m_transverseHookType, geomInfo, RebarHookOrientation.Left, RebarHookOrientation.Left)); }
/// <summary> /// Create the reinforcement at the top of beam, according to the top reinforcement location /// </summary> /// <param name="location">location of rebar which need to be created</param> /// <returns>the created reinforcement, return null if the creation is unsuccessful</returns> private RebarContainerItem FillTopItem(RebarContainer cont, TopRebarLocation location) { //get the geometry information of the reinforcement RebarGeometry geomInfo = m_geometry.GetTopRebar(location); RebarHookType startHookType = null; //the start hook type of the reinforcement RebarHookType endHookType = null; // the end hook type of the reinforcement RebarBarType rebarType = null; // the reinforcement type RebarHookOrientation startOrient = RebarHookOrientation.Right; // the start hook orient RebarHookOrientation endOrient = RebarHookOrientation.Left; // the end hook orient // decide the reinforcement type, hook type and hook orient according to location switch (location) { case TopRebarLocation.Start: startHookType = m_topHookType; // start hook type rebarType = m_topEndType; // reinforcement type startOrient = GetTopHookOrient(geomInfo, location); // start hook orient break; case TopRebarLocation.Center: rebarType = m_topCenterType; // reinforcement type break; case TopRebarLocation.End: endHookType = m_topHookType; // end hook type rebarType = m_topEndType; // reinforcement type endOrient = GetTopHookOrient(geomInfo, location); // end hook orient break; } // create the container item return(PlaceContainerItem(cont, rebarType, startHookType, endHookType, geomInfo, startOrient, endOrient)); }
/// <summary> /// Create the transverse reinforcement, according to the location of transverse bars /// </summary> /// <param name="location">location of rebar which need to be created</param> /// <returns>the created container item, return null if the creation is unsuccessful</returns> public RebarContainerItem FillTransverseItem(RebarContainer cont, TransverseRebarLocation location) { // Get the geometry information which support reinforcement creation RebarGeometry geomInfo = new RebarGeometry(); switch (location) { case TransverseRebarLocation.Start: // start transverse reinforcement case TransverseRebarLocation.End: // end transverse reinforcement geomInfo = m_geometry.GetTransverseRebar(location, m_transverseEndSpacing); break; case TransverseRebarLocation.Center:// center transverse reinforcement geomInfo = m_geometry.GetTransverseRebar(location, m_transverseCenterSpacing); break; } RebarHookOrientation startHook = RebarHookOrientation.Left; RebarHookOrientation endHook = RebarHookOrientation.Left; if (!GeomUtil.IsInRightDir(geomInfo.Normal)) { startHook = RebarHookOrientation.Right; endHook = RebarHookOrientation.Right; } // create the container item return(PlaceContainerItem(cont, m_transverseType, m_transverseHookType, m_transverseHookType, geomInfo, startHook, endHook)); }
/// <summary> /// Create the reinforcement at the bottom of beam /// </summary> /// <returns>true if the creation is successful, otherwise false</returns> public bool FillBottomItems(RebarContainer cont) { // get the geometry information of the bottom reinforcement RebarGeometry geomInfo = m_geometry.GetBottomRebar(); // create the container item RebarContainerItem item = PlaceContainerItem(cont, m_bottomType, null, null, geomInfo, RebarHookOrientation.Left, RebarHookOrientation.Left); return(null != item); }
/// <summary> /// Create the reinforcement at the top of beam /// </summary> /// <returns>true if the creation is successful, otherwise false</returns> private bool FillTopItems(RebarContainer cont) { // create all kinds of top reinforcement according to the TopRebarLocation foreach (TopRebarLocation location in Enum.GetValues(typeof(TopRebarLocation))) { RebarContainerItem item = FillTopItem(cont, location); //judge whether the top reinforcement creation is successful if (null == item) { return(false); } } return(true); }
/// <summary> /// A wrap function which used to create the reinforcement. /// </summary> /// <param name="rebarType">The element of RebarBarType</param> /// <param name="startHook">The element of start RebarHookType</param> /// <param name="endHook">The element of end RebarHookType</param> /// <param name="geomInfo">The goemetry information of the rebar</param> /// <param name="startOrient">An Integer defines the orientation of the start hook</param> /// <param name="endOrient">An Integer defines the orientation of the end hook</param> /// <returns></returns> protected RebarContainerItem PlaceContainerItem(RebarContainer cont, RebarBarType rebarType, RebarHookType startHook, RebarHookType endHook, RebarGeometry geomInfo, RebarHookOrientation startOrient, RebarHookOrientation endOrient) { Autodesk.Revit.DB.XYZ normal = geomInfo.Normal; // the direction of reinforcement distribution IList <Curve> curves = geomInfo.Curves; // the shape of the reinforcement curves RebarContainerItem item = cont.AppendItemFromCurves(RebarStyle.Standard, rebarType, startHook, endHook, normal, curves, startOrient, endOrient, false, true); if (2 < geomInfo.RebarNumber && 0 < geomInfo.RebarSpacing) { item.SetLayoutAsNumberWithSpacing(geomInfo.RebarNumber, geomInfo.RebarSpacing, true, true, true); } return(item); }
/// <summary> /// Override method to create reinforcement on the selected column /// </summary> /// <returns>true if the creation is successful, otherwise false.</returns> protected override bool FillWithBars() { //create Rebar Container ElementId conTypeId = RebarContainerType.CreateDefaultRebarContainerType(m_revitDoc); ElementId hostId = m_hostObject.Id; Element host = m_revitDoc.GetElement(hostId); if (null != host) { RebarContainer cont = RebarContainer.Create(m_revitDoc, host, conTypeId); bool flag = FillTransverseItems(cont); flag = flag && FillVerticalItems(cont); } return(base.FillWithBars()); }
/// <summary> /// Override method to create rebar on the selected beam /// </summary> /// <returns>true if the creation is successful, otherwise false</returns> protected override bool FillWithBars() { //create Rebar Container ElementId conTypeId = RebarContainerType.CreateDefaultRebarContainerType(m_revitDoc); RebarContainer cont = RebarContainer.Create(m_revitDoc, m_hostObject, conTypeId); // create the top items bool flag = FillTopItems(cont); // create the bottom items flag = flag && FillBottomItems(cont); // create the transverse items flag = flag && FillTransverseItems(cont); return(base.FillWithBars()); }
/// <summary> /// Create the vertical reinforcement according the location /// </summary> /// <param name="location">location of rebar which need to be created</param> /// <returns>the created reinforcement, return null if the creation is unsuccessful</returns> public RebarContainerItem FillVerticalItem(RebarContainer cont, VerticalRebarLocation location) { //calculate the reinforcement number in different location int rebarNubmer = m_verticalRebarNumber / 4; switch (location) { case VerticalRebarLocation.East: // the east vertical reinforcement if (0 < m_verticalRebarNumber % 4) { rebarNubmer++; } break; case VerticalRebarLocation.North: // the north vertical reinforcement if (2 < m_verticalRebarNumber % 4) { rebarNubmer++; } break; case VerticalRebarLocation.West: // the west vertical reinforcement if (1 < m_verticalRebarNumber % 4) { rebarNubmer++; } break; case VerticalRebarLocation.South: // the south vertical reinforcement break; } // get the geometry information for reinforcement creation RebarGeometry geomInfo = m_geometry.GetVerticalRebar(location, rebarNubmer); // create the container item return(PlaceContainerItem(cont, m_verticalType, null, null, geomInfo, RebarHookOrientation.Right, RebarHookOrientation.Right)); }
/// <summary> /// Exports a Rebar, AreaReinforcement or PathReinforcement to IFC ReinforcingBar. /// </summary> /// <param name="exporterIFC">The exporter.</param> /// <param name="element">The element.</param> /// <param name="productWrapper">The product wrapper.</param> public static void Export(ExporterIFC exporterIFC, Element element, ProductWrapper productWrapper) { ISet <DelayedProductWrapper> createdRebars = new HashSet <DelayedProductWrapper>(); if (element is Rebar) { createdRebars = ExportRebar(exporterIFC, element, productWrapper); } else if (element is AreaReinforcement) { AreaReinforcement areaReinforcement = element as AreaReinforcement; IList <ElementId> rebarIds = areaReinforcement.GetRebarInSystemIds(); Document doc = areaReinforcement.Document; foreach (ElementId id in rebarIds) { Element rebarInSystem = doc.GetElement(id); ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper); if (newlyCreatedRebars != null) { createdRebars.UnionWith(newlyCreatedRebars); } } } else if (element is PathReinforcement) { PathReinforcement pathReinforcement = element as PathReinforcement; IList <ElementId> rebarIds = pathReinforcement.GetRebarInSystemIds(); Document doc = pathReinforcement.Document; foreach (ElementId id in rebarIds) { Element rebarInSystem = doc.GetElement(id); ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper); if (newlyCreatedRebars != null) { createdRebars.UnionWith(newlyCreatedRebars); } } } else if (element is RebarContainer) { int itemIndex = 1; RebarContainer rebarContainer = element as RebarContainer; foreach (RebarContainerItem rebarContainerItem in rebarContainer) { ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarContainerItem, rebarContainer, itemIndex, productWrapper); if (newlyCreatedRebars != null) { itemIndex += createdRebars.Count; createdRebars.UnionWith(newlyCreatedRebars); } } } if (createdRebars != null && createdRebars.Count != 0) { string guid = GUIDUtil.CreateGUID(element); // Create a group to hold all of the created IFC entities, if the rebars aren't already in an assembly or a group. // We want to avoid nested groups of groups of rebars. bool relateToLevel = true; bool groupRebarHandles = (createdRebars.Count != 1); foreach (DelayedProductWrapper delayedProductWrapper in createdRebars) { if (ElementIsContainedInAssembly(delayedProductWrapper.RebarElement)) { groupRebarHandles = false; relateToLevel = false; break; } } ISet <IFCAnyHandle> createdRebarHandles = new HashSet <IFCAnyHandle>(); foreach (DelayedProductWrapper delayedProductWrapper in createdRebars) { IFCAnyHandle currentRebarHandle = delayedProductWrapper.ElementHandle; productWrapper.AddElement(delayedProductWrapper.RebarElement, currentRebarHandle, delayedProductWrapper.LevelInfo, null, relateToLevel); createdRebarHandles.Add(currentRebarHandle); } if (createdRebars.Count > 1) { if (groupRebarHandles) { // Check the intended IFC entity or type name is in the exclude list specified in the UI Common.Enums.IFCEntityType elementClassTypeEnum; if (Enum.TryParse <Common.Enums.IFCEntityType>("IfcGroup", out elementClassTypeEnum)) { if (!ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; string revitObjectType = exporterIFC.GetFamilyName(); string name = NamingUtil.GetNameOverride(element, revitObjectType); string description = NamingUtil.GetDescriptionOverride(element, null); string objectType = NamingUtil.GetObjectTypeOverride(element, revitObjectType); IFCAnyHandle rebarGroup = IFCInstanceExporter.CreateGroup(file, guid, ownerHistory, name, description, objectType); productWrapper.AddElement(element, rebarGroup); IFCInstanceExporter.CreateRelAssignsToGroup(file, GUIDUtil.CreateGUID(), ownerHistory, null, null, createdRebarHandles, null, rebarGroup); tr.Commit(); } } } } } else { // We will update the GUID of the one created IfcReinforcingElement to be the element GUID. // This will allow the IfcGUID parameter to be use/set if appropriate. ExporterUtil.SetGlobalId(createdRebarHandles.ElementAt(0), guid); } } }
private void Stream( ArrayList data, RebarContainer rebarContainer ) { data.Add( new Snoop.Data.ClassSeparator( typeof( RebarContainer ) ) ); data.Add( new Snoop.Data.ElementId( "", rebarContainer.GetHostId(), rebarContainer.Document ) ); data.Add( new Snoop.Data.Object( "Reinforcement Rounding Manager", rebarContainer.GetReinforcementRoundingManager() ) ); data.Add( new Snoop.Data.Int( "Items Count", rebarContainer.ItemsCount ) ); IEnumerator<RebarContainerItem> iter = rebarContainer.GetEnumerator(); iter.Reset(); while( iter.MoveNext() ) { RebarContainerItem item = iter.Current as RebarContainerItem; if( item == null ) return; String objectName = "Rebar Container Item [" + item.ItemIndex.ToString() + "]"; try { data.Add( new Snoop.Data.Object( objectName, item ) ); } catch( System.Exception ex ) { data.Add( new Snoop.Data.Exception( objectName, ex ) ); } } data.Add( new Snoop.Data.String( "Schedule Mark", rebarContainer.ScheduleMark ) ); }
private void Stream( ArrayList data, RebarContainer rebarCont ) { data.Add( new Snoop.Data.ClassSeparator( typeof( RebarContainer ) ) ); data.Add( new Snoop.Data.String( "Schedule Mark", rebarCont.ScheduleMark ) ); data.Add( new Snoop.Data.ElementId( "Host", rebarCont.GetHostId(), m_app.ActiveUIDocument.Document ) ); data.Add( new Snoop.Data.Int( "Number of Items", rebarCont.ItemsCount ) ); data.Add( new Snoop.Data.Object( "Reinforcement Rounding Manager", rebarCont.GetReinforcementRoundingManager() ) ); }
/// <summary> /// Exports a Rebar, AreaReinforcement or PathReinforcement to IFC ReinforcingBar. /// </summary> /// <param name="exporterIFC">The exporter.</param> /// <param name="element">The element.</param> /// <param name="productWrapper">The product wrapper.</param> public static void Export(ExporterIFC exporterIFC, Element element, ProductWrapper productWrapper) { ISet <DelayedProductWrapper> createdRebars = new HashSet <DelayedProductWrapper>(); // First, we will create individual rebars based on the Revit element. if (element is Rebar) { createdRebars = ExportRebar(exporterIFC, element, productWrapper); } else if (element is AreaReinforcement) { AreaReinforcement areaReinforcement = element as AreaReinforcement; IList <ElementId> rebarIds = areaReinforcement.GetRebarInSystemIds(); Document doc = areaReinforcement.Document; foreach (ElementId id in rebarIds) { Element rebarInSystem = doc.GetElement(id); ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper); if (newlyCreatedRebars != null) { createdRebars.UnionWith(newlyCreatedRebars); } } } else if (element is PathReinforcement) { PathReinforcement pathReinforcement = element as PathReinforcement; IList <ElementId> rebarIds = pathReinforcement.GetRebarInSystemIds(); Document doc = pathReinforcement.Document; foreach (ElementId id in rebarIds) { Element rebarInSystem = doc.GetElement(id); ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper); if (newlyCreatedRebars != null) { createdRebars.UnionWith(newlyCreatedRebars); } } } else if (element is RebarContainer) { int itemIndex = 1; RebarContainer rebarContainer = element as RebarContainer; foreach (RebarContainerItem rebarContainerItem in rebarContainer) { ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarContainerItem, rebarContainer, itemIndex, productWrapper); if (newlyCreatedRebars != null) { itemIndex += createdRebars.Count; createdRebars.UnionWith(newlyCreatedRebars); } } } // If we've created any rebar, we will group them below into three conceptual groups: // 1. One rebar that shouldn't be grouped or be in an assembly, // but be directly contained in a building story. // 2. Rebar that are in assemblies, where the assembly is contained in a building story. // 3. Multiple rebar that aren't in assembles, which should both be in a group and // directly contained in a building story. // // The reason for the cases above: // 1. Nested groups/assemblies aren't allow in IFC. So we can only have one level. // 2. IfcGroups don't have level assignment. So the individual components inside have // to be directly contained in a building story. // 3. IfcAssemblies do have level assignment, so individual components can't be directly // contained in a building story. This does mean that rebars in assemblies may // be associated with the wrong level, but that is an IFC limitation. if (createdRebars != null && createdRebars.Count != 0) { // Only one created element can have the consistent GUID of the main element. // This will be either the first created assembly or the first rebar element. string guid = GUIDUtil.CreateGUID(element); // While it seems likely that all of the rebar would have the same assembly id, // there's no need to assume this. Make a map of assembly id to created rebar. IDictionary <ElementId, ISet <DelayedProductWrapper> > relatedRebar = new Dictionary <ElementId, ISet <DelayedProductWrapper> >(); relatedRebar[ElementId.InvalidElementId] = new HashSet <DelayedProductWrapper>(); // Go through the created rebar and sort into buckets by assembly id. foreach (DelayedProductWrapper delayedProductWrapper in createdRebars) { Element rebarElement = delayedProductWrapper.RebarElement; if (rebarElement == null) { continue; } ElementId rebarAssemblyInstanceId = rebarElement.AssemblyInstanceId; ISet <DelayedProductWrapper> currentRebarSet = null; if (!relatedRebar.TryGetValue(rebarAssemblyInstanceId, out currentRebarSet)) { currentRebarSet = new HashSet <DelayedProductWrapper>(); relatedRebar[rebarAssemblyInstanceId] = currentRebarSet; } currentRebarSet.Add(delayedProductWrapper); } foreach (KeyValuePair <ElementId, ISet <DelayedProductWrapper> > relatedToAssembly in relatedRebar) { // Ignore buckets with no items in them. if (relatedToAssembly.Value.Count == 0) { continue; } // We will attach rebar to an assembly for rebar belonging to an assembly; // otherwise we will create a group, assuming there are at least 2 rebar to group. ElementId assemblyId = relatedToAssembly.Key; bool hasAssemblyId = (assemblyId != ElementId.InvalidElementId); bool attachToLevel = !hasAssemblyId; ISet <IFCAnyHandle> createdRebarHandles = new HashSet <IFCAnyHandle>(); foreach (DelayedProductWrapper delayedProductWrapper in relatedToAssembly.Value) { IFCAnyHandle currentRebarHandle = delayedProductWrapper.ElementHandle; productWrapper.AddElement(delayedProductWrapper.RebarElement, currentRebarHandle, delayedProductWrapper.LevelInfo, null, attachToLevel, delayedProductWrapper.ExportInfo); createdRebarHandles.Add(currentRebarHandle); } if (hasAssemblyId) { ExporterCacheManager.AssemblyInstanceCache.RegisterElements(assemblyId, productWrapper); } else if (createdRebarHandles.Count > 1) { // Check the intended IFC entity or type name is in the exclude list specified in the UI string rebarGUID = (guid != null) ? guid : GUIDUtil.CreateGUID(); CreateRebarGroup(exporterIFC, element, rebarGUID, productWrapper, createdRebarHandles); guid = null; } } // We will update the GUID of the one created IfcReinforcingElement to be the element GUID. // This will allow the IfcGUID parameter to be use/set if appropriate. if (createdRebars.Count == 1 && guid != null) { ExporterUtil.SetGlobalId(createdRebars.ElementAt(0).ElementHandle, guid); } } }