Exemple #1
0
        void ReconstructWallByCurve
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Curve curve,
            Optional <Autodesk.Revit.DB.WallType> type,
            Optional <Autodesk.Revit.DB.Level> level,
            [Optional] bool structural,
            [Optional] double height,
            [Optional] WallLocationLine locationLine,
            [Optional] bool flipped,
            [Optional, NickName("J")] bool allowJoins
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            if
            (
                scaleFactor != 1.0 ? !curve.Scale(scaleFactor) : true &&
                curve.IsShort(Revit.ShortCurveTolerance) ||
                !(curve.IsLinear(Revit.VertexTolerance) || curve.IsArc(Revit.VertexTolerance)) ||
                !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
            )
            {
                ThrowArgumentException(nameof(curve), "Curve must be a horizontal line or arc curve");
            }

            SolveOptionalType(ref type, doc, ElementTypeGroup.WallType, nameof(type));

            double axisMinZ     = Math.Min(curve.PointAtStart.Z, curve.PointAtEnd.Z);
            bool   levelIsEmpty = SolveOptionalLevel(ref level, doc, curve, nameof(level));

            height *= scaleFactor;
            if (height < Revit.VertexTolerance)
            {
                height = (type.HasValue ? type.Value : null)?.GetCompoundStructure()?.SampleHeight ?? LiteralLengthValue(6.0) / Revit.ModelUnits;
            }

            // Axis
            var levelPlane = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0.0, 0.0, level.Value.Elevation), Rhino.Geometry.Vector3d.ZAxis);

            curve = Rhino.Geometry.Curve.ProjectToPlane(curve, levelPlane);

            var curves = curve.ToHost().ToArray();

            Debug.Assert(curves.Length == 1);
            var centerLine = curves[0];

            // LocationLine
            if (locationLine != WallLocationLine.WallCenterline)
            {
                double offsetDist        = 0.0;
                var    compoundStructure = type.Value.GetCompoundStructure();
                if (compoundStructure == null)
                {
                    switch (locationLine)
                    {
                    case WallLocationLine.WallCenterline:
                    case WallLocationLine.CoreCenterline:
                        break;

                    case WallLocationLine.FinishFaceExterior:
                    case WallLocationLine.CoreExterior:
                        offsetDist = type.Value.Width / +2.0;
                        break;

                    case WallLocationLine.FinishFaceInterior:
                    case WallLocationLine.CoreInterior:
                        offsetDist = type.Value.Width / -2.0;
                        break;
                    }
                }
                else
                {
                    if (!compoundStructure.IsVerticallyHomogeneous())
                    {
                        compoundStructure = CompoundStructure.CreateSimpleCompoundStructure(compoundStructure.GetLayers());
                    }

                    offsetDist = compoundStructure.GetOffsetForLocationLine(locationLine);
                }

                if (offsetDist != 0.0)
                {
                    centerLine = centerLine.CreateOffset(flipped ? -offsetDist : offsetDist, XYZ.BasisZ);
                }
            }

            // Type
            ChangeElementTypeId(ref element, type.Value.Id);

            Wall newWall = null;

            if (element is Wall previousWall && previousWall.Location is LocationCurve locationCurve && centerLine.IsSameKindAs(locationCurve.Curve))
            {
                newWall = previousWall;

                locationCurve.Curve = centerLine;
            }
Exemple #2
0
        public void createWall()
        {
            try
            {
                //Wall.Create(Document document, Curve curve, ElementId wallTypeId, ElementId levelId, double wallHeight, double wallOffset, bool flip, bool structural)
                WallType yeniWallType = null;
                bool     bulundu      = false;
                FilteredElementCollector wallTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType));
                ElementId defaultElementTypeId     = doc.GetDefaultElementTypeId(ElementTypeGroup.WallType);
                #region Informatik isimli duvar tipini ara, yoksa yarat
                foreach (WallType wt in wallTypes)
                {
                    if (wt.Name == "Informatik")
                    {
                        informatikWallId = wt.Id;
                        bulundu          = true;
                        break;
                    }
                }
                if (bulundu == false)
                {
                    foreach (WallType wt in wallTypes)
                    {
                        if (wt.Id == defaultElementTypeId)
                        {
                            using (Transaction transaction = new Transaction(doc, "DuplicateWallType"))
                            {
                                transaction.Start();
                                yeniWallType = wt.Duplicate("Informatik") as WallType;
                                CompoundStructure cs                   = yeniWallType.GetCompoundStructure();
                                ElementId         materialId           = new ElementId(539);
                                IList <CompoundStructureLayer> cslList = new List <CompoundStructureLayer>();
                                CompoundStructureLayer         csl     = new CompoundStructureLayer(20 * mmToFeet, MaterialFunctionAssignment.Finish1, materialId);
                                cslList.Add(csl);
                                csl = new CompoundStructureLayer(160 * mmToFeet, MaterialFunctionAssignment.Structure, materialId);
                                cslList.Add(csl);
                                csl = new CompoundStructureLayer(20 * mmToFeet, MaterialFunctionAssignment.Finish2, materialId);
                                cslList.Add(csl);
                                CompoundStructure yeniStructure = CompoundStructure.CreateSimpleCompoundStructure(cslList);
                                yeniWallType.SetCompoundStructure(yeniStructure);
                                doc.SetDefaultElementTypeId(ElementTypeGroup.WallType, yeniWallType.Id);
                                transaction.Commit();
                                informatikWallId = yeniWallType.Id;
                            }
                            break;
                        }
                    }
                }
                #endregion
                #region levelId bul
                List <Level>             levels = new List <Level>();
                FilteredElementCollector filteredLevelCollector = new FilteredElementCollector(doc);
                filteredLevelCollector.OfClass(typeof(Level));
                levels = filteredLevelCollector.Cast <Level>().ToList();
                ElementId levelId = null;
                foreach (Level l in levels)
                {
                    if (l.Name == "Level 0")
                    {
                        levelId = l.Id;
                        break;
                    }
                }
                #endregion
                #region cizgileri seçtirt
                uiApp.ActiveUIDocument.Selection.GetElementIds().Clear();
                ISelectionFilter selFilter = new ModelLineSelectionFilter();
                this.Hide();
                IList <Reference> curves = uiApp.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, selFilter, "Select path Curve(s) for partition wall");
                this.Show();
                #endregion
                #region set computing options
                Options opt = new Options();
                opt.ComputeReferences        = true;
                opt.IncludeNonVisibleObjects = true;
                opt.View = doc.ActiveView;

                #endregion
                #region duvar yüksekliği ve offsetini belirle
                double wallHeight = 3000 * mmToFeet;
                double wallOffset = 0;
                #endregion
                List <Wall> yeniDuvarlar = new List <Wall>();
                if (curves.Count > 0)
                {
                    #region döngü
                    for (int i = 0; i < curves.Count; i++)
                    {
                        XYZ  globalPoint;
                        Wall yeniDuvar = null;
                        globalPoint = curves[i].GlobalPoint;
                        Element tempCurve = doc.GetElement(curves[i]) as Element;
                        Curve   curve     = null;
                        if (tempCurve != null)
                        {
                            #region element geometrisinden Curve bulunabiliyor mu
                            foreach (var geoObj in tempCurve.get_Geometry(opt))
                            {
                                Curve cv = geoObj as Curve;
                                if (cv != null)
                                {
                                    curve = cv;
                                    break;
                                }
                            }
                            #endregion
                            #region duvar üret
                            if (curve != null)
                            {
                                using (Transaction wallCreate = new Transaction(doc, "Duvar Yarat"))
                                {
                                    wallCreate.Start();
                                    yeniDuvar = Wall.Create(doc, curve, informatikWallId, levelId, wallHeight, wallOffset, false, false);
                                    if (yeniDuvar != null)
                                    {
                                        yeniDuvarlar.Add(yeniDuvar);
                                    }
                                    wallCreate.Commit();
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion
                    //BuiltInParameter myParameter = BuiltInParameter.DIVIDED_SURFACE_DISPLAY_ORIGINAL_SURFACE;
                    //Element myElement = yeniDuvar as Element;
                    //myElement.get_Parameter(myParameter).Set();
                    #region parametreleri kontrol et
                    if (yeniDuvarlar.Count > 0)
                    {
                        Wall yeniDuvar = yeniDuvarlar[0];

                        string s = string.Empty;
                        foreach (Parameter p in yeniDuvar.Parameters)
                        {
                            s += "Name=" + p.Definition.Name + " StorageType=" + p.StorageType.ToString() + "\r\n";
                        }
                        MessageBox.Show(s);
                    }
                    #endregion
                }
                if (curves.Count < 1)
                {
                    TaskDialog.Show("Seçilmedi", "En az bir çizgi seçmelisiniz");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }