Esempio n. 1
0
        public void CreateWalls
            (Document doc, HouseObject house,
            List <WallType> autoTypes, Level baseLevel)
        {
            foreach (A_Floor floor in house.Floors)
            {
                ///Create the walls.
                foreach (A_Wall wa in floor.Walls)
                {
                    WallType currentWt = null;
                    XYZ      p1        = new XYZ(wa.P1.X, wa.P1.Y, 0);
                    XYZ      p2        = new XYZ(wa.P2.X, wa.P2.Y, 0);
                    Curve    c         = Line.CreateBound(p1, p2);

                    ///Find the right wall type.
                    ///If the type doesnt exist,create a new one.
                    try
                    {
                        currentWt = autoTypes
                                    .First(at => at.Width - wa.Thickness < 0.0001);
                    }
                    catch
                    {
                        ///Duplicate a new walltype;
                        float wallWidthMm = Helper.Feet2Mm(wa.Thickness);
                        currentWt = AutoWallTypes[0].Duplicate
                                        ("AutoWall-" + wallWidthMm) as WallType;
                        ///Set the width of the new type;
                        CompoundStructure cStru = CompoundStructure
                                                  .CreateSingleLayerCompoundStructure
                                                      (MaterialFunctionAssignment.Structure,
                                                      wa.Thickness, currentWt.GetCompoundStructure().GetMaterialId(0));
                        currentWt.SetCompoundStructure(cStru);
                        ///Add it to collection.
                        AutoWallTypes.Add(currentWt);
                    }

                    ///Create the individual wall
                    wa.Wall = Wall.Create(doc, c, currentWt.Id, baseLevel.Id,
                                          floor.Height, 0, false, true);

                    ActiveForm.UpdateProgress(wallWorkLoad);
                }

                ///Create the floor.
                CurveArray floorCrv = new CurveArray();
                foreach (A_Room outer in floor.Outers)
                {
                    foreach (A_Contour con in outer.Meta.Contours)
                    {
                        floorCrv.Append(Line.CreateBound
                                            (new XYZ(con.P1.X, con.P1.Y, baseLevel.Elevation),
                                            new XYZ(con.P2.X, con.P2.Y, baseLevel.Elevation)));
                    }
                    doc.Create.NewFloor(floorCrv, false);
                }
            }
        }
Esempio n. 2
0
        public bool DoCreateSockets()
        {
            this.LoadSocketsFamilies(ActiveDoc);

            Document        doc        = this.ActiveDoc;
            List <A_Socket> allSockets =
                CurrentHouse.Floors
                .SelectMany(f => f.Socket)
                .ToList();
            List <A_Wall> allWalls =
                CurrentHouse.Floors
                .SelectMany(f => f.Walls)
                .ToList();

            if (allSockets.Count() == 0)
            {
                return(false);
            }

            foreach (A_Socket soc in allSockets)
            {
                XYZ centerPt = new XYZ
                                   (soc.X, soc.Y, soc.Z + BaseLevel.Elevation);
                XYZ dirPt = new XYZ
                                (0 - soc.Orientation.Y, soc.Orientation.X, 0);

                ///Get all the face of the host wall.
                Wall hostWall = allWalls
                                .First(w => w.Uid == soc.Related.Uid).Wall;

                List <Reference> sideFaces =
                    HostObjectUtils.GetSideFaces
                        (hostWall, ShellLayerType.Exterior)
                    .ToList();
                sideFaces.AddRange(
                    HostObjectUtils.GetSideFaces
                        (hostWall, ShellLayerType.Interior)
                    .ToList());

                ///Find the face where the socket is located.
                Reference hostFace = sideFaces
                                     .OrderBy(f => centerPt.DistanceTo
                                                  ((doc.GetElement(f)
                                                    .GetGeometryObjectFromReference(f)
                                                    as Face)
                                                  .Project(centerPt).XYZPoint))
                                     .First();
                if (hostFace == null)
                {
                    continue;
                }

                ///Choose the type.
                Family socFam;
                switch (soc.Tag)
                {
                case "五孔":
                    socFam = AutoSocketFamilies
                             .First(s =>
                                    (s.Name.Contains("五孔")) &&
                                    (!s.Name.Contains("防水")));
                    break;

                case "五孔防水":
                    socFam = AutoSocketFamilies
                             .First(s => s.Name.Contains("五孔防水"));
                    break;

                case "网络电视":
                    socFam = AutoSocketFamilies
                             .First(s => s.Name.Contains("网络电视"));
                    break;

                default:
                    socFam = AutoSocketFamilies
                             .First(s => s.Name.Contains(soc.Tag));
                    break;
                }
                FamilySymbol socSymbol =
                    doc.GetElement
                        (socFam.GetFamilySymbolIds().First())
                    as FamilySymbol;

                socSymbol.Activate();
                soc.Instance = doc.Create
                               .NewFamilyInstance
                                   (hostFace, centerPt, dirPt, socSymbol);

                ActiveForm.UpdateProgress(socketWorkLoad);
            }
            return(true);
        }
Esempio n. 3
0
        public void CreateOpenings
            (Document doc, HouseObject house,
            Level baseLevel, List <Family> doorFamilies,
            List <Family> windowFamilies)
        {
            foreach (A_Floor f in house.Floors)
            {
                foreach (A_Door d in f.Doors)
                {
                    ///Find the right doorfamily.
                    Family doorFam;
                    switch (d.Kind)
                    {
                    case A_DoorKind.PASS:
                        doorFam = doorFamilies
                                  .First(fa => fa.Name.Contains("PASS"));
                        break;

                    case A_DoorKind.SLIDING:
                        doorFam = doorFamilies
                                  .First(fa => fa.Name.Contains("SLIDING"));
                        break;

                    default:
                        doorFam = doorFamilies
                                  .First(fa => fa.Name.Contains("SINGLE"));
                        break;
                    }

                    ///Create the door.
                    d.Instance = CreateSingleOpening
                                     (doc, f, d, baseLevel, doorFam,
                                     BuiltInCategory.OST_Doors);

                    bool fliped = false;
                    ///Check the direction.
                    doc.Regenerate();
                    if (!d.Instance.FacingOrientation
                        .IsAlmostEqualTo(d.FacingOrientation))
                    {
                        d.Instance.flipFacing();
                        fliped = true;
                    }
                    if (!d.Instance.HandOrientation
                        .IsAlmostEqualTo(d.HandOrientation))
                    {
                        d.Instance.flipHand();
                        fliped = true;
                    }
                    if (!fliped)
                    {
                        d.Instance.flipFacing();
                        d.Instance.flipFacing();
                    }

                    ///Update the progress.
                    ActiveForm.UpdateProgress(doorWorkLoad);
                }

                foreach (A_Window w in f.Windows)
                {
                    ///Find the right window family.
                    string test      = w.Kind.ToString();
                    Family windowFam = windowFamilies
                                       .First(wf => wf.Name.Contains(w.Kind.ToString()));

                    ///Create the window.
                    w.Instance = CreateSingleOpening
                                     (doc, f, w, BaseLevel, windowFam,
                                     BuiltInCategory.OST_Windows);
                    doc.Regenerate();
                    w.Instance.flipFacing();
                    doc.Regenerate();
                    w.Instance.flipFacing();

                    ActiveForm.UpdateProgress(windowWorkLoad);
                }
            }
        }