Ejemplo n.º 1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Application app = commandData.Application.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            IList<Reference> ref2List = new List<Reference>();

            try
            {
                ref2List = uidoc.Selection.PickObjects(ObjectType.Element, new WallOrBeamSelectFilter(), "Pick walls and/or beams to disallow join in both ends");
            }
            catch(Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                message = "Command cancelled, Click finish in top left corner to complete the command";
                return Result.Cancelled;
            }

            using (Transaction t1 = new Transaction(doc, "Dissalow Join"))
            {
                t1.Start();
                foreach (Reference r in ref2List)
                {
                    Element e = doc.GetElement(r);
                    if (e is Wall)
                    {
                        Wall wall = e as Wall;
                        WallUtils.DisallowWallJoinAtEnd(wall, 0);
                        WallUtils.DisallowWallJoinAtEnd(wall, 1);
                    }
                    else if (e.Category.Id.IntegerValue == (int) BuiltInCategory.OST_StructuralFraming) {
                        FamilyInstance familyInstance = e as FamilyInstance;
                        StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 0);
                        StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 1);
                    }
                }

                t1.Commit();
            }
            return Result.Succeeded;
        }
Ejemplo n.º 2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;



            ISelectionFilter  beamFilter = new CategorySelectionFilter("Structural Framing");
            IList <Reference> refsBeams  = uidoc.Selection.PickObjects(ObjectType.Element, beamFilter, "Select Beams");

            using (var form = new FormJoin())
            {
                form.ShowDialog();

                if (form.DialogResult == winForm.DialogResult.Cancel)
                {
                    return(Result.Cancelled);
                }


                using (Transaction t = new Transaction(doc, "Edit Beam Join"))
                {
                    t.Start();

                    foreach (Reference r in refsBeams)
                    {
                        FamilyInstance ele = doc.GetElement(r) as FamilyInstance;

                        if (form.allowStartValue)
                        {
                            StructuralFramingUtils.AllowJoinAtEnd(ele, 0);
                        }

                        if (form.allowEndValue)
                        {
                            StructuralFramingUtils.AllowJoinAtEnd(ele, 1);
                        }

                        if (form.disallowStartValue)
                        {
                            StructuralFramingUtils.DisallowJoinAtEnd(ele, 0);
                        }

                        if (form.disallowEndValue)
                        {
                            StructuralFramingUtils.DisallowJoinAtEnd(ele, 1);
                        }

                        if (form.miterStart)
                        {
                            ele.ExtensionUtility.set_Extended(0, true);
                        }

                        if (form.miterEnd)
                        {
                            ele.ExtensionUtility.set_Extended(1, true);
                        }
                    }

                    t.Commit();
                }//close using

                return(Result.Succeeded);
            }//close form using
        }
Ejemplo n.º 3
0
        public List <ApplicationPlaceholderObject> ColumnToNative(Column speckleColumn)
        {
            if (speckleColumn.baseLine == null)
            {
                throw new Speckle.Core.Logging.SpeckleException("Only line based Beams are currently supported.");
            }

            DB.FamilySymbol familySymbol = GetElementType <FamilySymbol>(speckleColumn);
            var             baseLine     = CurveToNative(speckleColumn.baseLine).get_Item(0);

            // If the start point elevation is higher than the end point elevation, reverse the line.
            if (baseLine.GetEndPoint(0).Z > baseLine.GetEndPoint(1).Z)
            {
                baseLine = DB.Line.CreateBound(baseLine.GetEndPoint(1), baseLine.GetEndPoint(0));
            }

            DB.Level          level       = null;
            DB.Level          topLevel    = null;
            DB.FamilyInstance revitColumn = null;
            //var structuralType = StructuralType.Column;
            var isLineBased = true;

            var speckleRevitColumn = speckleColumn as RevitColumn;

            if (speckleRevitColumn != null)
            {
                level    = LevelToNative(speckleRevitColumn.level);
                topLevel = LevelToNative(speckleRevitColumn.topLevel);
                //structuralType = speckleRevitColumn.structural ? StructuralType.Column : StructuralType.NonStructural;
                //non slanted columns are point based
                isLineBased = speckleRevitColumn.isSlanted;
            }

            if (level == null)
            {
                level    = LevelToNative(LevelFromCurve(baseLine));
                topLevel = LevelToNative(LevelFromPoint(baseLine.GetEndPoint(1)));
            }

            //try update existing
            var  docObj   = GetExistingElementByApplicationId(speckleColumn.applicationId);
            bool isUpdate = false;

            if (docObj != null)
            {
                try
                {
                    var revitType = Doc.GetElement(docObj.GetTypeId()) as ElementType;

                    // if family changed, tough luck. delete and let us create a new one.
                    if (familySymbol.FamilyName != revitType.FamilyName)
                    {
                        Doc.Delete(docObj.Id);
                    }
                    else
                    {
                        revitColumn = (DB.FamilyInstance)docObj;
                        switch (revitColumn.Location)
                        {
                        case LocationCurve crv:
                            crv.Curve = baseLine;
                            break;

                        case LocationPoint pt:
                            pt.Point = baseLine.GetEndPoint(0);
                            break;
                        }

                        // check for a type change
                        if (!string.IsNullOrEmpty(familySymbol.FamilyName) && familySymbol.FamilyName != revitType.Name)
                        {
                            revitColumn.ChangeTypeId(familySymbol.Id);
                        }
                    }
                    isUpdate = true;
                }
                catch { }
            }

            if (revitColumn == null && isLineBased)
            {
                revitColumn = Doc.Create.NewFamilyInstance(baseLine, familySymbol, level, StructuralType.Column);
                if (revitColumn.Symbol.Family.FamilyPlacementType == FamilyPlacementType.CurveDrivenStructural)
                {
                    StructuralFramingUtils.DisallowJoinAtEnd(revitColumn, 0);
                    StructuralFramingUtils.DisallowJoinAtEnd(revitColumn, 1);
                }
            }

            //try with a point based column
            if (speckleRevitColumn != null && revitColumn == null && !isLineBased)
            {
                var start = baseLine.GetEndPoint(0);
                var end   = baseLine.GetEndPoint(1);

                var basePoint = start.Z < end.Z ? start : end; // pick the lowest
                revitColumn = Doc.Create.NewFamilyInstance(basePoint, familySymbol, level, StructuralType.NonStructural);
                //
                //rotate, we know it must be a RevitColumn
                var axis = DB.Line.CreateBound(new XYZ(basePoint.X, basePoint.Y, 0), new XYZ(basePoint.X, basePoint.Y, 1000));
                (revitColumn.Location as LocationPoint).Rotate(axis, speckleRevitColumn.rotation - (revitColumn.Location as LocationPoint).Rotation);
            }

            if (revitColumn == null)
            {
                throw (new Exception($"Failed to create column for {speckleColumn.applicationId}."));
            }

            TrySetParam(revitColumn, BuiltInParameter.FAMILY_BASE_LEVEL_PARAM, level);
            TrySetParam(revitColumn, BuiltInParameter.FAMILY_TOP_LEVEL_PARAM, topLevel);


            if (speckleRevitColumn != null)
            {
                if (speckleRevitColumn.handFlipped != revitColumn.HandFlipped)
                {
                    revitColumn.flipHand();
                }

                if (speckleRevitColumn.facingFlipped != revitColumn.FacingFlipped)
                {
                    revitColumn.flipFacing();
                }

                //do change offset for slanted columns, it's automatic
                if (!isLineBased)
                {
                    SetOffsets(revitColumn, speckleRevitColumn);
                }

                SetInstanceParameters(revitColumn, speckleRevitColumn);
            }

            var placeholders = new List <ApplicationPlaceholderObject>()
            {
                new ApplicationPlaceholderObject {
                    applicationId = speckleColumn.applicationId, ApplicationGeneratedId = revitColumn.UniqueId, NativeObject = revitColumn
                }
            };

            // TODO: nested elements.
            Report.Log($"{(isUpdate ? "Updated" : "Created")} Column {revitColumn.Id}");
            return(placeholders);
        }
Ejemplo n.º 4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            Autodesk.Revit.DB.Document doc = uidoc.Document;
            Transaction trans = new Transaction(doc);

            trans.Start("交易開始");

            //訂定土體範圍
            List <XYZ> topxyz = new List <XYZ>();
            XYZ        t1     = new XYZ(-200, -200, 0);
            XYZ        t2     = new XYZ(200, -200, 0);
            XYZ        t3     = new XYZ(200, 200, 0);
            XYZ        t4     = new XYZ(-200, 200, 0);

            topxyz.Add(t1 * 1000 / 304.8);
            topxyz.Add(t2 * 1000 / 304.8);
            topxyz.Add(t3 * 1000 / 304.8);
            topxyz.Add(t4 * 1000 / 304.8);
            TopographySurface.Create(doc, topxyz);

            //開挖深度所需參數
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.OfClass(typeof(BuildingPadType));
            BuildingPadType bdtp = collector.FirstElement() as BuildingPadType;

            csv_read csv = new csv_read();

            csv.Main();

            //開挖各階之深度輸入
            List <double> height = new List <double>();

            foreach (var data in csv.excaLevel)
            {
                height.Add(data.Item2 * -1);
            }

            //建立開挖階數
            Level[] levlist = new Level[height.Count()];
            for (int i = 0; i != height.Count(); i++)
            {
                levlist[i]      = Level.Create(doc, height[i] * 1000 / 304.8);
                levlist[i].Name = "開挖階數" + (i + 1).ToString();
            }

            double wallLength = csv.Wall_length;
            Level  DW_level   = Level.Create(doc, wallLength * -1 * 1000 / 304.8);

            //建立回築樓層
            Level[] re_levlist = new Level[csv.back.Count()];
            for (int i = 0; i != csv.back.Count(); i++)
            {
                re_levlist[i]      = Level.Create(doc, (csv.back[i].Item2 * -1 + csv.back[i].Item3 / (2)) * 1000 / 304.8);
                re_levlist[i].Name = (csv.back[i].Item1).ToString();
            }
            Level[] all_level_list = new Level[levlist.Count() + re_levlist.Count()];
            all_level_list = levlist.Concat(re_levlist).ToArray();

            //訂定開挖範圍
            IList <CurveLoop> profileloops      = new List <CurveLoop>();
            IList <Curve>     wall_profileloops = new List <Curve>();

            //須回到原點

            XYZ[] points = new XYZ[csv.excaRange.Count()];

            for (int i = 0; i != csv.excaRange.Count(); i++)
            {
                points[i] = new XYZ(csv.excaRange[i].Item1, csv.excaRange[i].Item2, 0) * 1000 / 304.8;
            }

            CurveLoop profileloop = new CurveLoop();

            for (int i = 0; i < points.Count() - 1; i++)
            {
                Line line = Line.CreateBound(points[i], points[i + 1]);
                wall_profileloops.Add(line);
                profileloop.Append(line);
            }
            profileloops.Add(profileloop);
            Level levdeep = null;

            //建立開挖深度
            ICollection <Level> level_familyinstance = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast <Level>().ToList();

            foreach (Level lev in level_familyinstance)
            {
                if (lev.Name == levlist[levlist.Count() - 1].Name)
                {
                    BuildingPad b = BuildingPad.Create(doc, bdtp.Id, lev.Id, profileloops);
                    levdeep = lev;
                }
            }

            //建立連續壁
            IList <Curve>          inner_wall_curves       = new List <Curve>();
            double                 wall_W                  = csv.Wall_width * 1000; //連續壁厚度
            List <Wall>            inner_wall              = new List <Wall>();
            ICollection <WallType> walltype_familyinstance = new FilteredElementCollector(doc).OfClass(typeof(WallType)).Cast <WallType>().ToList();

            foreach (WallType walltype in walltype_familyinstance)
            {
                if (walltype.Name == "連續壁")
                {
                    for (int i = 0; i < points.Count <XYZ>() - 1; i++)
                    {
                        Curve c = wall_profileloops[i].CreateOffset(wall_W / 2 / 304.8, new XYZ(0, 0, -1)); //偏移連續壁厚度1/2的距離,做為建置參考線
                        Wall  w = Wall.Create(doc, c, walltype.Id, DW_level.Id, wallLength * 1000 / 304.8, 0, false, false);
                        w.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set("連續壁");
                        inner_wall.Add(w);
                    }
                }
            }

            trans.Commit();

            //取得連續壁內座標點
            XYZ[] innerwall_points           = new XYZ[points.Count <XYZ>()];
            XYZ[] for_check_innerwall_points = new XYZ[points.Count <XYZ>()]; //計算支撐中間樁之擺放界線
            for (int i = 0; i < (inner_wall.Count <Wall>()); i++)
            {
                //inner
                XYZ wall_curve_point = (inner_wall[i].Location as LocationCurve).Curve.Tessellate()[0];
                wall_curve_point              = new XYZ(wall_curve_point.X, wall_curve_point.Y, 0);
                innerwall_points[i]           = points[i] - (points[i] - wall_curve_point) * 2;
                for_check_innerwall_points[i] = points[i] - (points[i] - wall_curve_point) * 1.4; //計算支撐中間樁之擺放界線
            }
            innerwall_points[points.Count <XYZ>() - 1]           = innerwall_points[0];
            for_check_innerwall_points[points.Count <XYZ>() - 1] = for_check_innerwall_points[0];

            //取得側牆profile
            IList <CurveLoop> bdtpCurve = new List <CurveLoop>();
            IList <Curve>     side_wall_profileloops = new List <Curve>();
            CurveLoop         bdtploop = new CurveLoop();

            for (int i = 0; i < innerwall_points.Count() - 1; i++)
            {
                Line line = Line.CreateBound(innerwall_points[i], innerwall_points[i + 1]);
                side_wall_profileloops.Add(line);
                bdtploop.Append(line);
            }

            //trans.commit();

            trans.Start("inner_buildingpad");
            // /*
            bdtpCurve.Add(bdtploop);
            //建立開挖深度
            ICollection <Level> level_family = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast <Level>().ToList();

            foreach (Level lev in level_family)
            {
                if (lev.Name == levlist[levlist.Count() - 1].Name)
                {
                    BuildingPad b = BuildingPad.Create(doc, bdtp.Id, lev.Id, bdtpCurve);
                    //b.get_Parameter(BuiltInParameter.)
                    //b.LookupParameter("厚度").SetValueString("1");
                    levdeep = lev;
                }
            }
            // */
            trans.Commit();

            trans.Start("side_wall");
            //建立側牆
            List <Wall> side_wall = new List <Wall>();

            foreach (WallType walltype in walltype_familyinstance)
            {
                if (walltype.Name == "側牆")
                {
                    for (int i = 0; i < csv.sidewall.Count; i++)
                    {
                        double floor_width  = csv.back[i].Item3 * 1000 / 304.8;                                   //set the width to a new value
                        double floor_deep   = -csv.back[i].Item2 * 1000 / 304.8;
                        double floor_bottom = (floor_deep + floor_width / 2);                                     //側牆底部高程點(考慮厚度做offset後-往上半個厚度)
                        double floor_top    = (csv.back[i + 1].Item2 + csv.back[i + 1].Item3 / 2) * 1000 / 304.8; //側牆頂部高程點(考慮厚度做offset後-往下半個厚度)
                        for (int j = 0; j < points.Count <XYZ>() - 1; j++)
                        {
                            Curve side_c = side_wall_profileloops[j].CreateOffset((csv.sidewall[i].Item2 * 1000 / 2) / 304.8, new XYZ(0, 0, -1)); //此步驟為偏移擋土牆厚度1/2距離,作為建置參考線
                            Wall  side_w = Wall.Create(doc, side_c, walltype.Id, re_levlist[i].Id, (floor_bottom * (-1) - floor_top), 0, false, false);
                            side_w.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set(csv.sidewall[i].Item1 + "側牆");
                            side_wall.Add(side_w);
                        }
                    }
                }
            }
            trans.Commit();

            //取得側牆牆點座標
            CurveArray profileloops_array = new CurveArray();

            XYZ[] sidewall_points = new XYZ[points.Count <XYZ>()];
            for (int i = 0; i < (inner_wall.Count <Wall>()); i++)
            {
                //side
                XYZ side_wall_curve_point = (side_wall[i].Location as LocationCurve).Curve.Tessellate()[0];
                side_wall_curve_point = new XYZ(side_wall_curve_point.X, side_wall_curve_point.Y, 0);
                sidewall_points[i]    = innerwall_points[i] - (innerwall_points[i] - side_wall_curve_point) * 2;
            }
            sidewall_points[points.Count <XYZ>() - 1] = sidewall_points[0];

            //建立底板範圍
            for (int i = 0; i < points.Count() - 1; i++)
            {
                Line line = Line.CreateBound(innerwall_points[i], innerwall_points[i + 1]);
                profileloops_array.Append(line);
            }

            trans.Start("建立底板");

            //建立底板類型及實作元件
            ICollection <FloorType> family = new FilteredElementCollector(doc).OfClass(typeof(FloorType)).Cast <FloorType>().ToList();
            FloorType floor_type           = family.Where(x => x.Name == "通用 300mm").First();
            int       base_control         = 0;

            foreach (Tuple <string, double, double, double> base_tuple in csv.back)
            {
                FloorType newFamSym = null;
                try { newFamSym = floor_type.Duplicate(base_tuple.Item1) as FloorType; } catch { newFamSym = family.Where(x => x.Name == base_tuple.Item1).First(); }
                double floor_width  = base_tuple.Item3 * 1000 / 304.8; //set the width to a new value
                double floor_deep   = base_tuple.Item2 * -1 * 1000 / 304.8;
                double floor_offset = (floor_deep + floor_width / 2) * 304.8;
                newFamSym.GetCompoundStructure().GetLayers()[0].Width = floor_width;
                CompoundStructure ly = newFamSym.GetCompoundStructure();
                ly.SetLayerWidth(0, floor_width);
                newFamSym.SetCompoundStructure(ly);
                Floor floor = doc.Create.NewFloor(profileloops_array, newFamSym as FloorType, re_levlist[base_control], false);
                floor.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set(base_tuple.Item1);
                floor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).SetValueString("0");
                base_control += 1;
            }
            trans.Commit();

            //取得所有XY數值
            List <double> Xs = new List <double>();
            List <double> Ys = new List <double>();

            double[] slope = new double[inner_wall.Count <Wall>()];
            double[] bias  = new double[inner_wall.Count <Wall>()];
            for (int i = 0; i < (innerwall_points.Count <XYZ>()); i++)
            {
                Xs.Add(innerwall_points[i].X);
                Ys.Add(innerwall_points[i].Y);
                if (i < slope.Count())
                {
                    if (innerwall_points[i + 1].X - innerwall_points[i].X == 0)
                    {
                        slope[i] = 20172018;
                        bias[i]  = innerwall_points[i + 1].X;
                    }
                    else
                    {
                        slope[i] = (innerwall_points[i + 1].Y - innerwall_points[i].Y) / (innerwall_points[i + 1].X - innerwall_points[i].X);
                        if (slope[i] == 0 || Math.Abs(slope[i]) < 0.0000001)
                        {
                            bias[i] = innerwall_points[i + 1].Y;
                        }
                        else
                        {
                            bias[i] = innerwall_points[i + 1].Y - slope[i] * innerwall_points[i + 1].X;
                        }
                    }
                }
            }

            Transaction trans_2 = new Transaction(doc);

            trans_2.Start("交易開始");
            //開始建立中間樁
            double columns_dis = csv.centralCol[0].Item1 * 1000 / 304.8; //中間樁間距
            ICollection <FamilySymbol> columns_familyinstance = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>().ToList();

            foreach (FamilySymbol column_type in columns_familyinstance)
            {
                if (column_type.Name == "中間樁")
                {
                    for (int j = 0; j < (Math.Abs(Ys.Max() - Ys.Min()) / columns_dis - 1); j++)
                    {
                        for (int i = 0; i < (Math.Abs(Xs.Max() - Xs.Min()) / columns_dis - 1); j++)
                        {
                            XYZ column_location = new XYZ(Xs.Min() + (i + 1) * columns_dis, Ys.Min() + (j + 1) * columns_dis, 0);
                            if (IsInPolygon(column_location, innerwall_points) == true)
                            {
                                //TaskDialog.Show("asd", "asd");
                                FamilyInstance column_instance = doc.Create.NewFamilyInstance(column_location, column_type, levdeep, Autodesk.Revit.DB.Structure.StructuralType.Column);
                                column_instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).SetValueString("0"); //中間樁長度
                                column_instance.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set("中間樁");
                            }
                        }
                    }
                }
            }

            //迴圈起始點
            for (int lev = 0; lev != csv.supLevel.Count(); lev++)
            {
                //建立圍囹
                //開始建立圍囹
                ICollection <FamilySymbol> beam_familyinstance = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>().ToList();
                foreach (FamilySymbol beam_type in beam_familyinstance)
                {
                    if (beam_type.Name == "H100x100")
                    {
                        double beam_H = double.Parse(beam_type.LookupParameter("H").AsValueString());
                        double beam_B = double.Parse(beam_type.LookupParameter("B").AsValueString());
                        for (int i = 0; i < innerwall_points.Count <XYZ>() - 1; i++)
                        {
                            Curve c = null;
                            if (i == points.Count <XYZ>())
                            {
                                try { int.Parse(csv.supLevel[lev].Item1.ToString()); c = Line.CreateBound(innerwall_points[i], innerwall_points[0]).CreateOffset((beam_H) / 304.8, new XYZ(0, 0, -1)); }
                                catch { c = Line.CreateBound(sidewall_points[i], sidewall_points[0]).CreateOffset((beam_H) / 304.8, new XYZ(0, 0, -1)); }
                            }
                            else
                            {
                                try { int.Parse(csv.supLevel[lev].Item1.ToString()); c = Line.CreateBound(innerwall_points[i], innerwall_points[i + 1]).CreateOffset((beam_H) / 304.8, new XYZ(0, 0, -1)); }
                                catch { c = Line.CreateBound(sidewall_points[i], sidewall_points[i + 1]).CreateOffset((beam_H) / 304.8, new XYZ(0, 0, -1)); }
                            }
                            FamilyInstance beam = doc.Create.NewFamilyInstance(c, beam_type, levlist[0], Autodesk.Revit.DB.Structure.StructuralType.Beam);
                            beam.LookupParameter("斷面旋轉").SetValueString("90");
                            StructuralFramingUtils.DisallowJoinAtEnd(beam, 0);
                            StructuralFramingUtils.DisallowJoinAtEnd(beam, 1);
                            beam.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set((csv.supLevel[lev].Item1).ToString() + "-圍囹");

                            //判斷圍囹之垂直深度,斜率零為負,反之為正

                            if ((i % 2 == 0))
                            {
                                beam.get_Parameter(BuiltInParameter.Y_OFFSET_VALUE).SetValueString((csv.supLevel[lev].Item2 * 1000 - beam_B / 2).ToString()); //2000為支撐階數深度,表1中
                            }
                            else
                            {
                                beam.get_Parameter(BuiltInParameter.Y_OFFSET_VALUE).SetValueString((csv.supLevel[lev].Item2 * 1000 + beam_B / 2).ToString());
                            }
                        }
                    }
                }

                //開始建立支撐
                //建立支撐

                XYZ frame_startpoint = null;
                XYZ frame_endpoint   = null;

                ICollection <FamilySymbol> frame_familyinstance = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>().ToList();

                foreach (FamilySymbol frame_type in frame_familyinstance)
                {
                    if (frame_type.Name == "H100x100")
                    {
                        double frame_H = double.Parse(frame_type.LookupParameter("H").AsValueString());

                        //X向支撐
                        for (int j = 0; j < Math.Abs(Ys.Max() - Ys.Min()) / columns_dis - 1; j++)
                        {
                            for (int i = 0; i < Math.Abs(Xs.Max() - Xs.Min()) / columns_dis - 1; i++)
                            {
                                XYZ frame_location = new XYZ(Xs.Min() + (i + 1) * columns_dis, Ys.Min() + (j + 1) * columns_dis, 0);
                                frame_startpoint = intersection(frame_location, for_check_innerwall_points, slope, bias, true)[0];
                                if (IsInPolygon(frame_location, innerwall_points) == true)
                                {
                                    try
                                    {
                                        frame_endpoint = intersection(frame_location, for_check_innerwall_points, slope, bias, true)[1];
                                        Line           line           = Line.CreateBound(frame_startpoint, frame_endpoint);
                                        FamilyInstance frame_instance = doc.Create.NewFamilyInstance(line, frame_type, levdeep, Autodesk.Revit.DB.Structure.StructuralType.Beam);
                                        frame_instance.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set((csv.supLevel[lev].Item1).ToString() + "-支撐");
                                        //處理偏移與延伸問題
                                        frame_instance.get_Parameter(BuiltInParameter.Z_OFFSET_VALUE).SetValueString((csv.supLevel[lev].Item2 * -1000).ToString());
                                        frame_instance.get_Parameter(BuiltInParameter.Y_OFFSET_VALUE).SetValueString((-frame_H).ToString());
                                        try
                                        {
                                            int.Parse(csv.supLevel[lev].Item1.ToString());
                                            frame_instance.get_Parameter(BuiltInParameter.START_EXTENSION).SetValueString((-frame_H).ToString());
                                            frame_instance.get_Parameter(BuiltInParameter.END_EXTENSION).SetValueString((-frame_H).ToString());
                                        }
                                        catch
                                        {
                                            frame_instance.get_Parameter(BuiltInParameter.START_EXTENSION).SetValueString((-frame_H - csv.sidewall[0].Item2 * 1000).ToString());
                                            frame_instance.get_Parameter(BuiltInParameter.END_EXTENSION).SetValueString((-frame_H - csv.sidewall[0].Item2 * 1000).ToString());
                                        }
                                        //取消接合
                                        StructuralFramingUtils.DisallowJoinAtEnd(frame_instance, 0);
                                        StructuralFramingUtils.DisallowJoinAtEnd(frame_instance, 1);

                                        //若為雙向支撐,則鏡射支撐
                                        if (csv.supLevel[lev].Item3 == 2)
                                        {
                                            ElementTransformUtils.MirrorElement(doc, frame_instance.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisY, frame_startpoint));
                                        }
                                        break;
                                    }
                                    catch { }
                                }
                            }
                        }

                        //Y向支撐
                        for (int i = 0; i < (Math.Abs(Xs.Max() - Xs.Min()) / columns_dis - 1); i++)
                        {
                            for (int j = 0; j < (Math.Abs(Ys.Max() - Ys.Min()) / columns_dis - 1); j++)
                            {
                                XYZ frame_location = new XYZ(Xs.Min() + (i + 1) * columns_dis, Ys.Min() + (1 + j) * columns_dis, 0);
                                frame_startpoint = intersection(frame_location, for_check_innerwall_points, slope, bias, false)[0];
                                if (IsInPolygon(frame_location, innerwall_points) == true)
                                {
                                    try
                                    {
                                        frame_endpoint = intersection(frame_location, for_check_innerwall_points, slope, bias, false)[1];
                                        Line           line           = Line.CreateBound(frame_startpoint, frame_endpoint);
                                        FamilyInstance frame_instance = doc.Create.NewFamilyInstance(line, frame_type, levdeep, Autodesk.Revit.DB.Structure.StructuralType.Beam);
                                        frame_instance.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set((csv.supLevel[lev].Item1).ToString() + "-支撐");

                                        //處理偏移與延伸問題

                                        frame_instance.get_Parameter(BuiltInParameter.Z_OFFSET_VALUE).SetValueString((csv.supLevel[lev].Item2 * -1000 + frame_H).ToString());//2000為支撐階數深度,表1中
                                        frame_instance.get_Parameter(BuiltInParameter.Y_OFFSET_VALUE).SetValueString((-frame_H).ToString());
                                        try
                                        {
                                            int.Parse(csv.supLevel[lev].Item1.ToString());
                                            frame_instance.get_Parameter(BuiltInParameter.START_EXTENSION).SetValueString((-frame_H).ToString());
                                            frame_instance.get_Parameter(BuiltInParameter.END_EXTENSION).SetValueString((-frame_H).ToString());
                                        }
                                        catch
                                        {
                                            frame_instance.get_Parameter(BuiltInParameter.START_EXTENSION).SetValueString((-frame_H - csv.sidewall[0].Item2 * 1000).ToString());
                                            frame_instance.get_Parameter(BuiltInParameter.END_EXTENSION).SetValueString((-frame_H - csv.sidewall[0].Item2 * 1000).ToString());
                                        }
                                        //取消接合
                                        StructuralFramingUtils.DisallowJoinAtEnd(frame_instance, 0);
                                        StructuralFramingUtils.DisallowJoinAtEnd(frame_instance, 1);

                                        //若為雙向支撐,則鏡射支撐
                                        if (csv.supLevel[lev].Item3 == 2)
                                        {
                                            ElementTransformUtils.MirrorElement(doc, frame_instance.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisX, frame_startpoint));
                                        }
                                        break;
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                }

                //建立斜撐
                ICollection <FamilySymbol> slopframe_symbol = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>().ToList();
                foreach (FamilySymbol slopframe_type in slopframe_symbol)
                {
                    if (slopframe_type.Name == "斜撐")
                    {
                        //X向斜撐
                        for (int j = 0; j < (Math.Abs(Ys.Max() - Ys.Min()) / columns_dis - 1); j++)
                        {
                            for (int i = 0; i < (Math.Abs(Xs.Max() - Xs.Min()) / columns_dis - 1); i++)
                            {
                                XYZ frame_location = new XYZ(Xs.Min() + (i + 1) * columns_dis, Ys.Min() + (j + 1) * columns_dis, 0);
                                frame_startpoint = intersection(frame_location, for_check_innerwall_points, slope, bias, true)[0];
                                if (IsInPolygon(frame_location, innerwall_points) == true)
                                {
                                    frame_endpoint = intersection(frame_location, for_check_innerwall_points, slope, bias, true)[1];
                                    FamilyInstance slopframe_1 = doc.Create.NewFamilyInstance(frame_startpoint, slopframe_type, all_level_list[lev], Autodesk.Revit.DB.Structure.StructuralType.Beam);
                                    FamilyInstance slopframe_2 = doc.Create.NewFamilyInstance(frame_endpoint, slopframe_type, all_level_list[lev], Autodesk.Revit.DB.Structure.StructuralType.Beam);
                                    slopframe_1.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set((csv.supLevel[lev].Item1).ToString() + "-斜撐");
                                    slopframe_2.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set((csv.supLevel[lev].Item1).ToString() + "-斜撐");
                                    slopframe_1.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(Math.Abs(all_level_list[lev].Elevation - csv.supLevel[lev].Item2 * -1000 / 304.8 + slopframe_1.LookupParameter("支撐厚度").AsDouble() / 2));

                                    slopframe_2.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(Math.Abs(all_level_list[lev].Elevation - csv.supLevel[lev].Item2 * -1000 / 304.8 + slopframe_1.LookupParameter("支撐厚度").AsDouble() / 2));
                                    int o;
                                    if (int.TryParse(csv.supLevel[lev].Item1, out o) == false)//305為圍囹寬度,應該要查表而非指定。
                                    {
                                        slopframe_1.LookupParameter("圍囹寬度").SetValueString((305 + csv.sidewall[0].Item2 * 1000).ToString());
                                        slopframe_2.LookupParameter("圍囹寬度").SetValueString((305 + csv.sidewall[0].Item2 * 1000).ToString());
                                    }
                                    else
                                    {
                                        slopframe_1.LookupParameter("圍囹寬度").SetValueString((305).ToString());
                                        slopframe_2.LookupParameter("圍囹寬度").SetValueString((305).ToString());
                                    }
                                    //旋轉斜撐元件
                                    Line rotate_line_s = Line.CreateBound(frame_startpoint, frame_startpoint + new XYZ(0, 0, 1));
                                    Line rotate_line_e = Line.CreateBound(frame_endpoint, frame_endpoint + new XYZ(0, 0, 1));
                                    slopframe_1.Location.Rotate(rotate_line_s, 1.5 * Math.PI);
                                    slopframe_2.Location.Rotate(rotate_line_e, 0.5 * Math.PI);

                                    //鏡射斜撐元件
                                    if (csv.supLevel[lev].Item3 == 2)//雙排
                                    {
                                        ElementTransformUtils.MirrorElement(doc, slopframe_1.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisY, frame_startpoint));
                                        ElementTransformUtils.MirrorElement(doc, slopframe_2.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisY, frame_endpoint));
                                    }
                                    else//單排
                                    {
                                        ElementTransformUtils.MirrorElement(doc, slopframe_1.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisY, frame_startpoint.Add(new XYZ(0, -(slopframe_1.LookupParameter("支撐厚度").AsDouble() / 2 + slopframe_1.LookupParameter("中間樁直徑").AsDouble() / 2), 0))));
                                        ElementTransformUtils.MirrorElement(doc, slopframe_2.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisY, frame_endpoint));
                                        slopframe_2.Location.Move((new XYZ(0, -(slopframe_1.LookupParameter("支撐厚度").AsDouble() + slopframe_1.LookupParameter("中間樁直徑").AsDouble()), 0)));
                                    }

                                    break;
                                }
                            }
                        }

                        //Y向斜撐
                        for (int i = 0; i < (Math.Abs(Xs.Max() - Xs.Min()) / columns_dis - 1); i++)
                        {
                            for (int j = 0; j < (Math.Abs(Ys.Max() - Ys.Min()) / columns_dis - 1); j++)
                            {
                                XYZ frame_location = new XYZ(Xs.Min() + (i + 1) * columns_dis, Ys.Min() + (1 + j) * columns_dis, 0);
                                frame_startpoint = intersection(frame_location, for_check_innerwall_points, slope, bias, false)[0];
                                if (IsInPolygon(frame_location, innerwall_points) == true)
                                {
                                    frame_endpoint = intersection(frame_location, for_check_innerwall_points, slope, bias, false)[1];
                                    FamilyInstance slopframe_1 = doc.Create.NewFamilyInstance(frame_startpoint, slopframe_type, all_level_list[lev], Autodesk.Revit.DB.Structure.StructuralType.Beam);
                                    FamilyInstance slopframe_2 = doc.Create.NewFamilyInstance(frame_endpoint, slopframe_type, all_level_list[lev], Autodesk.Revit.DB.Structure.StructuralType.Beam);
                                    slopframe_1.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set((csv.supLevel[lev].Item1).ToString() + "-斜撐");
                                    slopframe_2.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set((csv.supLevel[lev].Item1).ToString() + "-斜撐");
                                    slopframe_1.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(Math.Abs(all_level_list[lev].Elevation - csv.supLevel[lev].Item2 * -1000 / 304.8 - slopframe_1.LookupParameter("支撐厚度").AsDouble() / 2));

                                    slopframe_2.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(Math.Abs(all_level_list[lev].Elevation - csv.supLevel[lev].Item2 * -1000 / 304.8 - slopframe_2.LookupParameter("支撐厚度").AsDouble() / 2));
                                    int o;
                                    if (int.TryParse(csv.supLevel[lev].Item1, out o) == false)//305為圍囹寬度,應該要查表而非指定。
                                    {
                                        slopframe_1.LookupParameter("圍囹寬度").SetValueString((305 + csv.sidewall[0].Item2 * 1000).ToString());
                                        slopframe_2.LookupParameter("圍囹寬度").SetValueString((305 + csv.sidewall[0].Item2 * 1000).ToString());
                                    }
                                    else
                                    {
                                        slopframe_1.LookupParameter("圍囹寬度").SetValueString((305).ToString());
                                        slopframe_2.LookupParameter("圍囹寬度").SetValueString((305).ToString());
                                    }
                                    //旋轉斜撐元件
                                    Line rotate_line = Line.CreateBound(frame_endpoint, frame_endpoint + new XYZ(0, 0, 1));
                                    slopframe_2.Location.Rotate(rotate_line, Math.PI);

                                    //鏡射斜撐元件
                                    if (csv.supLevel[lev].Item3 == 2)//雙排
                                    {
                                        ElementTransformUtils.MirrorElement(doc, slopframe_1.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisX, frame_startpoint));
                                        ElementTransformUtils.MirrorElement(doc, slopframe_2.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisX, frame_endpoint));
                                    }
                                    else//單排
                                    {
                                        ElementTransformUtils.MirrorElement(doc, slopframe_1.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisX, frame_startpoint.Add(new XYZ(slopframe_1.LookupParameter("支撐厚度").AsDouble() / 2 + slopframe_1.LookupParameter("中間樁直徑").AsDouble() / 2, 0, 0))));
                                        ElementTransformUtils.MirrorElement(doc, slopframe_2.Id, Plane.CreateByNormalAndOrigin(XYZ.BasisX, frame_endpoint));
                                        slopframe_2.Location.Move((new XYZ((slopframe_1.LookupParameter("支撐厚度").AsDouble() + slopframe_1.LookupParameter("中間樁直徑").AsDouble()), 0, 0)));
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            trans_2.Commit();
            return(Result.Succeeded);
        }
Ejemplo n.º 5
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var uiApp = commandData.Application;
            var doc   = commandData.Application.ActiveUIDocument.Document;

            var sel = commandData.Application.ActiveUIDocument.Selection;

            if (sel.GetElementIds().Count == 0)
            {
                message = "Не выбраны элементы";
                return(Result.Failed);
            }

            var form = new FormEnterName();

            form.LabelText = "Укажите имя сборки:";
            form.ShowDialog();
            if (form.DialogResult != System.Windows.Forms.DialogResult.OK)
            {
                return(Result.Cancelled);
            }

            var name            = form.NameText;
            var groupedElements = form.GroupedElements;
            var untouchBeams    = form.UntouchBeams;

            var selids = sel.GetElementIds().ToList();
            var allIds = new List <ElementId>();

            Group            group = null;
            AssemblyInstance ai    = null;

            allIds = AssemblyUtil.GetAllNestedIds(doc, selids);

            var finalSelIds = new List <ElementId>();

            using (var t = new Transaction(doc))
            {
                if (untouchBeams)
                {
                    var beams = new List <FamilyInstance>();
                    foreach (var ei in selids)
                    {
                        var elem = doc.GetElement(ei);
                        var fin  = elem as FamilyInstance;
                        if (fin == null)
                        {
                            continue;
                        }
                        if (fin.Category.Id.IntegerValue != (int)BuiltInCategory.OST_StructuralFraming)
                        {
                            continue;
                        }
                        if (fin.StructuralType != StructuralType.Beam &&
                            fin.StructuralType != StructuralType.Brace)
                        {
                            continue;
                        }

                        beams.Add(fin);
                    }

                    if (beams.Count > 0)
                    {
                        t.Start("Открепление балок");

                        foreach (var fin in beams)
                        {
                            try
                            {
                                StructuralFramingUtils.DisallowJoinAtEnd(fin, 1);
                                StructuralFramingUtils.DisallowJoinAtEnd(fin, 0);

                                var oldElev = fin.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION)
                                              .AsDouble();
                                fin.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).Set(1);
                                fin.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).Set(oldElev);
                            }
                            catch
                            {
                            }
                        }

                        t.Commit();
                    }
                }


                allIds = AssemblyUtil.GetAllNestedIds(doc, selids);
                var mainElem = doc.GetElement(selids.First());

                //проверяю, могут ли элементы использоваться в сборке
                var idsForAssembly            = new List <ElementId>();
                var idsNotForAssembly         = new List <ElementId>();
                var messageAssemblyNotAllowed = "";

                foreach (var id in allIds)
                {
                    var elem = doc.GetElement(id);
                    if (elem.CanAssembling())
                    {
                        idsForAssembly.Add(id);
                    }
                    else
                    {
                        idsNotForAssembly.Add(id);
                        messageAssemblyNotAllowed += id.IntegerValue.ToString() + "; ";
                    }
                }

                if (idsNotForAssembly.Count > 0)
                {
                    TaskDialog.Show("Внимание",
                                    "Некоторые элементы не были включены в сборку. ID: " + messageAssemblyNotAllowed);
                }

                try
                {
                    t.Start("Создание сборки");
                    ai = AssemblyInstance.Create(doc, idsForAssembly, mainElem.Category.Id);
                    t.Commit();
                }
                catch (Exception ex)
                {
                    message += "Не удалось создать сборку: " + ex.Message;
                    return(Result.Failed);
                }

                try
                {
                    t.Start("Именование сборки");
                    ai.AssemblyTypeName = name;
                    t.Commit();
                }
                catch
                {
                    message += "\nНе удалось задать имя сборки. Установлено имя: " + ai.AssemblyTypeName;
                }

                if (groupedElements)
                {
                    t.Start("Создание группы");
                    group = doc.Create.NewGroup(allIds);
                    t.Commit();
                    finalSelIds.Add(group.Id);

                    try
                    {
                        t.Start("Именование группы");
                        var gtype = group.GroupType;
                        gtype.Name = name;
                        t.Commit();
                    }
                    catch
                    {
                        message += "\nНе удалось задать имя группы. Установлено имя: " + group.GroupType.Name;
                    }
                }
                else
                {
                    finalSelIds.Add(ai.Id);
                }
            }


            sel.SetElementIds(finalSelIds);

            return(Result.Succeeded);
        }
Ejemplo n.º 6
0
        /***************************************************/

        public static FamilyInstance ToRevitFamilyInstance(this IFramingElement framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (framingElement == null || document == null)
            {
                return(null);
            }

            FamilyInstance familyInstance = refObjects.GetValue <FamilyInstance>(document, framingElement.BHoM_Guid);

            if (familyInstance != null)
            {
                return(familyInstance);
            }

            settings = settings.DefaultIfNull();

            if (framingElement.Location == null)
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Revit element could not be created because the driving curve of a BHoM object is null. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            if (!framingElement.Location.IIsPlanar())
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Revit framing does only support planar curves, element could not be created. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            Curve revitCurve = framingElement.Location.IToRevit();

            if (revitCurve == null)
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Revit element could not be created because of curve conversion issues. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            Level level = document.LevelBelow(framingElement.Location, settings);

            FamilySymbol familySymbol = framingElement.Property.ToRevitElementType(document, framingElement.BuiltInCategories(document), settings, refObjects);

            if (familySymbol == null)
            {
                familySymbol = framingElement.ElementType(document, settings) as FamilySymbol;
            }

            if (familySymbol == null)
            {
                Compute.ElementTypeNotFoundWarning(framingElement);
                return(null);
            }

            FamilyPlacementType familyPlacementType = familySymbol.Family.FamilyPlacementType;

            if (familyPlacementType != FamilyPlacementType.CurveBased && familyPlacementType != FamilyPlacementType.CurveBasedDetail && familyPlacementType != FamilyPlacementType.CurveDrivenStructural && familyPlacementType != FamilyPlacementType.TwoLevelsBased)
            {
                Compute.InvalidFamilyPlacementTypeError(framingElement, familySymbol);
                return(null);
            }

            if (framingElement is Beam)
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Beam);
            }
            else if (framingElement is Bracing || framingElement is Cable)
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Brace);
            }
            else
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming);
            }

            document.Regenerate();

            familyInstance.CheckIfNullPush(framingElement);
            if (familyInstance == null)
            {
                return(null);
            }

            oM.Physical.FramingProperties.ConstantFramingProperty barProperty = framingElement.Property as oM.Physical.FramingProperties.ConstantFramingProperty;
            if (barProperty != null)
            {
                //TODO: if the material does not get assigned an error should be thrown?
                if (barProperty.Material != null)
                {
                    Material material = document.GetElement(new ElementId(BH.Engine.Adapters.Revit.Query.ElementId(barProperty.Material))) as Material;
                    if (material != null)
                    {
                        Parameter param = familyInstance.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
                        if (param != null && param.HasValue && !param.IsReadOnly)
                        {
                            familyInstance.StructuralMaterialId = material.Id;
                        }
                        else
                        {
                            BH.Engine.Reflection.Compute.RecordWarning(string.Format("The BHoM material has been correctly converted, but the property could not be assigned to the Revit element. ElementId: {0}", familyInstance.Id));
                        }
                    }
                }
            }

            //Set the insertion point to centroid.
            Parameter zJustification = familyInstance.get_Parameter(BuiltInParameter.Z_JUSTIFICATION);

            if (zJustification != null && !zJustification.IsReadOnly)
            {
                zJustification.Set((int)Autodesk.Revit.DB.Structure.ZJustification.Origin);
            }

            familyInstance.CopyParameters(framingElement, settings);
            familyInstance.SetLocation(framingElement, settings);

            if (familyInstance.StructuralMaterialType != StructuralMaterialType.Concrete && familyInstance.StructuralMaterialType != StructuralMaterialType.PrecastConcrete)
            {
                StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 0);
                StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 1);
            }

            refObjects.AddOrReplace(framingElement, familyInstance);
            return(familyInstance);
        }
Ejemplo n.º 7
0
        public List <ApplicationPlaceholderObject> BeamToNative(Beam speckleBeam, StructuralType structuralType = StructuralType.Beam)
        {
            if (speckleBeam.baseLine == null)
            {
                throw new Speckle.Core.Logging.SpeckleException("Only line based Beams are currently supported.");
            }

            DB.FamilySymbol familySymbol = GetElementType <FamilySymbol>(speckleBeam);
            var             baseLine     = CurveToNative(speckleBeam.baseLine).get_Item(0);

            DB.Level          level     = null;
            DB.FamilyInstance revitBeam = null;

            //comes from revit or schema builder, has these props
            var speckleRevitBeam = speckleBeam as RevitBeam;

            if (speckleRevitBeam != null)
            {
                if (level != null)
                {
                    level = GetLevelByName(speckleRevitBeam.level.name);
                }
            }

            if (level == null)
            {
                level = LevelToNative(LevelFromCurve(baseLine));
            }
            var isUpdate = false;
            //try update existing
            var docObj = GetExistingElementByApplicationId(speckleBeam.applicationId);

            if (docObj != null)
            {
                try
                {
                    var revitType = Doc.GetElement(docObj.GetTypeId()) as ElementType;

                    // if family changed, tough luck. delete and let us create a new one.
                    if (familySymbol.FamilyName != revitType.FamilyName)
                    {
                        Doc.Delete(docObj.Id);
                    }
                    else
                    {
                        revitBeam = (DB.FamilyInstance)docObj;
                        (revitBeam.Location as LocationCurve).Curve = baseLine;

                        // check for a type change
                        if (!string.IsNullOrEmpty(familySymbol.FamilyName) && familySymbol.FamilyName != revitType.Name)
                        {
                            revitBeam.ChangeTypeId(familySymbol.Id);
                        }
                    }
                    isUpdate = true;
                }
                catch
                {
                    //something went wrong, re-create it
                }
            }

            //create family instance
            if (revitBeam == null)
            {
                revitBeam = Doc.Create.NewFamilyInstance(baseLine, familySymbol, level, structuralType);
                StructuralFramingUtils.DisallowJoinAtEnd(revitBeam, 0);
                StructuralFramingUtils.DisallowJoinAtEnd(revitBeam, 1);
            }

            //reference level, only for beams
            TrySetParam(revitBeam, BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM, level);

            if (speckleRevitBeam != null)
            {
                SetInstanceParameters(revitBeam, speckleRevitBeam);
            }

            // TODO: get sub families, it's a family!
            var placeholders = new List <ApplicationPlaceholderObject>()
            {
                new ApplicationPlaceholderObject {
                    applicationId = speckleBeam.applicationId, ApplicationGeneratedId = revitBeam.UniqueId, NativeObject = revitBeam
                }
            };

            // TODO: nested elements.

            Report.Log($"{(isUpdate ? "Updated" : "Created")} AdaptiveComponent {revitBeam.Id}");

            return(placeholders);
        }
Ejemplo n.º 8
0
        //----------------------------------------------------------
        public string Draw_By_Revit(UIApplication uiapp, Document doc)
        {
            string result = "F";

            try
            {
                level_data  item_level_bottom = (level_data)level_bottom.SelectedItem;
                level_data  item_level_top    = (level_data)level_top.SelectedItem;
                family_data item_family       = (family_data)family.SelectedItem;
                type_data   item_type         = (type_data)type.SelectedItem;

                Draw_Data(item_type, item_family, doc);

                Level level_element_bottom = item_level_bottom.level;
                Level level_element_top    = item_level_top.level;

                double elevation_bottom_value = Convert.ToDouble(elevation_bottom.Text) / myAll_Data.list_unit_value_data[2] - item_level_bottom.elevation;
                double elevation_top_value    = Convert.ToDouble(elevation_top.Text) / myAll_Data.list_unit_value_data[2] - item_level_top.elevation;

                if (new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(x => x.Name == item_type.type.Name).ToList().Count() > 0)
                {
                    FamilyInstance instance     = null;
                    FamilySymbol   familySymbol = item_type.type as FamilySymbol;
                    if (familySymbol.IsActive == false)
                    {
                        familySymbol.Activate();
                    }

                    if (item_type.type.Category.Name == myAll_Data.list_category_draw[4])
                    {
                        instance = doc.Create.NewFamilyInstance(my_draw_data.center, familySymbol, level_element_bottom, StructuralType.Column) as FamilyInstance;

                        instance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).Set(level_element_bottom.Id);
                        instance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(elevation_bottom_value);
                        instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).Set(level_element_top.Id);
                        instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set(elevation_top_value);
                    }
                    else if (item_type.type.Category.Name == myAll_Data.list_category_draw[5])
                    {
                        instance = doc.Create.NewFamilyInstance(my_draw_data.curve, familySymbol, level_element_top, StructuralType.Beam) as FamilyInstance;

                        instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).Set(0.1);
                        instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).Set(0.1);

                        instance.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).Set(level_element_top.Id);
                        instance.get_Parameter(BuiltInParameter.Z_OFFSET_VALUE).Set(elevation_top_value);
                        instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).Set(0);
                        instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).Set(0);

                        StructuralFramingUtils.DisallowJoinAtEnd(instance, 0);
                        StructuralFramingUtils.DisallowJoinAtEnd(instance, 1);
                    }
                    else
                    {
                        instance = doc.Create.NewFamilyInstance(my_draw_data.center, familySymbol, host_of_opening, level_element_bottom, StructuralType.NonStructural);
                        if (instance.Host != null)
                        {
                            if (host_of_opening.Category.Name == myAll_Data.list_category_draw_host[0])
                            {
                                instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_top.Id);
                            }
                            else if (host_of_opening.Category.Name == myAll_Data.list_category_draw_host[1])
                            {
                                instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value);
                                if (instance.LookupParameter(myAll_Data.list_parameter_tag[4]) != null)
                                {
                                    instance.LookupParameter(myAll_Data.list_parameter_tag[4]).Set(Convert.ToDouble(elevation_bottom.Text) / myAll_Data.list_unit_value_data[2]);
                                }
                                if (instance.LookupParameter(myAll_Data.list_parameter_tag[0]) != null)
                                {
                                    instance.LookupParameter(myAll_Data.list_parameter_tag[0]).Set(0);
                                }
                            }
                            else
                            {
                                if (instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM) != null &&
                                    instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId().IntegerValue != -1 &&
                                    instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).IsReadOnly == false)
                                {
                                    instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_bottom.Id);
                                    instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value);
                                }
                                else if (instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM) != null &&
                                         instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId().IntegerValue != -1 &&
                                         instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).IsReadOnly == false)
                                {
                                    instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).Set(level_element_bottom.Id);
                                    instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value);
                                }
                            }
                        }
                        else
                        {
                            if (instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM) != null &&
                                instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).AsElementId().IntegerValue != -1 &&
                                instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).IsReadOnly == false)
                            {
                                instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level_element_bottom.Id);
                                instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value);
                            }
                            else if (instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM) != null &&
                                     instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).AsElementId().IntegerValue != -1 &&
                                     instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).IsReadOnly == false)
                            {
                                instance.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM).Set(level_element_bottom.Id);
                                instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM).Set(elevation_bottom_value);
                            }
                        }
                    }

                    if (my_draw_data.point1 != null)
                    {
                        Move_Element(my_draw_data.point1, my_draw_data.point2, doc, instance, item_type, item_family);
                    }

                    foreach (parameter_data data in my_parameter_data)
                    {
                        if (instance.LookupParameter(data.parameter_name).IsReadOnly == false)
                        {
                            if (data.parameter_value == "True")
                            {
                                instance.LookupParameter(data.parameter_name).Set(1);
                            }
                            else if (data.parameter_value == "False")
                            {
                                instance.LookupParameter(data.parameter_name).Set(0);
                            }
                            else
                            {
                                instance.LookupParameter(data.parameter_name).Set(Convert.ToDouble(data.parameter_value) / myAll_Data.list_unit_value_data[2]);
                            }
                        }
                    }

                    if (host_of_opening == null)
                    {
                        Join_Element(doc, instance);
                    }
                }
                else
                {
                    WallType wallType = item_type.type as WallType;
                    Wall     instance = Wall.Create(doc, my_draw_data.curve, wallType.Id, level_element_bottom.Id, 10, 0, true, true);

                    instance.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).Set(level_element_bottom.Id);
                    instance.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).Set(elevation_bottom_value);
                    instance.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(level_element_top.Id);
                    instance.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).Set(elevation_top_value);

                    WallUtils.DisallowWallJoinAtEnd(instance, 0);
                    WallUtils.DisallowWallJoinAtEnd(instance, 1);
                    instance.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM).Set(0);

                    if (my_draw_data.point1 != null)
                    {
                        Move_Element(my_draw_data.point1, my_draw_data.point2, doc, instance, item_type, item_family);
                    }
                    Join_Element(doc, instance);
                }

                result = "S";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(result);
        }