/// <summary> /// Iterates through all the BarDescriptions in the project. /// store these data in a data table m_barDescriptions and /// store the AreaReinforcements id value in a array list m_areaReinforcementIdList /// </summary> private bool PrepareAllNeededData() { // reset the Columns of data table m_barDescriptions SetDataTableCloumn(); AreaReinforcement tempAreaReinforcement = null; FilteredElementIterator i = (new FilteredElementCollector(m_revit.Application.ActiveUIDocument.Document)).OfClass(typeof(AreaReinforcement)).GetElementIterator(); while (i.MoveNext()) { tempAreaReinforcement = i.Current as AreaReinforcement; if (tempAreaReinforcement != null) { // store all the AreaReinforcements id value in a array list m_areaReinforcementIdList m_areaReinforcementIdList.Add(tempAreaReinforcement.Id.IntegerValue); // store BarDescriptions in a data table m_barDescriptions for (int j = 0; j < tempAreaReinforcement.NumBarDescriptions; j++) { BarDescription barDescription = tempAreaReinforcement.get_BarDescription(j); SetCurrentBarDescriptionToTable(tempAreaReinforcement, barDescription); } } } if (null == tempAreaReinforcement) { return(false); } return(true); }
///<summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, Autodesk.Revit.DB.ElementSet elements) { Transaction trans = new Transaction(revit.Application.ActiveUIDocument.Document, "Revit.SDK.Samples.CreateComplexAreaRein"); trans.Start(); //initialize members m_revit = revit; m_currentDoc = revit.Application.ActiveUIDocument; m_data = new AreaReinData(revit.Application.ActiveUIDocument.Document); try { //check precondition and prepare necessary data to create AreaReinforcement. Reference refer = null; IList <Curve> curves = new List <Curve>(); Floor floor = InitFloor(ref refer, ref curves); //ask for user's input AreaReinData dataOnFloor = new AreaReinData(revit.Application.ActiveUIDocument.Document); CreateComplexAreaReinForm createForm = new CreateComplexAreaReinForm(dataOnFloor); if (createForm.ShowDialog() == DialogResult.OK) { //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves[0]); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X, firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y, firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z); //create AreaReinforcement by AreaReinforcement.Create() function DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create; ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(revit.Application.ActiveUIDocument.Document); ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(revit.Application.ActiveUIDocument.Document); ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(revit.Application.ActiveUIDocument.Document); AreaReinforcement areaRein = AreaReinforcement.Create(revit.Application.ActiveUIDocument.Document, floor, curves, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId); //set AreaReinforcement and it's AreaReinforcementCurves parameters dataOnFloor.FillIn(areaRein); trans.Commit(); return(Autodesk.Revit.UI.Result.Succeeded); } } catch (ApplicationException appEx) { message = appEx.Message; trans.RollBack(); return(Autodesk.Revit.UI.Result.Failed); } catch { message = "Unknow Errors."; trans.RollBack(); return(Autodesk.Revit.UI.Result.Failed); } trans.RollBack(); return(Autodesk.Revit.UI.Result.Cancelled); }
/// <summary> /// set the parameters to given AreaReinforcement /// </summary> /// <param name="areaRein"></param> public override void FillIn(AreaReinforcement areaRein) { base.FillIn(areaRein); foreach (Parameter para in areaRein.Parameters) { if (para.Definition.Name == "Exterior Major Direction") { para.Set(Convert.ToInt32(m_exteriorMajorDirection)); } if (para.Definition.Name == "Interior Major Direction") { para.Set(Convert.ToInt32(m_interiorMajorDirection)); } if (para.Definition.Name == "Exterior Minor Direction") { para.Set(Convert.ToInt32(m_exteriorMinorDirection)); } if (para.Definition.Name == "Interior Minor Direction") { para.Set(Convert.ToInt32(m_interiorMinorDirection)); } } }
// Создание арматурной сетки по параметрам обьекта RebarArea rebarArea public static AreaReinforcement Create(Models.RebarArea rebarArea, XYZ majorDirection) { if (null == rebarArea.RebarBarType) { throw new Exception(string.Format("{0} - не выбран типоразмер арматуры", rebarArea.AreaReinforcementType.Name)); } else { Document doc = rebarArea.Document; Element hostElement = rebarArea.Host; //IList<Curve> curveArray = GetCurveArray(rebarArea, majorDirection); IList <Curve> curveArray = GetCurveArray2(rebarArea, majorDirection); ElementId areaReinforcementTypeId = rebarArea.AreaReinforcementType.Id; ElementId rebarBarTypeId = rebarArea.RebarBarType.Id; ElementId rebarHookTypeId = ElementId.InvalidElementId; using (Transaction t = new Transaction(doc, "CreateAreaReinforcement")) { t.Start(); AreaReinforcement areaReinforcement = AreaReinforcement.Create( doc, hostElement, curveArray, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId); SetDirectionAndSpacing(areaReinforcement, rebarArea); t.Commit(); return(areaReinforcement); } } }
/// <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 <IFCAnyHandle> createdRebars = null; if (element is Rebar) { 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); createdRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper); } } 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); createdRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper); } } if (createdRebars != null && createdRebars.Count > 1) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { string guid = GUIDUtil.CreateGUID(element); IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle(); 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, createdRebars, null, rebarGroup); tr.Commit(); } } }
/// <summary> /// check whether the selected is expected, find all hooktypes in current project /// </summary> /// <param name="selected">selected elements</param> /// <returns>whether the selected AreaReinforcement is expected</returns> private bool PreData() { ElementSet selected = m_commandData.Application.ActiveUIDocument.Selection.Elements; //selected is not only one AreaReinforcement if (selected.Size != 1) { return(false); } foreach (Object o in selected) { m_areaRein = o as AreaReinforcement; } if (null == m_areaRein) { return(false); } //make sure hook type and bar type exist in current project and get them m_hookTypes = new Hashtable(); m_barTypes = new Hashtable(); Document activeDoc = m_commandData.Application.ActiveUIDocument.Document; FilteredElementIterator itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarHookType)).GetElementIterator(); itor.Reset(); while (itor.MoveNext()) { RebarHookType hookType = itor.Current as RebarHookType; if (null != hookType) { string hookTypeName = hookType.Name; m_hookTypes.Add(hookTypeName, hookType.Id); } } itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarBarType)).GetElementIterator(); itor.Reset(); while (itor.MoveNext()) { RebarBarType barType = itor.Current as RebarBarType; if (null != barType) { string barTypeName = barType.Name; m_barTypes.Add(barTypeName, barType.Id); } } if (m_hookTypes.Count == 0 || m_barTypes.Count == 0) { return(false); } return(true); }
/// <summary> /// create simple AreaReinforcement on vertical straight rectangular wall /// </summary> /// <param name="wall"></param> /// <returns>is successful</returns> private bool CreateAreaReinOnWall(Wall wall) { //make sure selected is basic wall if (wall.WallType.Kind != WallKind.Basic) { TaskDialog.Show("Revit", "Selected wall is not a basic wall."); return(false); } GeomHelper helper = new GeomHelper(); Reference refer = null; IList <Curve> curves = new List <Curve>(); //check whether wall is vertical rectangular and analytical model shape is line if (!helper.GetWallGeom(wall, ref refer, ref curves)) { ApplicationException appEx = new ApplicationException( "Your selection is not a structural straight rectangular wall."); throw appEx; } AreaReinDataOnWall dataOnWall = new AreaReinDataOnWall(); CreateSimpleAreaReinForm createForm = new CreateSimpleAreaReinForm(dataOnWall); //allow use select parameters to create if (createForm.ShowDialog() == DialogResult.OK) { DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create; //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves[0]); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X, firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y, firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z); //create AreaReinforcement IList <Curve> curveList = new List <Curve>(); foreach (Curve curve in curves) { curveList.Add(curve); } ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(m_revit.Application.ActiveUIDocument.Document); ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(m_revit.Application.ActiveUIDocument.Document); ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(m_revit.Application.ActiveUIDocument.Document); AreaReinforcement areaRein = AreaReinforcement.Create(m_revit.Application.ActiveUIDocument.Document, wall, curveList, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId); dataOnWall.FillIn(areaRein); return(true); } return(false); }
public bool FillInData(AreaReinforcement areaRein) { bool flag = true; //member m_layoutRule = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE); flag = (m_layoutRule != null); ParameterSet paras = areaRein.Parameters; //exterior major layer m_exteriorMajorBarType = ParameterUtil.FindParaByName(paras, "Exterior Major Bar Type"); m_exteriorMajorHookType = ParameterUtil.FindParaByName(paras, "Exterior Major Hook Type"); m_exteriorMajorHookOrientation = ParameterUtil.FindParaByName(paras, "Exterior Major Hook Orientation"); flag &= (m_exteriorMajorBarType != null) && (m_exteriorMajorHookOrientation != null) && (m_exteriorMajorHookType != null); //exterior minor layer m_exteriorMinorBarType = ParameterUtil.FindParaByName(paras, "Exterior Minor Bar Type"); m_exteriorMinorHookType = ParameterUtil.FindParaByName(paras, "Exterior Minor Hook Type"); m_exteriorMinorHookOrientation = ParameterUtil.FindParaByName(paras, "Exterior Minor Hook Orientation"); flag &= (m_exteriorMinorBarType != null) && (m_exteriorMinorHookOrientation != null) && (m_exteriorMinorHookType != null); //interior major layer m_interiorMajorBarType = ParameterUtil.FindParaByName(paras, "Interior Major Bar Type"); m_interiorMajorHookType = ParameterUtil.FindParaByName(paras, "Interior Major Hook Type"); m_interiorMajorHookOrientation = ParameterUtil.FindParaByName(paras, "Interior Major Hook Orientation"); flag &= (m_interiorMajorBarType != null) && (m_interiorMajorHookOrientation != null) && (m_interiorMajorHookType != null); //interior minor layer m_interiorMinorBarType = ParameterUtil.FindParaByName(paras, "Interior Minor Bar Type"); m_interiorMinorHookType = ParameterUtil.FindParaByName(paras, "Interior Minor Hook Type"); m_interiorMinorHookOrientation = ParameterUtil.FindParaByName(paras, "Interior Minor Hook Orientation"); flag &= (m_interiorMinorBarType != null) && (m_interiorMinorHookOrientation != null) && (m_interiorMinorHookType != null); return(flag); }
///<summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, Autodesk.Revit.DB.ElementSet elements) { //initialize members m_revit = revit; m_currentDoc = revit.Application.ActiveUIDocument; m_data = new AreaReinData(); try { //check precondition and prepare necessary data to create AreaReinforcement. Reference refer = null; CurveArray curves = null; Floor floor = InitFloor(ref refer, ref curves); //ask for user's input AreaReinData dataOnFloor = new AreaReinData(); CreateComplexAreaReinForm createForm = new CreateComplexAreaReinForm(dataOnFloor); if (createForm.ShowDialog() == DialogResult.OK) { //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves.get_Item(0)); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X, firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y, firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z); //create AreaReinforcement by NewAreaReinforcement function DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create; AreaReinforcement areaRein = creator. NewAreaReinforcement(floor, curves, majorDirection); //set AreaReinforcement and it's AreaReinforcementCurves parameters dataOnFloor.FillIn(areaRein); return(Autodesk.Revit.UI.Result.Succeeded); } } catch (ApplicationException appEx) { message = appEx.Message; return(Autodesk.Revit.UI.Result.Failed); } catch { message = "Unknow Errors."; return(Autodesk.Revit.UI.Result.Failed); } return(Autodesk.Revit.UI.Result.Cancelled); }
/// <summary> /// fill in data with given AreaReinforcement /// </summary> /// <param name="areaRein"></param> /// <returns></returns> public bool FillInData(AreaReinforcement areaRein) { bool flag = false; //member m_layoutRule = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE); flag = (m_layoutRule != null); //top major layer m_topMajorBarType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_TOP_DIR_1); m_topMajorHookType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_TOP_DIR_1); m_topMajorHookOrientation = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_1); flag &= (m_topMajorBarType != null) && (m_topMajorHookOrientation != null) && (m_topMajorHookType != null); //top minor layer m_topMinorBarType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_TOP_DIR_2); m_topMinorHookType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_TOP_DIR_2); m_topMinorHookOrientation = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_2); flag &= (m_topMinorBarType != null) && (m_topMinorHookOrientation != null) && (m_topMinorHookType != null); //bottom major layer m_bottomMajorBarType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_BOTTOM_DIR_1); m_bottomMajorHookType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_BOTTOM_DIR_1); m_bottomMajorHookOrientation = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_BOTTOM_DIR_1); flag &= (m_bottomMajorBarType != null) && (m_bottomMajorHookOrientation != null) && (m_bottomMajorHookType != null); //bottom minor layer m_bottomMinorBarType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_BOTTOM_DIR_2); m_bottomMinorHookType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_BOTTOM_DIR_2); m_bottomMinorHookOrientation = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_BOTTOM_DIR_2); flag &= (m_bottomMinorBarType != null) && (m_bottomMinorHookOrientation != null) && (m_bottomMinorHookType != null); return(flag); }
private static AreaReinforcement Generate(Document doc, Wall wall, List <Curve> profile, bool isHorizontal, bool createInterior, bool createExterior, double offsetInt, double offsetExt, double interval, ElementId areaId, RebarBarType barType, string partition) { Debug.WriteLine("Start generating area rebar. Profile debug info: "); Debug.WriteLine(Util.ProfileDebugInfo(profile)); CurveUtils.SortCurvesContiguous(doc.Application.Create, profile, true); AreaReinforcement arein = AreaReinforcement.Create(doc, wall, profile, new XYZ(0, 0, 1), areaId, barType.Id, ElementId.InvalidElementId); if (isHorizontal) { arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BACK_DIR_1).Set(0); arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_FRONT_DIR_1).Set(0); arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_2_GENERIC).Set(interval); arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_2_GENERIC).Set(interval); if (!createInterior) { arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BACK_DIR_2).Set(0); } if (!createExterior) { arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_FRONT_DIR_2).Set(0); } } else { arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_FRONT_DIR_2).Set(0); arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BACK_DIR_2).Set(0); arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_1_GENERIC).Set(interval); arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_1_GENERIC).Set(interval); if (!createInterior) { arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BACK_DIR_1).Set(0); } if (!createExterior) { arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_FRONT_DIR_1).Set(0); } } arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_INTERIOR_OFFSET).Set(offsetInt); arein.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_EXTERIOR_OFFSET).Set(offsetExt); arein.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set(partition); Debug.WriteLine("Rebar area created"); return(arein); }
/// <summary> /// set the parameters to given AreaReinforcement /// </summary> /// <param name="areaRein"></param> public virtual void FillIn(AreaReinforcement areaRein) { int temp = (int)m_layoutRule; bool flag = ParameterUtil.SetParaInt(areaRein, BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE, temp); if (!flag) { Parameter paraLayout = ParameterUtil.FindParaByName( areaRein.Parameters, "Layout Rule"); if (null != paraLayout) { paraLayout.Set(temp); } } }
/// <summary> /// set the parameters to given AreaReinforcement /// </summary> /// <param name="areaRein"></param> public virtual void FillIn(AreaReinforcement areaRein) { int temp = (int)m_layoutRule; bool flag = ParameterUtil.SetParaInt(areaRein, BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE, temp); //if BuiltInParameter doesn't work if(!flag) { Parameter paraLayout = ParameterUtil.FindParaByName( areaRein.Parameters, "Layout Rule"); if (null != paraLayout) { paraLayout.Set(temp); } } ChangeAreaReinCurves(areaRein); }
/// <summary> /// set the parameters to given AreaReinforcement /// </summary> /// <param name="areaRein"></param> public override void FillIn(AreaReinforcement areaRein) { base.FillIn(areaRein); ParameterUtil.SetParaInt(areaRein, BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1, Convert.ToInt32(m_bottomMajorDirection)); ParameterUtil.SetParaInt(areaRein, BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2, Convert.ToInt32(m_bottomMinorDirection)); ParameterUtil.SetParaInt(areaRein, BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1, Convert.ToInt32(m_topMajorDirection)); ParameterUtil.SetParaInt(areaRein, BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2, Convert.ToInt32(m_topMinorDirection)); }
/// <summary> /// create simple AreaReinforcement on vertical straight rectangular wall /// </summary> /// <param name="wall"></param> /// <returns>is successful</returns> private bool CreateAreaReinOnWall(Wall wall) { //make sure selected is basic wall if (wall.WallType.Kind != WallKind.Basic) { MessageBox.Show("Selected wall is not a basic wall."); return(false); } GeomHelper helper = new GeomHelper(); Reference refer = null; CurveArray curves = null; //check whether wall is vertical rectangular and analytical model shape is line if (!helper.GetWallGeom(wall, ref refer, ref curves)) { ApplicationException appEx = new ApplicationException( "Your selection is not a structural straight rectangular wall."); throw appEx; } AreaReinDataOnWall dataOnWall = new AreaReinDataOnWall(); CreateSimpleAreaReinForm createForm = new CreateSimpleAreaReinForm(dataOnWall); //allow use select parameters to create if (createForm.ShowDialog() == DialogResult.OK) { DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create; //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves.get_Item(0)); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X, firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y, firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z); //create AreaReinforcement by NewAreaReinforcement function AreaReinforcement areaRein = creator.NewAreaReinforcement(wall, curves, majorDirection); dataOnWall.FillIn(areaRein); return(true); } return(false); }
/// <summary> /// On the interior 4 curves, set the override flag /// and flip the hooks on the top 2 layers to "up" /// </summary> /// <param name="areaRein"></param> private void ChangeAreaReinCurves(AreaReinforcement areaRein) { //interior 4 curves are listed in the back of the curves, //this order is decided when we create it for (int i = 4; i < 8; i++) { AreaReinforcementCurve areaReinCurve = areaRein.Curves.get_Item(i) as AreaReinforcementCurve; //remove hooks, set the hook the top 2 layers to 'up' ParameterUtil.SetParaInt(areaReinCurve, BuiltInParameter.REBAR_SYSTEM_OVERRIDE, -1); ParameterUtil.SetParaInt(areaReinCurve, BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_1, (int)HookOrientation.Up); ParameterUtil.SetParaInt(areaReinCurve, BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_2, (int)HookOrientation.Up); } }
/// <summary> /// create simple AreaReinforcement on horizontal floor /// </summary> /// <param name="floor"></param> /// <returns>is successful</returns> private bool CreateAreaReinOnFloor(Floor floor) { GeomHelper helper = new GeomHelper(); Reference refer = null; IList <Curve> curves = new List <Curve>(); //check whether floor is horizontal rectangular //and prepare necessary to create AreaReinforcement if (!helper.GetFloorGeom(floor, ref refer, ref curves)) { ApplicationException appEx = new ApplicationException( "Your selection is not a horizontal rectangular slab."); throw appEx; } AreaReinDataOnFloor dataOnFloor = new AreaReinDataOnFloor(); CreateSimpleAreaReinForm createForm = new CreateSimpleAreaReinForm(dataOnFloor); //allow use select parameters to create if (createForm.ShowDialog() == DialogResult.OK) { //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves[0]); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X, firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y, firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z); //Create AreaReinforcement ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(m_revit.Application.ActiveUIDocument.Document); ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(m_revit.Application.ActiveUIDocument.Document); ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(m_revit.Application.ActiveUIDocument.Document); AreaReinforcement areaRein = AreaReinforcement.Create(m_revit.Application.ActiveUIDocument.Document, floor, curves, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId); //set AreaReinforcement and it's AreaReinforcementCurves parameters dataOnFloor.FillIn(areaRein); return(true); } return(false); }
/// <summary> /// create simple AreaReinforcement on horizontal floor /// </summary> /// <param name="floor"></param> /// <returns>is successful</returns> private bool CreateAreaReinOnFloor(Floor floor) { GeomHelper helper = new GeomHelper(); Reference refer = null; CurveArray curves = null; //check whether floor is horizontal rectangular //and prepare necessary to create AreaReinforcement if (!helper.GetFloorGeom(floor, ref refer, ref curves)) { ApplicationException appEx = new ApplicationException( "Your selection is not a horizontal rectangular slab."); throw appEx; } AreaReinDataOnFloor dataOnFloor = new AreaReinDataOnFloor(); CreateSimpleAreaReinForm createForm = new CreateSimpleAreaReinForm(dataOnFloor); //allow use select parameters to create if (createForm.ShowDialog() == DialogResult.OK) { //define the Major Direction of AreaReinforcement, //we get direction of first Line on the Floor as the Major Direction Line firstLine = (Line)(curves.get_Item(0)); Autodesk.Revit.DB.XYZ majorDirection = new Autodesk.Revit.DB.XYZ( firstLine.get_EndPoint(1).X - firstLine.get_EndPoint(0).X, firstLine.get_EndPoint(1).Y - firstLine.get_EndPoint(0).Y, firstLine.get_EndPoint(1).Z - firstLine.get_EndPoint(0).Z); //crete AreaReinforcement by NewAreaReinforcement function DocCreator creator = m_revit.Application.ActiveUIDocument.Document.Create; AreaReinforcement areaRein = creator.NewAreaReinforcement(floor, curves, majorDirection); //set AreaReinforcement and it's AreaReinforcementCurves parameters dataOnFloor.FillIn(areaRein); return(true); } return(false); }
/// <summary> /// insert current BarDescription, which is iterated through, into data table /// </summary> /// <param name="areaReinforcement"></param> /// <param name="barDescription"></param> private void SetCurrentBarDescriptionToTable(AreaReinforcement areaReinforcement, BarDescription barDescription) { int areaReinforcementId = areaReinforcement.Id.IntegerValue; int layer = barDescription.Layer; string barType = barDescription.BarType.Name; double barLength = barDescription.Length; string[] hookType = new string[2] { "", "" }; bool hookSameDirection = barDescription.HooksInSameDirection; int barCount = barDescription.Count; for (int i = 0; i < 2; i++) { if (null == barDescription.get_HookType(i)) { hookType[i] = "None"; } else { hookType[i] = barDescription.get_HookType(i).Name; } } DataRow newRow = m_barDescriptions.NewRow(); newRow["areaReinforcementId"] = areaReinforcementId; newRow["layer"] = layer; newRow["barType"] = barType; newRow["barLength"] = barLength; newRow["oneEndHookType"] = hookType[0]; newRow["otherEndHookType"] = hookType[1]; newRow["hookSameDirection"] = hookSameDirection; newRow["barCount"] = barCount; m_barDescriptions.Rows.Add(newRow); }
/// <summary> /// check whether the selected is expected, prepare necessary data /// </summary> /// <param name="selected">selected elements</param> /// <returns>whether the selected AreaReinforcement is expected</returns> private bool PreData(ElementSet selected) { //selected is not only one AreaReinforcement if (selected.Size != 1) { return(false); } foreach (Object o in selected) { m_areaRein = o as AreaReinforcement; if (null == m_areaRein) { return(false); } } //whether the selected AreaReinforcement is rectangular CurveArray curves = new CurveArray(); m_areaReinCurves = new List <AreaReinforcementCurve>(); IList <ElementId> curveIds = m_areaRein.GetBoundaryCurveIds(); foreach (ElementId o in curveIds) { AreaReinforcementCurve areaCurve = m_doc.GetElement(o) as AreaReinforcementCurve; if (null == areaCurve) { ApplicationException appEx = new ApplicationException ("There is unexpected error with selected AreaReinforcement."); throw appEx; } m_areaReinCurves.Add(areaCurve); curves.Append(areaCurve.Curve); } bool flag = GeomUtil.IsRectangular(curves); return(flag); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="element"></param> /// <returns></returns> public static Revit.Element CloneElement(Application app, Revit.Element element) { Opening opening = element as Opening; if (opening != null) { return(CloneElement(app, opening)); } BoundaryConditions boundaryConditions = element as BoundaryConditions; if (boundaryConditions != null) { return(CloneElement(app, boundaryConditions)); } AreaLoad areaLoad = element as AreaLoad; if (areaLoad != null) { return(CloneElement(app, areaLoad)); } AreaReinforcement areaReinforcement = element as AreaReinforcement; if (areaReinforcement != null) { return(CloneElement(app, areaReinforcement)); } BeamSystem beamSystem = element as BeamSystem; if (beamSystem != null) { return(CloneElement(app, beamSystem)); } Dimension dimension = element as Dimension; if (dimension != null) { return(CloneElement(app, dimension)); } FamilyInstance familyInstance = element as FamilyInstance; if (familyInstance != null) { return(CloneElement(app, familyInstance)); } Floor floor = element as Floor; if (floor != null) { return(CloneElement(app, floor)); } Grid grid = element as Grid; if (grid != null) { return(CloneElement(app, grid)); } Group group = element as Group; if (group != null) { return(CloneElement(app, group)); } Level level = element as Level; if (floor != null) { return(CloneElement(app, floor)); } LineLoad lineLoad = element as LineLoad; if (lineLoad != null) { return(CloneElement(app, lineLoad)); } LoadCase loadCase = element as LoadCase; if (loadCase != null) { return(CloneElement(app, loadCase)); } LoadCombination loadCombination = element as LoadCombination; if (loadCombination != null) { return(CloneElement(app, loadCombination)); } LoadNature loadNature = element as LoadNature; if (loadNature != null) { return(CloneElement(app, loadNature)); } LoadUsage loadUsage = element as LoadUsage; if (loadUsage != null) { return(CloneElement(app, loadUsage)); } ModelCurve modelCurve = element as ModelCurve; if (modelCurve != null) { return(CloneElement(app, modelCurve)); } PointLoad pointLoad = element as PointLoad; if (pointLoad != null) { return(CloneElement(app, pointLoad)); } Rebar rebar = element as Rebar; if (rebar != null) { return(CloneElement(app, rebar)); } ReferencePlane referencePlane = element as ReferencePlane; if (referencePlane != null) { return(CloneElement(app, referencePlane)); } Room room = element as Room; if (room != null) { return(CloneElement(app, room)); } RoomTag roomTag = element as RoomTag; if (roomTag != null) { return(CloneElement(app, roomTag)); } SketchPlane sketchPlane = element as SketchPlane; if (sketchPlane != null) { return(CloneElement(app, sketchPlane)); } View3D view3D = element as View3D; if (view3D != null) { return(CloneElement(app, view3D)); } ViewDrafting viewDrafting = element as ViewDrafting; if (viewDrafting != null) { return(CloneElement(app, viewDrafting)); } ViewSection viewSection = element as ViewSection; if (viewSection != null) { return(CloneElement(app, viewSection)); } ViewSheet viewSheet = element as ViewSheet; if (viewSheet != null) { return(CloneElement(app, viewSheet)); } Wall wall = element as Wall; if (wall != null) { return(CloneElement(app, wall)); } // this element has not yet been exposed in the Creation Document class //Debug.Assert(false); return(null); }
private void Stream( ArrayList data, AreaReinforcement areaReinf ) { data.Add( new Snoop.Data.ClassSeparator( typeof( AreaReinforcement ) ) ); data.Add( new Snoop.Data.Object( "Area reinforcement type", areaReinf.AreaReinforcementType ) ); // jeremy migrated from Revit 2014 to 2015: //data.Add( new Snoop.Data.Enumerable( "Curves", areaReinf.GetCurveElementIds(), areaReinf.Document ) ); // 2014 data.Add( new Snoop.Data.Enumerable( "Curves", areaReinf.GetBoundaryCurveIds(), areaReinf.Document ) ); // 2015 data.Add( new Snoop.Data.Xyz( "Direction", areaReinf.Direction ) ); data.Add( new Snoop.Data.CategorySeparator( "Bar Descriptions" ) ); System.Collections.Generic.IList<ElementId> rebarIds = areaReinf.GetRebarInSystemIds(); data.Add( new Snoop.Data.Int( "Number of RebarInSystem", rebarIds.Count ) ); for( int i = 0; i < rebarIds.Count; i++ ) { data.Add( new Snoop.Data.Object( string.Format( "RebarInSystem [{0:d}]", i ), areaReinf.Document.GetElement( rebarIds[i] ) ) ); } }
/// <summary> /// insert current BarDescription, which is iterated through, into data table /// </summary> /// <param name="areaReinforcement"></param> /// <param name="barDescription"></param> private void SetCurrentBarDescriptionToTable(AreaReinforcement areaReinforcement, BarDescription barDescription) { int areaReinforcementId = areaReinforcement.Id.IntegerValue; int layer = barDescription.Layer; string barType = barDescription.BarType.Name; double barLength = barDescription.Length; string[] hookType = new string[2]{"",""}; bool hookSameDirection = barDescription.HooksInSameDirection; int barCount = barDescription.Count; for (int i = 0; i < 2; i++) { if (null == barDescription.get_HookType(i)) { hookType[i] = "None"; } else { hookType[i] = barDescription.get_HookType(i).Name; } } DataRow newRow = m_barDescriptions.NewRow(); newRow["areaReinforcementId"] = areaReinforcementId; newRow["layer"] = layer; newRow["barType"] = barType; newRow["barLength"] = barLength; newRow["oneEndHookType"] = hookType[0]; newRow["otherEndHookType"] = hookType[1]; newRow["hookSameDirection"] = hookSameDirection; newRow["barCount"] = barCount; m_barDescriptions.Rows.Add(newRow); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Debug.Listeners.Clear(); Debug.Listeners.Add(new RbsLogger.Logger("SelectHost")); UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; Selection sel = uiDoc.Selection; List <ElementId> selIds = sel.GetElementIds().ToList(); if (selIds.Count != 1) { message = "Выберите элемент, для которого нужно найти основу."; return(Result.Failed); } Element selElem = doc.GetElement(selIds.First()); Debug.WriteLine("Selected elem id: " + selElem.Id.IntegerValue.ToString()); ElementId hostId = null; if (selElem is AreaReinforcement) { AreaReinforcement el = selElem as AreaReinforcement; hostId = el.GetHostId(); Debug.WriteLine("It is area reinforcement"); } if (selElem is PathReinforcement) { PathReinforcement el = selElem as PathReinforcement; hostId = el.GetHostId(); Debug.WriteLine("It is path reinforcement"); } if (selElem is Rebar) { Rebar el = selElem as Rebar; hostId = el.GetHostId(); Debug.WriteLine("It is rebar"); } if (selElem is RebarInSystem) { RebarInSystem el = selElem as RebarInSystem; hostId = el.SystemId; Debug.WriteLine("It is rebar in system"); } if (selElem is FamilyInstance) { FamilyInstance el = selElem as FamilyInstance; Element host = el.Host; if (host != null) { hostId = host.Id; Debug.WriteLine("It is family instance with host"); } else { Element parentFamily = el.SuperComponent; if (parentFamily != null) { Debug.WriteLine("It is family instance with parent family"); hostId = parentFamily.Id; } } } if (hostId == null) { message = "Не удалось получить родительский элемент."; Debug.WriteLine("Host not found"); return(Result.Failed); } else { sel.SetElementIds(new List <ElementId> { hostId }); Debug.WriteLine("Host id: " + hostId.IntegerValue.ToString()); return(Result.Succeeded); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { #region App Constants and instances UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; Selection sel = uidoc.Selection; #endregion IList <Reference> refs = sel.PickObjects(ObjectType.Element, "Please select an element to copy"); foreach (Reference r in refs) { Element element = doc.GetElement(r.ElementId); Debug.Print(element.ToString()); Debug.Print(element.Name); AnalyticalModel analytical = element.GetAnalyticalModel() as AnalyticalModel; if (null == analytical) { throw new Exception("Can't get AnalyticalModel from the selected wall"); } AreaReinforcement rein = null; IList <Curve> curves = analytical.GetCurves(AnalyticalCurveType.ActiveCurves); Line firstLine = (Line)(curves[0]); XYZ majorDirection = new XYZ( firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X, firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y, firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z ); ElementId defaultRebarBarTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.RebarBarType); ElementId defaultAreaReinforcementTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.AreaReinforcementType); ElementId defaultHookTypeId = ElementId.InvalidElementId; using (Transaction trans = new Transaction(doc)) { trans.Start("Arming.."); FailureHandlingOptions options = trans.GetFailureHandlingOptions(); WarningSuppressor preproccessor = new WarningSuppressor(); options.SetClearAfterRollback(true); options.SetFailuresPreprocessor(preproccessor); trans.SetFailureHandlingOptions(options); rein = AreaReinforcement.Create(doc, element, curves, majorDirection, defaultAreaReinforcementTypeId, defaultRebarBarTypeId, defaultHookTypeId); rein.AdditionalTopCoverOffset = 0; // any number <-- rein.AdditionalBottomCoverOffset = 0; // any number --> trans.SetFailureHandlingOptions(options); trans.Commit(); var suppressor = new WarningSuppressor(); } } return(Result.Succeeded); }
public static List <string> GenerateRebar(Document doc, Wall wall, RebarInfoWall wri, RebarCoverType zeroCover, ElementId areaTypeId) { Debug.WriteLine("Start reinforcement for wall: " + wall.Id.IntegerValue.ToString()); List <string> messages = new List <string>(); double lengthRound = 5 / 304.8; ProjectInfo pi = doc.ProjectInformation; Parameter roundLengthParam = pi.LookupParameter("Арм.ОкруглениеДлины"); if (roundLengthParam != null && roundLengthParam.HasValue) { lengthRound = roundLengthParam.AsDouble(); } wall.get_Parameter(BuiltInParameter.CLEAR_COVER_OTHER).Set(zeroCover.Id); Debug.WriteLine("Set zero rebar cover for other faces"); Solid sol = SupportGeometry.GetSolidFromElement(wall); List <Face> vertFaces = SupportGeometry.GetVerticalFaces(sol); Face mainFace = SupportGeometry.GetLargeFace(vertFaces); PlanarFace pface = mainFace as PlanarFace; Debug.WriteLine("Vertical planar face was found"); List <Curve> wallOutlineDraft = SupportGeometry.GetFaceOuterBoundary(pface); Debug.WriteLine("Outline draft curves found: " + wallOutlineDraft.Count.ToString()); //удаляю совпадающие линии List <Curve> wallOutline = SupportGeometry.CleanLoop(wallOutlineDraft); Debug.WriteLine("Outline clean curves found: " + wallOutline.Count.ToString()); //определяю отступы для защитных слоев RebarCoverType coverFront = doc.GetElement(wall.get_Parameter(BuiltInParameter.CLEAR_COVER_EXTERIOR).AsElementId()) as RebarCoverType; RebarCoverType coverBack = doc.GetElement(wall.get_Parameter(BuiltInParameter.CLEAR_COVER_INTERIOR).AsElementId()) as RebarCoverType; if (coverFront == null) { coverFront = coverBack; } if (coverBack == null) { coverBack = coverFront; } double userDefineCover = wri.rebarCover; MyRebarType verticalRebarType = new MyRebarType(doc, wri.verticalRebarTypeName); if (verticalRebarType.isValid == false) { messages.Add("Не удалось получить тип стержня " + wri.verticalRebarTypeName); Debug.WriteLine("Unable to get vertical rebartype: " + wri.verticalRebarTypeName); } MyRebarType horizontalRebarType = new MyRebarType(doc, wri.horizontalRebarTypeName); if (horizontalRebarType.isValid == false) { messages.Add("Не удалось получить тип стержня " + wri.horizontalRebarTypeName); Debug.WriteLine("Unable to get horizontal rebartype: " + wri.horizontalRebarTypeName); } #if R2017 || R2018 || R2019 || R2020 || R2021 double vertDiam = verticalRebarType.bartype.BarDiameter; double horizDiam = horizontalRebarType.bartype.BarDiameter; #else double vertDiam = verticalRebarType.bartype.BarNominalDiameter; double horizDiam = horizontalRebarType.bartype.BarNominalDiameter; #endif double offsetVerticalExterior = userDefineCover - coverFront.CoverDistance - 0.5 * vertDiam; double offsetVerticalInterior = userDefineCover - coverBack.CoverDistance - 0.5 * vertDiam; double offsetHorizontalExterior = offsetVerticalExterior - horizDiam; double offsetHorizontalInterior = offsetVerticalInterior - horizDiam; if (wri.generateVertical) { Debug.WriteLine("Start creating vertical rebar"); Parameter paramFloorThickinessParam = wall.LookupParameter("Рзм.ТолщинаПерекрытия"); if (wri.autoVerticalFreeLength) { Debug.WriteLine("Try to auto-calculate vertical free length"); if (paramFloorThickinessParam != null && paramFloorThickinessParam.HasValue) { double floorThickness = paramFloorThickinessParam.AsDouble(); double freeLength = ConcreteUtils.getRebarFreeLength(verticalRebarType.bartype, wall, lengthRound); wri.verticalFreeLength = floorThickness + freeLength; Debug.WriteLine("Vertical free length = " + wri.verticalFreeLength); } else { Debug.WriteLine("Unable to auto-calculate vertical free length"); throw new Exception("Не задан параметр Рзм.ТолщинаПерекрытия в элементе " + wall.Id.IntegerValue.ToString()); } } List <Curve> curvesVertical = SupportGeometry.MoveLine(wallOutline, wri.verticalFreeLength, SupportGeometry.LineSide.Top); Debug.WriteLine("Curves for vertical loop: " + curvesVertical.Count.ToString()); if (wri.useUnification) { Debug.WriteLine("Try to unificate vertical length"); double verticalZoneHeight = SupportGeometry.GetZoneHeigth(curvesVertical); double unificateLength = wri.getNearestLength(verticalZoneHeight); double moveToUnificate = unificateLength - verticalZoneHeight; if (moveToUnificate > 0.005) { List <Curve> curvesVerticalUnificate = SupportGeometry.MoveLine(curvesVertical, moveToUnificate, SupportGeometry.LineSide.Top); curvesVertical = curvesVerticalUnificate; } } /*LocationCurve wallLocCurve = wall.Location as LocationCurve; * Line wallCurve = wallLocCurve.Curve as Line; * if (wallCurve == null) throw new Exception("Curved wall!");*/ double sideOffset = wri.backOffset - 0.5 * vertDiam; curvesVertical = SupportGeometry.MoveLine(curvesVertical, sideOffset, SupportGeometry.LineSide.Left); curvesVertical = SupportGeometry.MoveLine(curvesVertical, sideOffset, SupportGeometry.LineSide.Right); CurveUtils.SortCurvesContiguous(doc.Application.Create, curvesVertical, true); Debug.WriteLine("Contiguous curves sort"); if (wri.verticalOffset < 0.0001) { Debug.WriteLine("Generate vertical rebar area without offset"); AreaReinforcement arVertical = Generate(doc, wall, curvesVertical, false, true, true, offsetVerticalInterior, offsetVerticalExterior, wri.verticalRebarInterval, areaTypeId, verticalRebarType.bartype, wri.verticalSectionText); } else { Debug.WriteLine("Generate vertical rebar area with offset"); AreaReinforcement arVertical1 = Generate(doc, wall, curvesVertical, false, true, false, offsetVerticalInterior, offsetVerticalExterior, wri.verticalRebarInterval, areaTypeId, verticalRebarType.bartype, wri.verticalSectionText); List <Curve> curves2 = SupportGeometry.MoveLine(curvesVertical, wri.verticalOffset, SupportGeometry.LineSide.Top); curves2 = SupportGeometry.MoveLine(curves2, wri.verticalOffset, SupportGeometry.LineSide.Bottom); AreaReinforcement arVertical2 = Generate(doc, wall, curves2, false, false, true, offsetVerticalInterior, offsetVerticalExterior, wri.verticalRebarInterval, areaTypeId, verticalRebarType.bartype, wri.verticalSectionText); } } if (wri.generateHorizontal) { Debug.WriteLine("Start creating horizontal rebar"); //определяю контур double horizontalTopOffset = 0.5 * horizDiam - wri.topOffset; double horizintalBottomOffset = wri.bottomOffset - 0.5 * horizDiam; List <Curve> curvesHorizontal = SupportGeometry.MoveLine(wallOutline, horizontalTopOffset, SupportGeometry.LineSide.Top); curvesHorizontal = SupportGeometry.MoveLine(curvesHorizontal, horizintalBottomOffset, SupportGeometry.LineSide.Bottom); double sideOffset = wri.horizontalFreeLength * -1; curvesHorizontal = SupportGeometry.MoveLine(curvesHorizontal, sideOffset, SupportGeometry.LineSide.Left); curvesHorizontal = SupportGeometry.MoveLine(curvesHorizontal, sideOffset, SupportGeometry.LineSide.Right); List <AreaRebarInfo> curvesBase = new List <AreaRebarInfo>(); if (wri.horizontalAddInterval) { Debug.WriteLine("Create with additional offset"); double horizRebarInterval = wri.horizontalRebarInterval; if (wri.horizontalAdditionalStepSpace) { horizRebarInterval = horizRebarInterval / 2; } double heigth = SupportGeometry.GetZoneHeigth(curvesHorizontal); double heigthByAxis = heigth - horizDiam; double countCheckAsDouble1 = heigthByAxis / horizRebarInterval; double countCheckAsDouble2 = Math.Round(countCheckAsDouble1, 2); double countCheckAsDouble3 = Math.Truncate(countCheckAsDouble2); int countCheck = (int)countCheckAsDouble3; double addIntervalByAxis = heigthByAxis - countCheck * horizRebarInterval; if (addIntervalByAxis < horizDiam) //доборный шаг не требуется { Debug.WriteLine("Additional offset not needed"); curvesBase.Add(new AreaRebarInfo(curvesHorizontal, horizRebarInterval)); } else { Debug.WriteLine("Additional offset = " + (addIntervalByAxis * 304.8).ToString("F3")); int count = countCheck - 1; if (addIntervalByAxis < 50 / 304.8) //доборный шаг менее 50мм - увеличиваю отступ сверху { count--; } double heigthClean = count * horizRebarInterval; double offsetMain = heigth - heigthClean - horizDiam; List <Curve> profileMain = SupportGeometry.MoveLine(curvesHorizontal, -offsetMain, SupportGeometry.LineSide.Top); if (wri.horizontalAdditionalStepSpace) { if (wri.horizontalAddStepHeightBottom > 0) { List <List <Curve> > profilesAddBottom = SupportGeometry.CopyTopOrBottomLines(curvesHorizontal, wri.horizontalAddStepHeightBottom, false); foreach (var prof in profilesAddBottom) { curvesBase.Add(new AreaRebarInfo(prof, horizRebarInterval)); } profileMain = SupportGeometry.MoveLine(profileMain, wri.horizontalAddStepHeightBottom, SupportGeometry.LineSide.Bottom); } else if (wri.horizontalAddStepHeightTop > 0) { List <List <Curve> > profilesAddTop = SupportGeometry.CopyTopOrBottomLines(curvesHorizontal, wri.horizontalAddStepHeightTop, true); foreach (var prof in profilesAddTop) { curvesBase.Add(new AreaRebarInfo(prof, horizRebarInterval)); } profileMain = SupportGeometry.MoveLine(profileMain, -wri.horizontalAddStepHeightTop, SupportGeometry.LineSide.Top); } curvesBase.Add(new AreaRebarInfo(profileMain, horizRebarInterval * 2)); } else { curvesBase.Add(new AreaRebarInfo(profileMain, horizRebarInterval)); } double heigthAdd = heigth - heigthClean - horizRebarInterval; List <List <Curve> > profilesAdd = SupportGeometry.CopyTopOrBottomLines(curvesHorizontal, heigthAdd, true); foreach (var prof in profilesAdd) { curvesBase.Add(new AreaRebarInfo(prof, horizRebarInterval)); } } } else { Debug.WriteLine("Create only one zone for horizontal rebars"); curvesBase.Add(new AreaRebarInfo(curvesHorizontal, wri.horizontalRebarInterval)); } Debug.WriteLine("Loops for horizontal rebar: " + curvesBase.Count.ToString()); foreach (var profileInfo in curvesBase) { double interval = profileInfo.interval; List <Curve> curves = profileInfo.curves; AreaReinforcement ar = Generate(doc, wall, curves, true, true, true, offsetHorizontalInterior, offsetHorizontalExterior, interval, areaTypeId, horizontalRebarType.bartype, wri.horizontalSectionText); } } return(messages); }
/// <summary> /// check whether the selected is expected, prepare necessary data /// </summary> /// <param name="selected">selected elements</param> /// <returns>whether the selected AreaReinforcement is expected</returns> private bool PreData(ElementSet selected) { //selected is not only one AreaReinforcement if (selected.Size != 1) { return false; } foreach (Object o in selected) { m_areaRein = o as AreaReinforcement; if (null == m_areaRein) { return false; } } //whether the selected AreaReinforcement is rectangular CurveArray curves = new CurveArray(); m_areaReinCurves = new List<AreaReinforcementCurve>(); foreach (object o in m_areaRein.Curves) { AreaReinforcementCurve areaCurve = o as AreaReinforcementCurve; if (null == areaCurve) { ApplicationException appEx = new ApplicationException ("There is unexpected error with selected AreaReinforcement."); throw appEx; } m_areaReinCurves.Add(areaCurve); curves.Append(areaCurve.Curve); } bool flag = GeomUtil.IsRectangular(curves); return flag; }
public bool FillInData(AreaReinforcement areaRein) { bool flag = true; //member m_layoutRule = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE); flag = (m_layoutRule != null); ParameterSet paras = areaRein.Parameters; //exterior major layer m_exteriorMajorBarType = ParameterUtil.FindParaByName(paras, "Exterior Major Bar Type"); m_exteriorMajorHookType = ParameterUtil.FindParaByName(paras, "Exterior Major Hook Type"); m_exteriorMajorHookOrientation = ParameterUtil.FindParaByName(paras, "Exterior Major Hook Orientation"); flag &= (m_exteriorMajorBarType != null) && (m_exteriorMajorHookOrientation != null) && (m_exteriorMajorHookType != null); //exterior minor layer m_exteriorMinorBarType = ParameterUtil.FindParaByName(paras, "Exterior Minor Bar Type"); m_exteriorMinorHookType = ParameterUtil.FindParaByName(paras, "Exterior Minor Hook Type"); m_exteriorMinorHookOrientation = ParameterUtil.FindParaByName(paras, "Exterior Minor Hook Orientation"); flag &= (m_exteriorMinorBarType != null) && (m_exteriorMinorHookOrientation != null) && (m_exteriorMinorHookType != null); //interior major layer m_interiorMajorBarType = ParameterUtil.FindParaByName(paras, "Interior Major Bar Type"); m_interiorMajorHookType = ParameterUtil.FindParaByName(paras, "Interior Major Hook Type"); m_interiorMajorHookOrientation = ParameterUtil.FindParaByName(paras, "Interior Major Hook Orientation"); flag &= (m_interiorMajorBarType != null) && (m_interiorMajorHookOrientation != null) && (m_interiorMajorHookType != null); //interior minor layer m_interiorMinorBarType = ParameterUtil.FindParaByName(paras, "Interior Minor Bar Type"); m_interiorMinorHookType = ParameterUtil.FindParaByName(paras, "Interior Minor Hook Type"); m_interiorMinorHookOrientation = ParameterUtil.FindParaByName(paras, "Interior Minor Hook Orientation"); flag &= (m_interiorMinorBarType != null) && (m_interiorMinorHookOrientation != null) && (m_interiorMinorHookType != null); return flag; }
private AreaReinforcement FemDesignRebarToRevit(Document doc, FemDesignRebar femRebar) { string hostGuid = femRebar.hostGuid; double meterToFeet = UnitUtils.ConvertToInternalUnits(1, DisplayUnitType.DUT_METERS); double diameter = femRebar.diameter * meterToFeet; double spacing = femRebar.spacing * meterToFeet; XYZ majorDirection = new XYZ(femRebar.majorDirection.x, femRebar.majorDirection.y, femRebar.majorDirection.z); Dictionary<string, int> isActiveDirection = new Dictionary<string, int>() { {"x top", 0}, {"x bottom", 0}, {"y top", 0}, {"y bottom", 0} }; isActiveDirection[femRebar.direction + " " + femRebar.layer] = 1; Element rebarHost = null; FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(AnalyticalModelSurface)).WhereElementIsNotElementType(); foreach (AnalyticalModelSurface s in fec) { //if(e.get_Parameter(new Guid("7f162ddd-61bb-43f5-9394-846db8aef825")) == null) continue; //if(e.get_Parameter(new Guid("7f162ddd-61bb-43f5-9394-846db8aef825")).AsString() == hostGuid) { //if (s.LookupParameter("StruXML Guid") == null) continue; //if (s.LookupParameter("StruXML Guid").AsString() == hostGuid) //{ // rebarHost = doc.GetElement(s.GetElementId()); // break; //} // FEM-design guid is stored in Extensible Storage if (s.GetEntity(Schema.Lookup(new Guid("3a97c049-093e-46e6-b854-0e2323d640d0"))) == null) continue; Entity ent = s.GetEntity(Schema.Lookup(new Guid("3a97c049-093e-46e6-b854-0e2323d640d0"))); if (ent.Get<Guid>("Guid").ToString() == hostGuid) { rebarHost = doc.GetElement(s.GetElementId()); break; } } //The boundary curves of the area rebar system IList<Curve> curveList = new List<Curve>(); foreach (FemDesignLine femLine in femRebar.regionCurves) { XYZ p1 = new XYZ(femLine.startPoint.x * meterToFeet, femLine.startPoint.y * meterToFeet, femLine.startPoint.z * meterToFeet); XYZ p2 = new XYZ(femLine.endPoint.x * meterToFeet, femLine.endPoint.y * meterToFeet, femLine.endPoint.z * meterToFeet); Line l1 = Line.CreateBound(p1, p2); curveList.Add(l1); } ElementId rebarTypeId = new FilteredElementCollector(doc).OfClass(typeof(RebarBarType)).Cast<RebarBarType>().FirstOrDefault(x => Math.Abs(x.BarDiameter - diameter) < 0.0001).Id; ElementId areaReinfType = new FilteredElementCollector(doc).OfClass(typeof(AreaReinforcementType)).FirstOrDefault().Id; //Create area reinforcement AreaReinforcement areaReinf1 = AreaReinforcement.Create(doc, rebarHost, curveList, majorDirection, areaReinfType, rebarTypeId, ElementId.InvalidElementId); //set spacing areaReinf1.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_1_GENERIC).Set(spacing); areaReinf1.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_2_GENERIC).Set(spacing); areaReinf1.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_1_GENERIC).Set(spacing); areaReinf1.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_2_GENERIC).Set(spacing); //Area reinforcement in Revit can have up to 4 layers and FEM-Design considers one at a time. Deactivating the three unused layers: areaReinf1.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(isActiveDirection["x top"]); areaReinf1.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(isActiveDirection["x bottom"]); areaReinf1.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(isActiveDirection["y top"]); areaReinf1.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(isActiveDirection["y bottom"]); //TODO: Cover //TODO: Option do remove area system, and correct spacing return areaReinf1; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { #region App Constants and instances UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; Selection sel = uidoc.Selection; #endregion #region Core Functionality // Retrieve elements from database Reference pickedObj = sel.PickObject(ObjectType.Element, "Please select an element to copy."); if (pickedObj != null && pickedObj.ElementId != ElementId.InvalidElementId) { Element element = doc.GetElement(pickedObj.ElementId); Element wall = element as Element; Debug.Print(wall.Name); AnalyticalModel analytical = wall.GetAnalyticalModel() as AnalyticalModel; if (null == analytical) { throw new Exception("Can't get AnalyticalModel from the selected wall"); } #region Path Reinforcement Implementation /* * List<Curve> curves = new List<Curve>(); * LocationCurve location = wall.Location as LocationCurve; * XYZ start = location.Curve.GetEndPoint(0); * XYZ end = location.Curve.GetEndPoint(1); * curves.Add(Line.CreateBound(start, end)); * ElementId defaultRebarBarTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.RebarBarType); * ElementId defaultPathReinforcementTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.PathReinforcementType); * ElementId defaultHookTypeId = ElementId.InvalidElementId; * * using (Transaction trans = new Transaction(doc)) * { * trans.Start("Arming.."); * * * PathReinforcement rein = PathReinforcement.Create(doc, wall, curves, true, defaultPathReinforcementTypeId, defaultRebarBarTypeId, defaultHookTypeId, defaultHookTypeId); * rein.AdditionalOffset = 10; * Console.WriteLine(rein.Parameters); * Console.WriteLine(); * Console.WriteLine(rein.ParametersMap); * Console.WriteLine(); * Console.WriteLine(rein.PrimaryBarOrientation); * Console.WriteLine(); * Console.WriteLine(rein.GetOrderedParameters()); * Console.WriteLine(); * Console.WriteLine(rein.GetSubelements()); * Console.WriteLine(); * * trans.Commit(); * } */ #endregion #region Area Reinforcement Implementation /* Area Reinforce */ AreaReinforcement rein = null; IList <Curve> curves = analytical.GetCurves(AnalyticalCurveType.ActiveCurves); Line firstLine = (Line)(curves[0]); XYZ majorDirection = new XYZ( firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X, firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y, firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z ); ElementId defaultRebarBarTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.RebarBarType); ElementId defaultAreaReinforcementTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.AreaReinforcementType); ElementId defaultHookTypeId = ElementId.InvalidElementId; using (Transaction trans = new Transaction(doc)) { trans.Start("Arming.."); rein = AreaReinforcement.Create(doc, wall, curves, majorDirection, defaultAreaReinforcementTypeId, defaultRebarBarTypeId, defaultHookTypeId); rein.AdditionalTopCoverOffset = 0; // any number <-- rein.AdditionalBottomCoverOffset = 0; // any number --> trans.Commit(); } /* * TaskDialog td = new TaskDialog("spacing?"); * td.MainInstruction = "spacing!"; * td.CommonButtons = TaskDialogCommonButtons.Yes; * td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "yes"); * td.Show(); */ using (Transaction trans = new Transaction(doc)) { IList <Parameter> parameters = rein.GetOrderedParameters(); //14 20 26! 32! var i = 0; trans.Start("Spacing.."); foreach (Parameter p in parameters) { //Debug.Print(p.Definition.Name); //Debug.Print(p.Definition.ParameterType.ToString()); // Debug.Print(i.ToString()); //Debug.Print(""); if (i == 14) { Debug.Print(p.Definition.Name + " will be 500.0"); p.SetValueString("500.0"); //»нтервал в основном направлении, наружна¤ грань } if (i == 20) { Debug.Print(p.Definition.Name + " will be 500.0"); p.SetValueString("500.0"); //»нтервал во второстепенном направлении, наружна¤ грань } if (i == 26) { Debug.Print(p.Definition.Name + " will be 500.0"); p.SetValueString("500.0"); // »нтервал в основном направлении, внутренн¤¤ грань } if (i == 32) { Debug.Print(p.Definition.Name + " will be 500.0"); p.SetValueString("500.0"); //»нтервал во второстепенном направлении, внутренн¤¤ грань } i += 1; } trans.Commit(); } #endregion } #endregion #region StandartFiltering for Future /* * FilteredElementCollector col * = new FilteredElementCollector(doc) * .WhereElementIsNotElementType() * .OfCategory(BuiltInCategory.INVALID) * .OfClass(typeof(Wall)); * * * // Filtered element collector is iterable * * foreach (Element e in col) * { * Debug.Print(e.Name); * } */ #endregion return(Result.Succeeded); }
/// <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); } } }
public static List <string> Generate(Document doc, Floor floor, RebarInfoFloor rif, ElementId areaTypeId) { Debug.WriteLine("RebarWorkerFloor is started"); List <string> messages = new List <string>(); MyRebarType mrt = new MyRebarType(doc, rif.rebarTypeName); if (mrt.isValid == false) { messages.Add("Не удалось получить тип стержня " + rif.rebarTypeName); } double interval = rif.interval; double topCoverUser = rif.topCover; double bottomCoverUser = rif.bottomCover; RebarCoverType coverTop = doc.GetElement(floor.get_Parameter(BuiltInParameter.CLEAR_COVER_TOP).AsElementId()) as RebarCoverType; RebarCoverType coverBottom = doc.GetElement(floor.get_Parameter(BuiltInParameter.CLEAR_COVER_BOTTOM).AsElementId()) as RebarCoverType; if (coverTop == null) { Debug.WriteLine("Top cover is null"); coverTop = coverBottom; } if (coverBottom == null) { Debug.WriteLine("Bottom cover is null"); coverBottom = coverTop; } Debug.WriteLine("Rebar cover types id, top: " + coverTop.Id.IntegerValue + ", bottom: " + coverBottom.Id.IntegerValue); #if R2017 || R2018 || R2019 || R2020 || R2021 double diam = mrt.bartype.BarDiameter; #else double diam = mrt.bartype.BarNominalDiameter; #endif double topCoverDir1 = topCoverUser - coverTop.CoverDistance; double topCoverDir2 = topCoverDir1 + diam; if (rif.turnTopBars) { topCoverDir1 += diam; topCoverDir2 -= diam; } double bottomCoverDir1 = bottomCoverUser - coverBottom.CoverDistance; double bottomCoverDir2 = bottomCoverDir1 + diam; if (rif.turnBottomBars) { bottomCoverDir1 += diam; bottomCoverDir2 -= diam; } List <Curve> curves = SupportGeometry.GetFloorOuterBoundary(floor); Debug.WriteLine("Boundary curves count: " + curves.Count); XYZ direction = new XYZ(1, 0, 0); if (rif.useDirection) { double angle = floor.SpanDirectionAngle; Transform rotateTransform = Transform.CreateRotationAtPoint(new XYZ(0, 0, 1), angle, new XYZ(0, 0, 0)); Line horizontal = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1, 0, 0)); Curve rotatedCurve = horizontal.CreateTransformed(rotateTransform); direction = rotatedCurve.GetEndPoint(1); } Debug.WriteLine("Direction: " + direction.ToString()); AreaReinforcement arTopX = AreaReinforcement .Create(doc, floor, curves, direction, areaTypeId, mrt.bartype.Id, ElementId.InvalidElementId); arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(1); arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(0); arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(0); arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(0); arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_1_GENERIC).Set(interval); arTopX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_TOP_OFFSET).Set(topCoverDir1); arTopX.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set("верх X фон"); Debug.WriteLine("Top X is created"); AreaReinforcement arTopY = AreaReinforcement .Create(doc, floor, curves, direction, areaTypeId, mrt.bartype.Id, ElementId.InvalidElementId); arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(0); arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(1); arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(0); arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(0); arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_2_GENERIC).Set(interval); arTopY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_TOP_OFFSET).Set(topCoverDir2); arTopY.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set("верх Y фон"); Debug.WriteLine("Top Y is created"); AreaReinforcement arBottomX = AreaReinforcement .Create(doc, floor, curves, direction, areaTypeId, mrt.bartype.Id, ElementId.InvalidElementId); arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(0); arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(0); arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(1); arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(0); arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_1_GENERIC).Set(interval); arBottomX.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_BOTTOM_OFFSET).Set(bottomCoverDir1); arBottomX.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set("низ X фон"); Debug.WriteLine("Bottom X is created"); AreaReinforcement arBottomY = AreaReinforcement .Create(doc, floor, curves, direction, areaTypeId, mrt.bartype.Id, ElementId.InvalidElementId); arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1_GENERIC).Set(0); arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2_GENERIC).Set(0); arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1_GENERIC).Set(0); arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2_GENERIC).Set(1); arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_2_GENERIC).Set(interval); arBottomY.get_Parameter(BuiltInParameter.REBAR_SYSTEM_ADDL_BOTTOM_OFFSET).Set(bottomCoverDir2); arBottomY.get_Parameter(BuiltInParameter.NUMBER_PARTITION_PARAM).Set("низ Y фон"); Debug.WriteLine("Bottom Y is created"); return(messages); }
/// <summary> /// check whether the selected is expected, find all hooktypes in current project /// </summary> /// <param name="selected">selected elements</param> /// <returns>whether the selected AreaReinforcement is expected</returns> private bool PreData() { ElementSet selected = m_commandData.Application.ActiveUIDocument.Selection.Elements; //selected is not only one AreaReinforcement if( selected.Size != 1 ) { return false; } foreach( Object o in selected ) { m_areaRein = o as AreaReinforcement; } if( null == m_areaRein ) { return false; } //make sure hook type and bar type exist in current project and get them m_hookTypes = new Hashtable(); m_barTypes = new Hashtable(); Document activeDoc = m_commandData.Application.ActiveUIDocument.Document; FilteredElementIterator itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarHookType)).GetElementIterator(); itor.Reset(); while( itor.MoveNext() ) { RebarHookType hookType = itor.Current as RebarHookType; if( null != hookType ) { string hookTypeName = hookType.Name; m_hookTypes.Add( hookTypeName, hookType.Id ); } } itor = (new FilteredElementCollector(activeDoc)).OfClass(typeof(RebarBarType)).GetElementIterator(); itor.Reset(); while (itor.MoveNext()) { RebarBarType barType = itor.Current as RebarBarType; if( null != barType ) { string barTypeName = barType.Name; m_barTypes.Add( barTypeName, barType.Id ); } } if( m_hookTypes.Count == 0 || m_barTypes.Count == 0 ) { return false; } return true; }
// Назначение параметров для RebarBarType private static AreaReinforcement SetDirectionAndSpacing( AreaReinforcement areaReinforcement, RebarArea rebarArea) { Direction direction = rebarArea.Direction; if (rebarArea.Spacing < 100) { throw new Exception(string.Format("{0} - шаг арматуры мешьше 100 мм", rebarArea.AreaReinforcementType.Name)); } double rebarSpacing = rebarArea.Spacing * mmToft; Parameter direction_top_major_X = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_1); Parameter direction_top_minor_Y = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_ACTIVE_TOP_DIR_2); Parameter direction_bottom_major_X = areaReinforcement.get_Parameter( BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_1); Parameter direction_bottom_minor_Y = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_ACTIVE_BOTTOM_DIR_2); switch (direction) { case Direction.TopMajor: direction_top_major_X.Set(1); direction_top_minor_Y.Set(0); direction_bottom_major_X.Set(0); direction_bottom_minor_Y.Set(0); Parameter spacing_top_major_X = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_1); spacing_top_major_X.Set(rebarSpacing); break; case Direction.TopMinor: direction_top_major_X.Set(0); direction_top_minor_Y.Set(1); direction_bottom_major_X.Set(0); direction_bottom_minor_Y.Set(0); Parameter spacing_top_minor_Y = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_SPACING_TOP_DIR_2); spacing_top_minor_Y.Set(rebarSpacing); Parameter add_top_cover = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_ADDL_TOP_OFFSET); add_top_cover.Set(rebarArea.RebarBarType.BarDiameter); break; case Direction.BottomMajor: direction_top_major_X.Set(0); direction_top_minor_Y.Set(0); direction_bottom_major_X.Set(1); direction_bottom_minor_Y.Set(0); Parameter spacing_bottom_major_X = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_1); spacing_bottom_major_X.Set(rebarSpacing); break; case Direction.BottomMinor: direction_top_major_X.Set(0); direction_top_minor_Y.Set(0); direction_bottom_major_X.Set(0); direction_bottom_minor_Y.Set(1); Parameter spacing_bottom_minor_Y = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_SPACING_BOTTOM_DIR_2); spacing_bottom_minor_Y.Set(rebarSpacing); Parameter add_bottom_cover = areaReinforcement.get_Parameter (BuiltInParameter.REBAR_SYSTEM_ADDL_BOTTOM_OFFSET); add_bottom_cover.Set(rebarArea.RebarBarType.BarDiameter); break; } return(areaReinforcement); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string assemblyFolder = System.IO.Path.GetDirectoryName(assemblyPath); string shortcutsXmlPath = System.IO.Path.Combine(assemblyFolder, "KeyboardShortcuts.xml"); string idsFilePath = System.IO.Path.Combine(assemblyFolder, "ids.txt"); string speedFilePath = System.IO.Path.Combine(assemblyFolder, "speed.txt"); string speedString = "5"; if (System.IO.File.Exists(speedFilePath)) { speedString = System.IO.File.ReadAllText(speedFilePath); } int speed = int.Parse(speedString); DialogWindowRestoreAreaRebar form = new DialogWindowRestoreAreaRebar(shortcutsXmlPath, speed); if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(Result.Cancelled); } speed = form.speed; Document doc = commandData.Application.ActiveUIDocument.Document; Selection sel = commandData.Application.ActiveUIDocument.Selection; List <ElementId> selids = sel.GetElementIds().ToList(); List <AreaReinforcement> ars = new List <AreaReinforcement>(); foreach (ElementId id in selids) { AreaReinforcement ar = doc.GetElement(id) as AreaReinforcement; if (ar != null) { ars.Add(ar); } } if (ars.Count == 0) { message += "Выберите арматуру по площади"; return(Result.Failed); } if (System.IO.File.Exists(idsFilePath)) { System.IO.File.Delete(idsFilePath); } using (System.IO.StreamWriter idsFileWriter = System.IO.File.CreateText(idsFilePath)) { foreach (AreaReinforcement ar in ars) { string line = ar.Id.IntegerValue.ToString() + ":"; List <ElementId> curveIds = ar.GetBoundaryCurveIds().ToList(); foreach (ElementId id in curveIds) { line = line + id.IntegerValue.ToString() + ","; } idsFileWriter.WriteLine(line); } idsFileWriter.Close(); } using (System.IO.StreamWriter speedFileWriter = System.IO.File.CreateText(speedFilePath)) { speedFileWriter.Write(speed.ToString()); speedFileWriter.Close(); } string scriptPath = System.IO.Path.Combine(assemblyFolder, "RestoreAreaRebar.exe"); //нужно сбросить выделение, если есть выбранные элементы commandData.Application.ActiveUIDocument.Selection.SetElementIds(new List <ElementId>()); //запускаю супер-програмку System.Diagnostics.Process.Start(scriptPath); return(Result.Succeeded); }
/// <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); } } }
/// <summary> /// fill in data with given AreaReinforcement /// </summary> /// <param name="areaRein"></param> /// <returns></returns> public bool FillInData(AreaReinforcement areaRein) { bool flag = false; //member m_layoutRule = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_LAYOUT_RULE); flag = (m_layoutRule != null); //top major layer m_topMajorBarType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_TOP_DIR_1); m_topMajorHookType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_TOP_DIR_1); m_topMajorHookOrientation = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_1); flag &= (m_topMajorBarType != null) && (m_topMajorHookOrientation != null) && (m_topMajorHookType != null); //top minor layer m_topMinorBarType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_TOP_DIR_2); m_topMinorHookType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_TOP_DIR_2); m_topMinorHookOrientation = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_2); flag &= (m_topMinorBarType != null) && (m_topMinorHookOrientation != null) && (m_topMinorHookType != null); //bottom major layer m_bottomMajorBarType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_BOTTOM_DIR_1); m_bottomMajorHookType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_BOTTOM_DIR_1); m_bottomMajorHookOrientation = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_BOTTOM_DIR_1); flag &= (m_bottomMajorBarType != null) && (m_bottomMajorHookOrientation != null) && (m_bottomMajorHookType != null); //bottom minor layer m_bottomMinorBarType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_BAR_TYPE_BOTTOM_DIR_2); m_bottomMinorHookType = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_TYPE_BOTTOM_DIR_2); m_bottomMinorHookOrientation = areaRein.get_Parameter( BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_BOTTOM_DIR_2); flag &= (m_bottomMinorBarType != null) && (m_bottomMinorHookOrientation != null) && (m_bottomMinorHookType != null); return flag; }