예제 #1
0
        private WallType DuplicateWallType(WallType wallType, Document doc)
        {
            WallType newWallType;

            //Select the wall type in the document
            IEnumerable <WallType> _wallTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(WallType))
                                                let type = elem as WallType
                                                           where type.Kind == WallKind.Basic
                                                           select type;

            List <string> wallTypesNames = _wallTypes.Select(o => o.Name).ToList();

            if (!wallTypesNames.Contains("newWallTypeName"))
            {
                newWallType = wallType.Duplicate("newWallTypeName") as WallType;
            }
            else
            {
                newWallType = wallType.Duplicate("newWallTypeName2") as WallType;
            }

            CompoundStructure cs = newWallType.GetCompoundStructure();

            IList <CompoundStructureLayer> layers = cs.GetLayers();
            int layerIndex = 0;

            foreach (CompoundStructureLayer csl in layers)
            {
                double layerWidth = csl.Width * 2;
                if (cs.GetRegionsAssociatedToLayer(layerIndex).Count == 1)
                {
                    try
                    {
                        cs.SetLayerWidth(layerIndex, layerWidth);
                    }
                    catch
                    {
                        throw new ErrorMessageException(Tools.LangResMan.GetString("roomFinishes_verticallyCompoundError", Tools.Cult));
                    }
                }
                else
                {
                    throw new ErrorMessageException(Tools.LangResMan.GetString("roomFinishes_verticallyCompoundError", Tools.Cult));
                }

                layerIndex++;
            }

            newWallType.SetCompoundStructure(cs);

            return(newWallType);
        }
예제 #2
0
        public void ChangeElementMaterial(Element element, Material material)
        {
            Wall             w  = (Wall)element;
            WallType         wt = w.WallType;
            WallType         nwt;
            IList <WallType> desiredType = new FilteredElementCollector(doc)
                                           .OfClass(typeof(WallType))
                                           .Cast <WallType>()
                                           .Where <WallType>(wallType => wallType.Name.Equals("MyWall")).ToList <WallType>();

            if (desiredType.Count == 0)
            {
                nwt = wt.Duplicate("MyWall") as WallType;
                CompoundStructure cs = nwt.GetCompoundStructure();
                IList <CompoundStructureLayer> layers = nwt.GetCompoundStructure().GetLayers();
                int layerIndex = 0;
                foreach (CompoundStructureLayer l in layers)
                {
                    cs.SetMaterialId(layerIndex, material.Id);
                    layerIndex++;
                }
                nwt.SetCompoundStructure(cs);
            }
            else
            {
                nwt = desiredType.First();
            }
            w.WallType = nwt;
        }
예제 #3
0
        public WallType CreateNewWallType(Document doc, Wall wall)
        {
            WallType wallType    = wall.WallType;
            WallType NewWallType = null;

            Transaction t = new Transaction(doc, "Duplicate wall");

            t.Start();
            try
            {
                NewWallType = wallType.Duplicate("SW48") as WallType;
                CompoundStructure compoundStructure = NewWallType.GetCompoundStructure();
                int layerIndex = compoundStructure.GetFirstCoreLayerIndex();
                IList <CompoundStructureLayer> csLayers = compoundStructure.GetLayers();
                foreach (CompoundStructureLayer csl in csLayers)
                {
                    if (csl.Function.ToString() == "Structure")
                    {
                        compoundStructure.SetLayerWidth(layerIndex, 48 / 12);
                    }
                    layerIndex++;
                }
                NewWallType.SetCompoundStructure(compoundStructure);
            }
            catch {}
            t.Commit();
            return(NewWallType);
        }
예제 #4
0
        public WallType CreateWallType(Document document, WallType _wallType, double wallTypeThickness)
        {
            WallType wallType = null;

            try
            {
                wallType = _wallType.Duplicate($"Wall {Convert.ToInt32((wallTypeThickness )).ToString() }mm") as WallType;

                CompoundStructure compoundStructure = wallType.GetCompoundStructure();

                int layerIndex = compoundStructure.GetFirstCoreLayerIndex();


                IList <CompoundStructureLayer> clayers = compoundStructure.GetLayers();

                foreach (CompoundStructureLayer csl in clayers)
                {
                    if (csl.Function.ToString() == "Structure")
                    {
                        compoundStructure.SetLayerWidth(layerIndex, wallTypeThickness * _mm_to_feet);
                    }

                    layerIndex++;
                }

                wallType.SetCompoundStructure(compoundStructure);
            }
            catch { }


            return(wallType);
        }
        private WallType CreateNewWallType(WallType wallType)
        {
            WallType      newWallType;
            List <string> wallTypesNames = _wallTypes.Select(o => o.Name).ToList();

            if (!wallTypesNames.Contains("newWallTypeName"))
            {
                newWallType = wallType.Duplicate("newWallTypeName") as WallType;
            }
            else
            {
                newWallType = wallType.Duplicate("newWallTypeName2") as WallType;
            }



            CompoundStructure cs = newWallType.GetCompoundStructure();

            IList <CompoundStructureLayer> layers = cs.GetLayers();
            int layerIndex = 0;

            foreach (CompoundStructureLayer csl in layers)
            {
                double layerWidth = csl.Width * 2;
                if (cs.GetRegionsAssociatedToLayer(layerIndex).Count == 1)
                {
                    try
                    {
                        cs.SetLayerWidth(layerIndex, layerWidth);
                    }
                    catch
                    {
                        throw new ErrorMessageException(Tools.LangResMan.GetString("roomFinishes_verticallyCompoundError", Tools.Cult));
                    }
                }
                else
                {
                    throw new ErrorMessageException(Tools.LangResMan.GetString("roomFinishes_verticallyCompoundError", Tools.Cult));
                }

                layerIndex++;
            }

            newWallType.SetCompoundStructure(cs);

            return(newWallType);
        }
예제 #6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;

            View   acview   = uidoc.ActiveView;
            UIView acuiview = uidoc.ActiveUiview();


            Transaction ts = new Transaction(doc, "******");

            try
            {
                ts.Start();

                //点选指定执行的元素, 本次按只能选择墙考虑
                Reference pickedEleReference = sel.PickObject(ObjectType.Element);
                //通过引用取到选中的元素
                Wall wall = doc.GetElement(pickedEleReference) as Wall;


                string info = "信息如下";

                info += "\n\t" + "1 ELEM_TYPE_PARAM (族名称):" +
                        wall.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString();

                info += "\n\t" + "2 长度:" + wall.LookupParameter("长度").AsValueString();

                TaskDialog.Show("提示", info);

                //当新添加的族类型族中已经有的时候, 该程序不能正常运行.
                WallType    wallType           = wall.WallType;
                ElementType duplicatedWallType = wallType.Duplicate(wallType.Name + "duplicated7");

                ts.Commit();
            }

            catch (Exception)
            {
                if (ts.GetStatus() == TransactionStatus.Started)
                {
                    ts.RollBack();
                }
            }

            return(Result.Succeeded);
        }
예제 #7
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            //ElementSet a = uidoc.Selection.Elements; // 2014
            ICollection <ElementId> ids = uidoc.Selection.GetElementIds(); // 2015

            const string newWallTypeName = "NewWallType_with_Width_doubled";

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Duplicate Wall Type");

                foreach (ElementId id in ids)
                {
                    Wall wall = doc.GetElement(id) as Wall;

                    if (null != wall)
                    {
                        WallType wallType = wall.WallType;

                        WallType newWallType = wallType.Duplicate(
                            newWallTypeName) as WallType;

                        //CompoundStructureLayerArray layers = newWallType.CompoundStructure.Layers; // 2011
                        IList <CompoundStructureLayer> layers = newWallType.GetCompoundStructure().GetLayers(); // 2012

                        foreach (CompoundStructureLayer layer in layers)
                        {
                            // double each layer thickness:

                            //layer.Thickness *= 2.0; // 2011

                            layer.Width *= 2.0; // 2012
                        }
                        // assign the new wall type back to the wall:

                        wall.WallType = newWallType;

                        // only process the first wall, if one was selected:

                        break;
                    }
                }
                t.Commit();
            }
            return(Result.Succeeded);

            #region Assign colour
#if ASSIGN_COLOUR
            ElementSet elemset = doc.Selection.Elements;

            foreach (Element e in elemset)
            {
                FamilyInstance inst = e as FamilyInstance;

                // get the symbol and duplicate it:
                FamilySymbol dupSym = inst.Symbol.Duplicate(
                    "D1") as FamilySymbol;

                // access the material:
                ElementId matId = dupSym.get_Parameter(
                    "Material").AsElementId();

                Material mat = doc.GetElement(ref matId)
                               as Autodesk.Revit.Elements.Material;

                // change the color of this material:
                mat.Color = new Color(255, 0, 0);

                // assign the new symbol to the instance:
                inst.Symbol = dupSym;
#endif // ASSIGN_COLOUR
            #endregion // Assign colour
        }
    }
예제 #8
0
파일: MyRevit.cs 프로젝트: pgrandin/revit
        public Result setup_wall_struct(Document doc)
        {
            WallType wallType = null;

            // FIXME : replace with the material approach?
            FilteredElementCollector wallTypes
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(WallType));

            foreach (WallType wt in wallTypes)
            {
                if (wt.Name.Equals("Generic - 8\""))
                {
                    wallType = wt;
                    break;
                }
            }

            Material concrete = new FilteredElementCollector(doc)
                                .OfClass(typeof(Material))
                                .Cast <Material>().FirstOrDefault(q
                                                                  => q.Name == "Concrete, Cast-in-Place gray");

            Material insulation = new FilteredElementCollector(doc)
                                  .OfClass(typeof(Material))
                                  .Cast <Material>().FirstOrDefault(q
                                                                    => q.Name == "EIFS, Exterior Insulation");

            Material lumber = new FilteredElementCollector(doc)
                              .OfClass(typeof(Material))
                              .Cast <Material>().FirstOrDefault(q
                                                                => q.Name == "Softwood, Lumber");

            Material gypsum = new FilteredElementCollector(doc)
                              .OfClass(typeof(Material))
                              .Cast <Material>().FirstOrDefault(q
                                                                => q.Name == "Gypsum Wall Board");

            WallType newWallType = null;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Basement exterior wall");

                newWallType = wallType.Duplicate("Basement") as WallType;
                // FIXME : this layer should have the "structural material" parameter set
                CompoundStructureLayer l1        = new CompoundStructureLayer(8.0 / 12, MaterialFunctionAssignment.Structure, concrete.Id);
                CompoundStructureLayer newLayer  = new CompoundStructureLayer(3.0 / 12, MaterialFunctionAssignment.Insulation, insulation.Id);
                CompoundStructureLayer newLayer2 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Finish1, lumber.Id);
                CompoundStructureLayer newLayer3 = new CompoundStructureLayer(.5 / 12, MaterialFunctionAssignment.Finish2, gypsum.Id);

                CompoundStructure structure = newWallType.GetCompoundStructure();

                IList <CompoundStructureLayer> layers = structure.GetLayers();

                layers.Add(l1);
                layers.Add(newLayer);
                layers.Add(newLayer2);
                layers.Add(newLayer3);
                structure.SetLayers(layers);

                structure.DeleteLayer(0);

                structure.SetNumberOfShellLayers(ShellLayerType.Interior, 3);

                newWallType.SetCompoundStructure(structure);

                tx.Commit();
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("2x4 + Gypsum wall");

                newWallType = wallType.Duplicate("2x4 + Gypsum") as WallType;
                CompoundStructureLayer l1 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Structure, lumber.Id);
                CompoundStructureLayer l2 = new CompoundStructureLayer(0.5 / 12, MaterialFunctionAssignment.Finish1, gypsum.Id);

                CompoundStructure structure = newWallType.GetCompoundStructure();

                IList <CompoundStructureLayer> layers = structure.GetLayers();

                layers.Add(l2);
                layers.Add(l1);
                layers.Add(l2);
                structure.SetLayers(layers);

                structure.DeleteLayer(0);
                structure.SetNumberOfShellLayers(ShellLayerType.Exterior, 1);
                structure.SetNumberOfShellLayers(ShellLayerType.Interior, 1);

                newWallType.SetCompoundStructure(structure);

                tx.Commit();
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("2x4 + Gypsum wall with Exterior");

                newWallType = wallType.Duplicate("2x4 + Gypsum wall with Exterior") as WallType;
                CompoundStructureLayer l1 = new CompoundStructureLayer(3.5 / 12, MaterialFunctionAssignment.Structure, lumber.Id);
                CompoundStructureLayer l2 = new CompoundStructureLayer(0.5 / 12, MaterialFunctionAssignment.Finish1, gypsum.Id);

                CompoundStructure structure = newWallType.GetCompoundStructure();

                IList <CompoundStructureLayer> layers = structure.GetLayers();

                layers.Add(l2);
                layers.Add(l1);
                layers.Add(l2);
                structure.SetLayers(layers);

                structure.DeleteLayer(0);
                structure.SetNumberOfShellLayers(ShellLayerType.Exterior, 1);
                structure.SetNumberOfShellLayers(ShellLayerType.Interior, 1);


                ElementType wallSweepType = new FilteredElementCollector(doc)
                                            .OfCategory(BuiltInCategory.OST_Cornices)
                                            .WhereElementIsElementType()
                                            .Cast <ElementType>().FirstOrDefault();

                if (wallSweepType != null)
                {
                    var wallSweepInfo = new WallSweepInfo(WallSweepType.Sweep, false);
                    wallSweepInfo.Distance = 2;

                    List <WallSweepInfo> ModSW = new List <WallSweepInfo>();
                    // structure.AddWallSweep(wallSweepInfo);
                }


                newWallType.SetCompoundStructure(structure);

                tx.Commit();
            }

            return(Result.Succeeded);
        }
예제 #9
0
파일: Command.cs 프로젝트: inktan/RevitApi_
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc   = commandData.Application.ActiveUIDocument;
            Document   doc     = commandData.Application.ActiveUIDocument.Document;
            View       view    = uidoc.ActiveView;
            ElementId  levelid = view.GenLevel.Id;

            bool iscontinue = true;

            do
            {
                List <Element> eles = new List <Element>();
                try
                {
                    eles = GetSelected(uidoc);
                }
                catch
                {
                    iscontinue = false;
                    continue;
                }
                if (eles == null)
                {
                    TaskDialog.Show("wrong", "选择的符号线的数量不为2.");  continue;
                }


                //get line_closer & line_farther
                Line line1 = (eles[0] as DetailLine).GeometryCurve as Line;
                Line line2 = (eles[1] as DetailLine).GeometryCurve as Line;
                if (line1 == null || line2 == null)
                {
                    TaskDialog.Show("wrong", "仅支持直线."); continue;
                }
                Line line1unbound = (eles[0] as DetailLine).GeometryCurve as Line;
                line1unbound.MakeUnbound();
                Line line2unbound = (eles[1] as DetailLine).GeometryCurve as Line;
                line2unbound.MakeUnbound();
                //get distance from origin
                IntersectionResult result1   = line1unbound.Project(new XYZ(-1000 / 304.8, -1000 / 304.8, line1.GetEndPoint(0).Z));
                double             distance1 = result1.Distance;
                IntersectionResult result2   = line2unbound.Project(new XYZ(-1000 / 304.8, -1000 / 304.8, line2.GetEndPoint(0).Z));
                double             distance2 = result2.Distance;
                if (IsAlmostEqual(distance1, distance2))
                {
                    TaskDialog.Show("wrong", "两条线间距太小."); continue;
                }
                Line line_closer          = null;
                Line line_farther         = null;
                Line line_closer_unbound  = null;
                Line line_farther_unbound = null;
                if (distance1 > distance2)
                {
                    line_closer          = line2;
                    line_farther         = line1;
                    line_closer_unbound  = line2unbound;
                    line_farther_unbound = line1unbound;
                }
                else
                {
                    line_closer          = line1;
                    line_farther         = line2;
                    line_closer_unbound  = line1unbound;
                    line_farther_unbound = line2unbound;
                }

                //Determine parallel
                XYZ  dir1       = line_closer.Direction;
                XYZ  dir2       = line_farther.Direction;
                bool isparallel = dir1.IsAlmostEqualTo(dir2) || dir1.IsAlmostEqualTo(-dir2);
                if (!isparallel)
                {
                    TaskDialog.Show("wrong", "请选择平行的线."); continue;
                }

                //get points
                //makeunbound
                XYZ startpoint_closerline  = line_closer.GetEndPoint(0);
                XYZ endpoint_closerline    = line_closer.GetEndPoint(1);
                XYZ startpoint_fartherline = line_farther.GetEndPoint(0);
                XYZ endpoint_fartherline   = line_farther.GetEndPoint(1);

                //get width of wall
                IntersectionResult intersection = line_closer_unbound.Project(startpoint_fartherline);
                double             distance     = intersection.Distance;
                XYZ  point_intersection         = intersection.XYZPoint;
                Line normalline    = Line.CreateBound(point_intersection, startpoint_fartherline);
                XYZ  normallinedir = normalline.Direction;

                //offset
                Line wallline = null;
                if (line_closer.Length > line_farther.Length)
                {
                    wallline = OffsetLine(line_closer, normallinedir, distance / 2);
                }
                else
                {
                    wallline = OffsetLine(line_farther, -normallinedir, distance / 2);
                }

                //get material
                FilteredElementCollector materialcollector = new FilteredElementCollector(doc);
                materialcollector.OfCategory(BuiltInCategory.OST_Materials).OfClass(typeof(Material));
                IEnumerable <Material> materials = from ele in materialcollector
                                                   let material = ele as Material
                                                                  where material.Name == "BRIK"
                                                                  select material;
                if (materials.Count() == 0)
                {
                    TaskDialog.Show("wrong", "未找到BRIK材质"); continue;
                }
                ElementId materialid = materials.First().Id;

                //get walltype
                FilteredElementCollector walltypecollector = new FilteredElementCollector(doc);
                walltypecollector.OfClass(typeof(WallType)).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType();
                IEnumerable <WallType> walltypes = from element in walltypecollector
                                                   let walltypetemp                       = element as WallType
                                                                                 let para = walltypetemp.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM)
                                                                                            where walltypetemp.Name.Contains("A-WALL-INTR")
                                                                                            where walltypetemp.Kind == WallKind.Basic
                                                                                            //  where para.AsDouble() == distance
                                                                                            where IsAlmostEqual(para.AsDouble(), distance)
                                                                                            select walltypetemp;
                if (walltypecollector.Count() == 0)
                {
                    TaskDialog.Show("wrong", "请先随意新建一个类型."); continue;
                }
                WallType typetemp = null;
                foreach (WallType type in walltypecollector)
                {
                    if (type.Kind == WallKind.Basic)
                    {
                        typetemp = type; break;
                    }
                }
                if (typetemp == null)
                {
                    TaskDialog.Show("wrong", "请先随意新建一个内墙类型."); continue;
                }
                WallType walltype = null;
                if (walltypes.Count() == 0)
                {
                    TaskDialog.Show("wrong", "未找到合适的类型,将新建一个类型");
                    using (Transaction createwalltype = new Transaction(doc))
                    {
                        createwalltype.Start("新建墙类型");

                        walltype = typetemp.Duplicate("A-WALL-INTR-" + Convert.ToInt32((distance * 304.8)).ToString()) as WallType;
                        CompoundStructure compoundstructure = CompoundStructure.CreateSingleLayerCompoundStructure(MaterialFunctionAssignment.Structure, distance, materialid);
                        walltype.SetCompoundStructure(compoundstructure);

                        createwalltype.Commit();
                    }
                }
                else
                {
                    walltype = walltypes.First();
                }


                //transaction

                using (Transaction transaction = new Transaction(doc))
                {
                    transaction.Start("生成墙");

                    Wall wall = Wall.Create(doc, wallline, walltype.Id, levelid, 10, 0, false, false);

                    transaction.Commit();
                }
            }while (iscontinue);



            return(Result.Succeeded);
        }