Пример #1
0
        public static Dictionary <string, Element> ByHostAndCurve(Element host, Curve curve)
        {
            AD.Document   currentDBDocument = DocumentManager.Instance.CurrentDBDocument;
            AD.Element    internalElement   = host.InternalElement;
            AD.CurveArray curveArray        = new AD.CurveArray();
            try
            {
                curveArray.Append(ProtoToRevitCurve.ToRevitType(curve, true));
            }
            catch (Exception)
            {
                PolyCurve polyCurve = (PolyCurve)curve;
                Curve[]   array     = polyCurve.Curves();
                for (int i = 0; i < array.Length; i++)
                {
                    Curve crv = array[i];
                    curveArray.Append(ProtoToRevitCurve.ToRevitType(crv, true));
                }
            }
            TransactionManager.Instance.EnsureInTransaction(currentDBDocument);
            AD.Opening opening = currentDBDocument.Create.NewOpening(internalElement, curveArray, true);
            Element    value   = ElementWrapper.ToDSType(opening, false);

            TransactionManager.Instance.TransactionTaskDone();
            return(new Dictionary <string, Element>
            {
                {
                    "Opening",
                    value
                }
            });
        }
 public bool CanConvertToSpeckle(object @object)
 {
     return(@object
            switch
     {
         DB.DetailCurve _ => true,
         DB.DirectShape _ => true,
         DB.FamilyInstance _ => true,
         DB.Floor _ => true,
         DB.Level _ => true,
         DB.View _ => true,
         DB.ModelCurve _ => true,
         DB.Opening _ => true,
         DB.RoofBase _ => true,
         DB.Area _ => true,
         DB.Architecture.Room _ => true,
         DB.Architecture.TopographySurface _ => true,
         DB.Wall _ => true,
         DB.Mechanical.Duct _ => true,
         DB.Mechanical.Space _ => true,
         DB.Plumbing.Pipe _ => true,
         DB.Electrical.Wire _ => true,
         DB.CurtainGridLine _ => true, //these should be handled by curtain walls
         DB.Architecture.BuildingPad _ => true,
         DB.Architecture.Stairs _ => true,
         DB.Architecture.StairsRun _ => true,
         DB.Architecture.StairsLanding _ => true,
         DB.Architecture.Railing _ => true,
         DB.Architecture.TopRail _ => true,
         DB.Ceiling _ => true,
         DB.PointCloudInstance _ => true,
         DB.Group _ => true,
         DB.ProjectInfo _ => true,
         DB.ElementType _ => true,
         DB.Grid _ => true,
         DB.ReferencePoint _ => true,
         DB.Structure.AnalyticalModelStick _ => true,
         DB.Structure.AnalyticalModelSurface _ => true,
         DB.Structure.BoundaryConditions _ => true,
         _ => (@object as Element).IsElementSupported()
     });
Пример #3
0
        public BuiltElements.Opening OpeningToSpeckle(DB.Opening revitOpening)
        {
            if (!ShouldConvertHostedElement(revitOpening, revitOpening.Host))
            {
                return(null);
            }

            RevitOpening speckleOpening;

            if (revitOpening.IsRectBoundary)
            {
                speckleOpening = new RevitWallOpening();

                var poly = new Polyline();
                poly.value = new List <double>();

                //2 points: bottom left and top right
                var btmLeft  = PointToSpeckle(revitOpening.BoundaryRect[0]);
                var topRight = PointToSpeckle(revitOpening.BoundaryRect[1]);
                poly.value.AddRange(btmLeft.value);
                poly.value.AddRange(new Point(btmLeft.value[0], btmLeft.value[1], topRight.value[2], ModelUnits).value);
                poly.value.AddRange(topRight.value);
                poly.value.AddRange(new Point(topRight.value[0], topRight.value[1], btmLeft.value[2], ModelUnits).value);
                poly.value.AddRange(btmLeft.value);
                poly.units             = ModelUnits;
                speckleOpening.outline = poly;
            }
            else
            {
                if (revitOpening.Host != null)
                {
                    //we can ignore vertical openings because they will be created when we try re-create voids in the roof / ceiling / floor outline
                    return(null);
                    //speckleOpening = new RevitVerticalOpening();
                }
                else
                {
                    speckleOpening = new RevitShaft();
                    if (revitOpening.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE) != null)
                    {
                        ((RevitShaft)speckleOpening).topLevel    = ConvertAndCacheLevel(revitOpening, BuiltInParameter.WALL_HEIGHT_TYPE);
                        ((RevitShaft)speckleOpening).bottomLevel = ConvertAndCacheLevel(revitOpening, BuiltInParameter.WALL_BASE_CONSTRAINT);
                        ((RevitShaft)speckleOpening).height      = GetParamValue <double>(revitOpening, BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                    }
                }

                var poly = new Polycurve(ModelUnits);
                poly.segments = new List <ICurve>();
                foreach (DB.Curve curve in revitOpening.BoundaryCurves)
                {
                    if (curve != null)
                    {
                        poly.segments.Add(CurveToSpeckle(curve));
                    }
                }
                speckleOpening.outline = poly;
            }

            //speckleOpening.type = revitOpening.Name;

            GetAllRevitParamsAndIds(speckleOpening, revitOpening, new List <string> {
                "WALL_BASE_CONSTRAINT", "WALL_HEIGHT_TYPE", "WALL_USER_HEIGHT_PARAM"
            });

            return(speckleOpening);
        }
Пример #4
0
        public ApplicationPlaceholderObject OpeningToNative(BuiltElements.Opening speckleOpening)
        {
            var baseCurves = CurveToNative(speckleOpening.outline);

            var docObj = GetExistingElementByApplicationId(speckleOpening.applicationId);

            if (docObj != null)
            {
                Doc.Delete(docObj.Id);
            }

            DB.Opening revitOpening = null;

            switch (speckleOpening)
            {
            case RevitWallOpening rwo:
            {
                if (CurrentHostElement as Wall == null)
                {
                    throw new Exception($"Hosted wall openings require a host wall");
                }
                var points = (rwo.outline as Polyline).points.Select(x => PointToNative(x)).ToList();
                revitOpening = Doc.Create.NewOpening(CurrentHostElement as Wall, points[0], points[2]);
                break;
            }

            case RevitVerticalOpening rvo:
            {
                if (CurrentHostElement == null)
                {
                    throw new Exception($"Hosted vertical openings require a host family");
                }
                revitOpening = Doc.Create.NewOpening(CurrentHostElement, baseCurves, true);
                break;
            }

            case RevitShaft rs:
            {
                var bottomLevel = LevelToNative(rs.bottomLevel);
                var topLevel    = LevelToNative(rs.topLevel);
                revitOpening = Doc.Create.NewOpening(bottomLevel, topLevel, baseCurves);
                TrySetParam(revitOpening, BuiltInParameter.WALL_USER_HEIGHT_PARAM, rs.height);

                break;
            }

            default:
                ConversionErrors.Add(new Error("Cannot create Opening", "Opening type not supported"));
                throw new Exception("Opening type not supported");
            }


            if (speckleOpening is RevitOpening ro)
            {
                SetInstanceParameters(revitOpening, ro);
            }

            return(new ApplicationPlaceholderObject {
                NativeObject = revitOpening, applicationId = speckleOpening.applicationId, ApplicationGeneratedId = revitOpening.UniqueId
            });
        }
Пример #5
0
        public static re.Element CreateWallOpening(re.Wall wall, dg.PolyCurve polyCrv)
        {
            try
            {
                // Try to get a wall from trace
                rdb.Document doc         = DocumentManager.Instance.CurrentDBDocument;
                var          openingElem = ElementBinder.GetElementFromTrace <rdb.Element>(doc);
                rdb.Opening  opening     = null;
                if (openingElem != null && openingElem.Id.IntegerValue != (int)rdb.BuiltInCategory.OST_SWallRectOpening)
                {
                    opening = openingElem as rdb.Opening;
                }

                if (!VerifyRect(polyCrv))
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "VerifyRect failed");
                    return(null);
                }

                // Find the two corner points.
                if (!GetRectCorners(polyCrv, out rdb.XYZ corner0, out rdb.XYZ corner1))
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "GetRectCorners failed");
                    return(null);
                }

                if (corner0 == null || corner1 == null)
                {
                    if (opening != null)
                    {
                        TransactionManager.Instance.EnsureInTransaction(doc);
                        doc.Delete(opening.Id);
                        TransactionManager.Instance.TransactionTaskDone();
                    }
                    TaskDialog.Show("Test", "one of the corners is null");
                    return(null);
                }

                TransactionManager.Instance.EnsureInTransaction(doc);
                // Purge the original element
                if (opening != null)
                {
                    doc.Delete(opening.Id);
                }

                // Build a new opening;
                try
                {
                    rdb.Wall    w        = wall.InternalElement as rdb.Wall;
                    rdb.Opening o        = doc.Create.NewOpening(w, corner0, corner1);
                    re.Element  rOpening = re.ElementWrapper.ToDSType(o, true) as re.Element;
                    TransactionManager.Instance.TransactionTaskDone();
                    ElementBinder.CleanupAndSetElementForTrace(doc, o);
                    return(rOpening);
                }
                catch (Exception ex)
                {
                    TransactionManager.Instance.TransactionTaskDone();
                    TaskDialog.Show("CreateError", ex.ToString());
                    ElementBinder.CleanupAndSetElementForTrace(doc, null);
                }
            }
            catch (Exception e)
            {
                Autodesk.Revit.UI.TaskDialog.Show("Test", "Error:\n" + e.ToString());
                throw;
            }
            return(null);
        }