コード例 #1
0
ファイル: MainForm.cs プロジェクト: yasenRK/AreaPlanHelper
        private bool retrieveAndRender()
        {
            try
            {
                List <Autodesk.Revit.DB.Document> docs = new List <Autodesk.Revit.DB.Document>();
                foreach (var doc in _docsToProcess)
                {
                    docs.Add(doc.Doc);
                }

                _controller = new Controller(docs, _currentDoc, cbParameter.SelectedItem.ToString(), _config);

                Autodesk.Revit.DB.Parameter p = _currentDoc.ActiveView.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.VIEW_PHASE);
                if (p == null)
                {
                    throw new ApplicationException("No view phase info?");
                }
                string phaseName = _currentDoc.GetElement(p.AsElementId()).Name;

                _rooms = _controller.RetrieveRooms(_currentDoc.ActiveView.GenLevel.Name, phaseName);

                // if this is only the current model, we can do more.

                if (docs[0].Title == _currentDoc.Title)
                {
                    int openCount = Controller.CountOpenSpots(_currentDoc, _currentDoc.ActiveView.GenLevel.Name, phaseName);
                    linkOpenSpots.Text    = "NOTE: There are " + openCount + " open areas in your room model that do not have Room elements. PLEASE REVIEW!";
                    linkOpenSpots.Visible = (openCount > 0);
                }
                else
                {
                    linkOpenSpots.Text    = "NOTE: please ensure that all possible rooms are created, including vertical penetration.";
                    linkOpenSpots.Visible = true;
                }


                IList <RoomObjectSummary> summaries = RoomObjectSummary.Summarize(_rooms, _config);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = summaries.ToArray();

                return(true);
            }
            catch (ApplicationException aex)
            {
                MessageBox.Show(aex.Message);
            }
            catch (Exception ex)
            {
                var td = new Autodesk.Revit.UI.TaskDialog("Unexpected issue");
                td.MainContent     = ex.GetType().Name + ": " + ex.Message;
                td.ExpandedContent = "Developer Info: " + Environment.NewLine + ex.StackTrace;
                td.Show();
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Create a new instance of WallType, deleting the original
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="wallType"></param>
        /// <param name="baseLevel"></param>
        /// <param name="height"></param>
        /// <param name="offset"></param>
        /// <param name="flip"></param>
        /// <param name="isStructural"></param>
        private Wall(Curve curve, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Level baseLevel, double height, double offset, bool flip, bool isStructural)
        {
            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(Document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var wallElem =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Wall>(Document);

            bool successfullyUsedExistingWall = false;

            //There was a modelcurve, try and set sketch plane
            // if you can't, rebuild
            if (wallElem != null && wallElem.Location is Autodesk.Revit.DB.LocationCurve)
            {
                var wallLocation = wallElem.Location as Autodesk.Revit.DB.LocationCurve;
                if ((wallLocation.Curve is Autodesk.Revit.DB.Line == curve is Autodesk.Revit.DB.Line) ||
                    (wallLocation.Curve is Autodesk.Revit.DB.Arc == curve is Autodesk.Revit.DB.Arc))
                {
                    wallLocation.Curve = curve;

                    Autodesk.Revit.DB.Parameter baseLevelParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_BASE_CONSTRAINT);
                    Autodesk.Revit.DB.Parameter topOffsetParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                    Autodesk.Revit.DB.Parameter wallTypeParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ELEM_TYPE_PARAM);
                    if (baseLevelParameter.AsElementId() != baseLevel.Id)
                    {
                        baseLevelParameter.Set(baseLevel.Id);
                    }
                    if (Math.Abs(topOffsetParameter.AsDouble() - height) > 1.0e-10)
                    {
                        topOffsetParameter.Set(height);
                    }
                    if (wallTypeParameter.AsElementId() != wallType.Id)
                    {
                        wallTypeParameter.Set(wallType.Id);
                    }
                    successfullyUsedExistingWall = true;
                }
            }

            var wall = successfullyUsedExistingWall ? wallElem :
                       Autodesk.Revit.DB.Wall.Create(Document, curve, wallType.Id, baseLevel.Id, height, offset, flip, isStructural);

            InternalSetWall(wall);

            TransactionManager.Instance.TransactionTaskDone();

            // delete the element stored in trace and add this new one
            ElementBinder.CleanupAndSetElementForTrace(Document, InternalWall);
        }