예제 #1
0
        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;
        }
예제 #2
0
        public static List <FemDesignRebar> GetFemRebars()
        {
            var fileContent = string.Empty;
            var filePath    = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                openFileDialog.Filter           = "struxml files (*.struxml)|*.struxml|All files (*.*)|*.*";
                openFileDialog.FilterIndex      = 1;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = openFileDialog.FileName;
                }
            }

            XDocument xmlDoc = XDocument.Load(filePath);
            //XNamespace ns = "urn:strusoft";
            XNamespace ns = xmlDoc.Root.GetDefaultNamespace();

            IEnumerable <XElement> rebarElements = xmlDoc.Root.Element(ns + "entities").Elements(ns + "surface_reinforcement");
            List <FemDesignRebar>  femRebarList  = new List <FemDesignRebar>();

            foreach (XElement xe in rebarElements)
            {
                FemDesignRebar femRebar = new FemDesignRebar()
                {
                    hostGuid            = xe.Element(ns + "base_shell").Attribute("guid").Value,
                    rebarParametesrGuid = xe.Element(ns + "surface_reinforcement_parameters").Attribute("guid").Value,
                    layer     = xe.Element(ns + "straight").Attribute("face").Value,
                    direction = xe.Element(ns + "straight").Attribute("direction").Value,
                };
                femRebar.SetSpacing(xe.Element(ns + "straight").Attribute("space").Value);
                femRebar.SetCover(xe.Element(ns + "straight").Attribute("cover").Value);
                femRebar.SetDiameter(xe.Element(ns + "wire").Attribute("diameter").Value);

                // Get geometry
                IEnumerable <XElement> edges = xe.Element(ns + "region").Element(ns + "contour").Elements(ns + "edge");
                foreach (XElement edge in edges)
                {
                    XElement     startPoint   = edge.Elements(ns + "point").First();
                    XElement     endPoint     = edge.Elements(ns + "point").ElementAt(1);
                    XElement     normal       = edge.Element(ns + "normal");
                    FemDesignXYZ startPt      = new FemDesignXYZ(startPoint.Attribute("x").Value, startPoint.Attribute("y").Value, startPoint.Attribute("z").Value);
                    FemDesignXYZ endPt        = new FemDesignXYZ(endPoint.Attribute("x").Value, endPoint.Attribute("y").Value, endPoint.Attribute("z").Value);
                    FemDesignXYZ normalVector = new FemDesignXYZ(normal.Attribute("x").Value, normal.Attribute("y").Value, normal.Attribute("z").Value);
                    femRebar.regionCurves.Add(new FemDesignLine(startPt, endPt, normalVector));
                }

                // Get major direction
                XElement     reinforcementParameters = xmlDoc.Root.Element(ns + "entities").Elements(ns + "surface_reinforcement_parameters").First(e => e.Attribute("guid").Value == femRebar.rebarParametesrGuid);
                XElement     xVec       = reinforcementParameters.Element(ns + "x_direction");
                FemDesignXYZ xDirection = new FemDesignXYZ(xVec.Attribute("x").Value, xVec.Attribute("y").Value, xVec.Attribute("z").Value);
                femRebar.majorDirection = xDirection;
                femRebarList.Add(femRebar);
            }
            return(femRebarList);
        }