Esempio n. 1
0
        //adds the given view to the given sheet then returns the ElementId, places the view at the given coordiantes on the sheet
        public ElementId AddViewToSheet(string sheetName, string viewName, XYZ xyz)
        {
            //get the sheet and the view
            ElementId s = GetSheetId(sheetName);
            ElementId v = GetViewId(viewName);

            //check if we have elements to work with
            if (s == null || v == null)
            {
                return(null);
            }

            //check if we have been given a specific location to place the viewport
            if (xyz == null)
            {
                xyz = new XYZ(0, 0, 0);
            }

            //create the viewport
            using (Transaction t = new Transaction(doc))
            {
                t.Start("Creating ViewPort.");
                Viewport vp = Viewport.Create(doc, s, v, xyz);
                t.Commit();

                return(vp.Id);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Provide Sheet to place view on and the X & Y
        /// coordinates of the Lower Left Corner of the View Port
        /// from the Lower Left Corner of the Titleblock
        /// </summary>
        /// <param name="sheet">Sheet to place the view on</param>
        /// <param name="viewToPlace">View to place</param>
        /// <param name="xOffsetFromTitleBlockLowerLeft">Distance in Feet from the Lower Left Corner of Title Block to Lower Left Corner of Viewport along Horizontal axis</param>
        /// <param name="yOffsetFromTitleBlockLowerLeft">Distance in Feet from the Lower Left Corner of Title Block to Lower Left Corner of Viewport along Vertical axis</param>
        public void PlaceViewOnSheetCoords(ViewSheet sheet, View viewToPlace, double xOffsetFromTitleBlockLowerLeft, double yOffsetFromTitleBlockLowerLeft)
        {
            Document doc = sheet.Document;
            XYZ      titleBlockCorner = GetLowerLeftCornerOfTitleBlock(sheet);

            // Create viewport to get outline
            Viewport viewport = null;

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Create Viewport");
                viewport = Viewport.Create(doc, sheet.Id, viewToPlace.Id, new XYZ());
                t.Commit();
            }

            // reposition to user coordinates
            XYZ vportCenterPos = GetViewportSetBoxCenter(xOffsetFromTitleBlockLowerLeft, yOffsetFromTitleBlockLowerLeft, viewport, titleBlockCorner);

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Move Viewport to sheet corner");
                viewport.SetBoxCenter(vportCenterPos);
                t.Commit();
            }
        }
Esempio n. 3
0
        public void RecreateViewport(Document doc, Viewport viewport, XYZ p2)
        {
            // 1.Get XYZ of viewport :
            BoundingBoxXYZ bb = viewport.get_BoundingBox(doc.GetElement(viewport.OwnerViewId) as View);
            XYZ            p1 = viewport.GetBoxCenter();
            // 2. Get ViewId (eg. Legend ID) :
            ElementId viewID = viewport.ViewId;
            View      view   = doc.GetElement(viewID) as View;
            // 3. Get viewsheet ID :
            ElementId vsid = viewport.SheetId;

            using (Transaction t = new Transaction(doc, " viewport"))
            {
                t.Start();

                // 4. Delete Viewport has selected
                //if (viewport.Id != null) doc.Delete(viewport.Id);
                // 5. Duplicate View :
                View      dupView   = null;
                ElementId newViewId = ElementId.InvalidElementId;
                if (view.CanViewBeDuplicated(ViewDuplicateOption.WithDetailing))
                {
                    newViewId = view.Duplicate(ViewDuplicateOption.WithDetailing);
                    dupView   = doc.GetElement(newViewId) as View;
                }
                // 6. Create Viewport associated with View in sheet :

                Viewport vp = Viewport.Create(doc, vsid, dupView.Id, p2);

                t.Commit();
            }
        }
Esempio n. 4
0
        //以下为各种method---------------------------------分割线---------------------------------

        //外部事件方法建立
        //创建图纸,添加视图
        public ViewSheet CreatViewSheetPort(Document doc, FamilySymbol familySymbol, ElementId activeViewId, string activeViewName, XYZ xYZ)//参数说明:doc, 标题栏族, 需要创建视口的视图id,所选视图id的名字
        {
            using (Transaction ViewSheetViewPort_new = new Transaction(doc))
            {
                ViewSheetViewPort_new.Start("ViewSheetViewPort_new");
                ViewSheet viewSheet = ViewSheet.Create(doc, familySymbol.Id);
                if (viewSheet == null)
                {
                    TaskDialog.Show("Revit2020", "未能成功创建新图纸.");
                    return(null);
                }
                //设置视口位置
                //UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2, (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2);

                if (Viewport.CanAddViewToSheet(doc, viewSheet.Id, activeViewId))//判断视图是否能够加入图纸
                {
                    Viewport.Create(doc, viewSheet.Id, activeViewId, xYZ);
                }
                else
                {
                    TaskDialog.Show("Revit2020", activeViewName + "已经存在与图纸中");
                }
                ViewSheetViewPort_new.Commit();
                return(viewSheet);
            }
        }
Esempio n. 5
0
        PlaceViews(ViewSet views, ViewSheet sheet)
        {
            double xDistance = 0;
            double yDistance = 0;

            CalculateDistance(sheet.Outline, views.Size, ref xDistance, ref yDistance);

            UV origin = GetOffset(sheet.Outline, xDistance, yDistance);
            UV temp   = new UV(origin.U, origin.V);

            int n = 1;

            foreach (Autodesk.Revit.DB.View v in views)
            {
                UV location = new UV(temp.U, temp.V);
                Autodesk.Revit.DB.View view = v;
                Rescale(view, xDistance, yDistance);
                Viewport.Create(view.Document, sheet.Id, view.Id, new XYZ(location.U, location.V, 0));

                if (0 != n++ % m_rows)
                {
                    temp = new UV(temp.U + xDistance * (1 - TITLEBAR), temp.V);
                }
                else
                {
                    temp = new UV(origin.U, temp.V + yDistance);
                }
            }
        }
        private void SetViewForSheet(View view, ViewSheet sheet, int scale)
        {
            if (scale > 0)
            {
                try
                {
                    view.Scale = scale;
                }
                catch (Exception ex)
                {
                }
            }

            try
            {
                if (Viewport.CanAddViewToSheet(view.Document, sheet.Id, view.Id))
                {
                    BoundingBoxUV sheetBox  = sheet.Outline;
                    double        yPosition = (sheetBox.Max.V - sheetBox.Min.V) / 2 + sheetBox.Min.V;
                    double        xPosition = (sheetBox.Max.U - sheetBox.Min.U) / 2 + sheetBox.Min.U;

                    XYZ      orig     = new XYZ(xPosition, yPosition, 0);
                    Viewport viewport = Viewport.Create(view.Document, sheet.Id, view.Id, orig);
                }
                else
                {
                }
            }
            catch (ArgumentException ex)
            {
            }
        }
Esempio n. 7
0
        private void SetViewForSheet(View view, ViewSheet sheet, int scale)
        {
            if (scale > 0)
            {
                try
                {
                    view.Scale = scale;
                }
                catch (Exception ex)
                {
                }
            }

            try
            {
                if (Viewport.CanAddViewToSheet(view.Document, sheet.Id, view.Id))
                {
                    BoundingBoxUV sheetBox    = sheet.Outline;
                    XYZ           sheetOrigin = sheet.Origin;

                    Viewport viewport = Viewport.Create(view.Document, sheet.Id, view.Id, XYZ.Zero);

                    BoundingBoxXYZ viewportBoundingBox = viewport.get_BoundingBox(sheet);
                    XYZ            viewportOrigin      = viewportBoundingBox.Min;

                    ElementTransformUtils.MoveElement(view.Document, viewport.Id, new XYZ(sheetOrigin.X - viewportOrigin.X, sheetOrigin.Y - viewportOrigin.Y, 0));
                }
                else
                {
                }
            }
            catch (ArgumentException ex)
            {
            }
        }
Esempio n. 8
0
        /*
         * public void CreateSheet2D()
         * {
         *  if(titleBlock != null && housingNum.Count() > 0)
         *  {
         *      using (Transaction t = new Transaction(m_rvtDoc, "Create a new ViewSheet"))
         *      {
         *          t.Start();
         *          try
         *          {
         *              for(int i = 0; i < housingNum.Count(); i++)
         *              {
         *                  ViewSheet viewSheet = ViewSheet.Create(m_rvtDoc, titleBlock.Id);
         *                  if(viewSheet == null)
         *                  {
         *                      throw new Exception("Failed to create new Sheet");
         *                  }
         *                  viewSheet.Name = this.sheetName;
         *                  viewSheet.SheetNumber = housingNum[i] + "-" + this.numSuffix;
         *
         *                  // place views on sheet
         *                  for (int j = 0; j < this.floorPlans.Count(); j++)
         *                  {
         *                      if(this.floorPlans[j].Name.ToString() + "-" + this.numSuffix == viewSheet.SheetNumber)
         *                      {
         *                          UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2, (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2);
         *
         *                          Viewport viewPort = Viewport.Create(m_rvtDoc, viewSheet.Id, this.floorPlans[j].Id, new XYZ(location.U, location.V, 0));
         *                          this.floorPlans.Remove(this.floorPlans[j]);
         *                      }
         *                  }
         *              }
         *              t.Commit();
         *          }
         *          catch
         *          {
         *              t.RollBack();
         *          }
         *      }
         *  }
         * } */



        public bool CreateSheet2D()
        {
            if (titleBlock != null && this.floorPlans.Count() > 0)
            {
                using (Transaction t = new Transaction(m_rvtDoc, "Create sheet using view"))
                {
                    t.Start();
                    try
                    {
                        for (int i = 0; i < floorPlans.Count(); i++)
                        {
                            ViewSheet viewSheet = ViewSheet.Create(m_rvtDoc, titleBlock.Id);
                            if (viewSheet == null)
                            {
                                throw new Exception("Failed to create new Sheet");
                            }
                            viewSheet.Name        = this.sheetName;
                            viewSheet.SheetNumber = floorPlans[i].Name.ToString() + "-" + this.numSuffix;
                            UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2, (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2);

                            Viewport viewPort = Viewport.Create(m_rvtDoc, viewSheet.Id, this.floorPlans[i].Id, new XYZ(location.U, location.V, 0));
                        }
                        t.Commit();
                        return(true);
                    }
                    catch
                    {
                        t.RollBack();
                    }
                }
            }
            return(false);
        }
Esempio n. 9
0
        public static void SheetFromOrphanViews(Document doc)
        {
            var views = viewsNotOnSheets(doc);

            ElementId titleBlockId = new FilteredElementCollector(doc)
                                     .OfCategory(BuiltInCategory.OST_TitleBlocks)
                                     .WhereElementIsElementType()
                                     .FirstElementId();

            using (Transaction t = new Transaction(doc, "Create Sheets"))
            {
                t.Start();

                foreach (ElementId eid in views)
                {
                    View view = doc.GetElement(eid) as View;
                    view.CropBoxActive  = true;
                    view.CropBoxVisible = false;

                    ViewSheet sheet = ViewSheet.Create(doc, titleBlockId);
                    Viewport.Create(doc, sheet.Id, eid, XYZ.Zero);

                    doc.Regenerate();

                    ElementId vport = sheet.GetAllViewports().First();
                    Viewport  port  = doc.GetElement(vport) as Viewport;
                    var       max   = port.GetBoxOutline().MaximumPoint;
                    var       min   = port.GetBoxOutline().MinimumPoint;
                }
                t.Commit();
            }
        }
        protected override Result ProcessCommand(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var titleBlockSymbol = new FilteredElementCollector(_activeDocument)
                                   .OfCategory(BuiltInCategory.OST_TitleBlocks)
                                   .WhereElementIsElementType()
                                   .Cast <FamilySymbol>()
                                   .First();

            var view = new FilteredElementCollector(_activeDocument)
                       .OfCategory(BuiltInCategory.OST_Views)
                       .WhereElementIsNotElementType()
                       .Cast <ViewPlan>()
                       .First(x => x.Name == "Level 1");


            using (Transaction trans = new Transaction(_activeDocument, "Create Sheet"))
            {
                trans.Start();
                var sheet       = ViewSheet.Create(_activeDocument, titleBlockSymbol.Id);
                var boundingBox = sheet.Outline;
                var uX          = (boundingBox.Max.U + boundingBox.Min.U) / 2;
                var uY          = (boundingBox.Max.V + boundingBox.Min.V) / 2;
                var centerPoint = new XYZ(uX, uY, 0);
                sheet.Name        = "VinaTakeuchi - Sheet";
                sheet.SheetNumber = "VNT-01";
                var viewPort = Viewport.Create(_activeDocument, sheet.Id, view.Id, centerPoint);
                trans.Commit();
            }
            return(Result.Succeeded);
        }
Esempio n. 11
0
        /// <summary>
        /// This method adds the collection of views to the existing ViewSheet and packs them
        /// </summary>
        /// <param name="views"></param>
        private void InternalAddViewsToSheetView(IEnumerable <Autodesk.Revit.DB.View> views)
        {
            var sheet = InternalViewSheet;

            TransactionManager.Instance.EnsureInTransaction(Document);

            // (sic) from Dynamo Legacy
            var width  = sheet.Outline.Max.U - sheet.Outline.Min.U;
            var height = sheet.Outline.Max.V - sheet.Outline.Min.V;
            var packer = new CygonRectanglePacker(width, height);
            int count  = 0;

            foreach (var view in views)
            {
                var viewWidth  = view.Outline.Max.U - view.Outline.Min.U;
                var viewHeight = view.Outline.Max.V - view.Outline.Min.V;

                Autodesk.Revit.DB.UV placement = null;
                if (packer.TryPack(viewWidth, viewHeight, out placement))
                {
                    var dbViews = sheet.GetAllPlacedViews().Select(x => Document.GetElement(x)).
                                  OfType <Autodesk.Revit.DB.View>();
                    if (dbViews.Contains(view))
                    {
                        //move the view
                        //find the corresponding viewport
                        var enumerable =
                            DocumentManager.Instance.ElementsOfType <Autodesk.Revit.DB.Viewport>()
                            .Where(x => x.SheetId == sheet.Id && x.ViewId == view.Id).ToArray();

                        if (!enumerable.Any())
                        {
                            continue;
                        }

                        var viewport = enumerable.First();
                        viewport.SetBoxCenter(new XYZ(placement.U + viewWidth / 2, placement.V + viewHeight / 2, 0));
                    }
                    else
                    {
                        //place the view on the sheet
                        if (Viewport.CanAddViewToSheet(Document, sheet.Id, view.Id))
                        {
                            var viewport = Viewport.Create(Document, sheet.Id, view.Id,
                                                           new XYZ(placement.U + viewWidth / 2, placement.V + viewHeight / 2, 0));
                        }
                    }
                }
                else
                {
                    throw new Exception(String.Format("View {0} could not be packed on the Sheet.  The sheet is {1} x {2} and the view to be added is {3} x {4}",
                                                      count, width, height, viewWidth, viewHeight));
                }

                count++;
            }

            TransactionManager.Instance.TransactionTaskDone();
        }
Esempio n. 12
0
        private static Result createReshoringLayoutSheets(UIDocument uiDoc)
        {
            Document _doc = uiDoc.Document;

            string _titleblockName           = "E1 30 x 42 Horizontal: E1 30x42 Horizontal";
            XYZ    _columnScheduleBottomLeft = new XYZ(2.3354130772204, 2.39482128194158, 0);
            XYZ    _viewCenter = new XYZ(1.45453036348288, 1.18116967618813, 0.871414246948733);
            XYZ    _levelScheduleBottomLeft = new XYZ(0.156336990263879, 2.37688649933288, 0);

            var _levels = Getters.GetLevels(_doc);

            Level _levelAbove  = null;
            Level _topLevel    = _levels.FirstOrDefault();
            Level _bottomLevel = _levels.LastOrDefault();

            List <Tuple <ViewSheet, View> > _sheetsWithViews = new List <Tuple <ViewSheet, View> >();


            foreach (Level _level in _levels)
            {
                if (_levelAbove == null)
                {
                    _levelAbove = _level;
                }

                BoundedViewCreator _boundedViewCreator = new BoundedViewCreator(_level, null, null);
                SheetCreator       _sheetCreator       = new SheetCreator(_doc);
                string             _viewName           = _boundedViewCreator.GetViewName(string.Empty, "FP");
                ViewSheet          _viewSheet          = _sheetCreator.CreateSheet(_titleblockName, _viewName, _viewName);
                ViewPlan           _viewPlan           = _boundedViewCreator.CreateViewPlan(80);
                _sheetsWithViews.Add(new Tuple <ViewSheet, View>(_viewSheet, _viewPlan));

                ViewSchedule          _columnSchedule = ScheduleCreator.CreateLayoutColumnSchedule(_doc, _level.Name, " Reshores");
                ScheduleSheetInstance _columnScheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _viewSheet.Id, _columnSchedule.Id, _columnScheduleBottomLeft);

                ViewSchedule          _levelSchedule = ScheduleCreator.CreateLayoutLoadSchedule(_doc, _level.Name, " Loads");
                ScheduleSheetInstance _levelScheduleSheetInstance = ScheduleSheetInstance.Create(_doc, _viewSheet.Id, _levelSchedule.Id, _levelScheduleBottomLeft);

                _levelAbove = _level;
            }

            _doc.Regenerate();

            FamilySymbol _tagSymbol = new FilteredElementCollector(_doc)
                                      .OfCategory(BuiltInCategory.OST_MultiCategoryTags)
                                      .OfClass(typeof(FamilySymbol)).OfType <FamilySymbol>()
                                      .FirstOrDefault(p => p.FamilyName.Contains("Mark"));


            foreach (var _sheetWithView in _sheetsWithViews)
            {
                DimensionCreator.CreateDimensions(_sheetWithView.Item2);
                TagCreator.CreateTags(_sheetWithView.Item2, _tagSymbol);
                Viewport.Create(_doc, _sheetWithView.Item1.Id, _sheetWithView.Item2.Id, _viewCenter);
            }

            return(Result.Succeeded);
        }
Esempio n. 13
0
        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                MessageBox.Show("The task has been cancelled");
                progressBar1.Value        = 0;
                this.PlaceButton.Enabled  = true;
                this.RemoveButton.Enabled = true;
                StatusLabel.Visible       = false;
            }
            else if (e.Error != null)
            {
                MessageBox.Show("The Task Has Been Cancelled", "Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                progressBar1.Value        = 0;
                this.PlaceButton.Enabled  = true;
                this.RemoveButton.Enabled = true;
                StatusLabel.Visible       = false;
            }
            else
            {
                //Placed the elements onto the sheet here

                XYZ point = userSelectedPoint;

                try
                {
                    using (Transaction t = new Transaction(localDoc, "Place Legend"))
                    {
                        t.Start();
                        foreach (Tuple <Element, Element> add in AddToSheet)
                        {
                            Viewport.Create(localDoc, add.Item1.Id, add.Item2.Id, point);
                        }

                        t.Commit();
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }


                WFItem.SelectedLegends.Clear();
                WFItem.SelectedSheets.Clear();
                AddToSheet.Clear();

                progressBar1.Value        = 0;
                this.PlaceButton.Enabled  = true;
                this.RemoveButton.Enabled = true;
                StopButton.Enabled        = false;

                StatusLabel.Visible = false;
                MessageBox.Show("The Task Has Been Completed.", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public void SheetsFromViews()
        {
            // define current document
            Document curDoc = this.Application.ActiveUIDocument.Document;

            // define sheet num and counter
            int sheetNum = 101;
            int counter  = 0;

            // get all plan views
            FilteredElementCollector planColl = new FilteredElementCollector(curDoc);

            planColl.OfClass(typeof(ViewPlan));

            // get all titleblocks
            FilteredElementCollector tblockColl = new FilteredElementCollector(curDoc);

            tblockColl.OfCategory(BuiltInCategory.OST_TitleBlocks);

            // start transaction
            Transaction t = new Transaction(curDoc, "Sheets from Plans");

            t.Start();

            // loop through plan views
            foreach (View v in planColl)
            {
                if (v.IsTemplate == false)
                {
                    if (v.ViewType == ViewType.FloorPlan)
                    {
                        ViewSheet newVS = ViewSheet.Create(curDoc, tblockColl.FirstElementId());

                        // update sheet number and sheet name
                        newVS.SheetNumber = "A" + sheetNum.ToString();
                        newVS.Name        = v.Name;

                        // create viewport and add view to sheet
                        Viewport vp = Viewport.Create(curDoc, newVS.Id, v.Id, new XYZ(0, 0, 0));

                        // increment
                        counter++;
                        sheetNum++;
                    }
                }
            }

            // commit changes
            t.Commit();
            t.Dispose();

            // alert user
            TaskDialog.Show("Complete", "Created " + counter.ToString() + " new sheets.");
        }
Esempio n. 15
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static Viewport ToRevitViewport(this oM.Adapters.Revit.Elements.Viewport viewport, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (viewport == null || viewport.Location == null)
            {
                return(null);
            }

            Viewport revitViewPort = refObjects.GetValue <Viewport>(document, viewport.BHoM_Guid);

            if (revitViewPort != null)
            {
                return(revitViewPort);
            }

            settings = settings.DefaultIfNull();

            if (string.IsNullOrEmpty(viewport.ViewName))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(viewport.SheetNumber))
            {
                return(null);
            }

            List <View> viewList = new FilteredElementCollector(document).OfClass(typeof(View)).Cast <View>().ToList();

#if (REVIT2020 || REVIT2021)
            View view = viewList.FirstOrDefault(x => !x.IsTemplate && x.Name == viewport.ViewName);
#else
            View view = viewList.FirstOrDefault(x => !x.IsTemplate && x.ViewName == viewport.ViewName);
#endif

            if (view == null)
            {
                return(null);
            }

            List <ViewSheet> viewSheetList = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).Cast <ViewSheet>().ToList();
            ViewSheet        viewSheet     = viewSheetList.FirstOrDefault(x => !x.IsTemplate && !x.IsPlaceholder && x.SheetNumber == viewport.SheetNumber);
            if (viewSheet == null)
            {
                return(null);
            }

            revitViewPort = Viewport.Create(document, viewSheet.Id, view.Id, viewport.Location.ToRevit());

            // Copy parameters from BHoM object to Revit element
            revitViewPort.CopyParameters(viewport, settings);

            refObjects.AddOrReplace(viewport, revitViewPort);
            return(revitViewPort);
        }
Esempio n. 16
0
        /// <summary>
        /// Function to create viewport
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="marker"></param>
        /// <param name="floorPlan"></param>
        /// <param name="i"></param>
        /// <param name="viewTemplate"></param>
        /// <param name="annoCategories"></param>
        /// <param name="sheet"></param>
        /// <param name="viewports"></param>
        public static void CreateViewport(Document doc, ViewSheet sheet, ref List <Viewport> viewports, View view)
        {
            // Create viewports
            Viewport viewP = Viewport.Create(doc, sheet.Id, view.Id, new XYZ());

            // Disable temporary hide
            view.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate);

            // Store viewports
            viewports.Add(viewP);
        }
Esempio n. 17
0
 public void PlaceViewToSheet(Document doc, View view, ViewSheet sheet)
 {
     if (view != null)
     {
         XYZ      point     = new XYZ(0, 0, 0);
         Viewport vp        = Viewport.Create(doc, sheet.Id, view.Id, point);
         Outline  outline1  = vp.GetBoxOutline();
         XYZ      boxCenter = vp.GetBoxCenter();
         vp.SetBoxCenter(outline1.MaximumPoint);
         doc.Regenerate();
     }
 }
Esempio n. 18
0
 ////[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
 public void PlaceViewPortOnSheet(
     Element destSheet, ElementId destViewId, XYZ viewCentre)
 {
     try {
         Viewport.Create(doc, destSheet.Id, destViewId, viewCentre);
     } catch (Autodesk.Revit.Exceptions.ArgumentException ex) {
         SCaddinsApp.WindowManager.ShowMessageBox(ex.Message);
     } catch (Autodesk.Revit.Exceptions.ForbiddenForDynamicUpdateException fex) {
         SCaddinsApp.WindowManager.ShowMessageBox(fex.Message);
     } catch (Autodesk.Revit.Exceptions.ModificationForbiddenException mex) {
         SCaddinsApp.WindowManager.ShowMessageBox(mex.Message);
     }
 }
Esempio n. 19
0
 public IImage GetThumbnail()
 {
     if (thumbnail == null)
     {
         thumbnail = renderService.CreateRenderTargetImage(ThumbnailSize);
         renderService.Render(thumbnail, new [] { Viewport.Create(IntVector2.Zero, ThumbnailSize, ThumbnailView.Create(this)) }, 0);
     }
     else if (thumbnailDirty)
     {
         renderService.Render(thumbnail, new[] { Viewport.Create(IntVector2.Zero, ThumbnailSize, ThumbnailView.Create(this)) }, 0);
     }
     thumbnailDirty = false;
     return(thumbnail);
 }
Esempio n. 20
0
        private Viewport AddViewToSheet(Document doc, ViewSheet sheet, ElementType noTitle, XYZ pt, ElementId view)
        {
            if (Viewport.CanAddViewToSheet(doc, sheet.Id, view))
            {
                Viewport p3D = Viewport.Create(doc, sheet.Id, view, pt);
                if (noTitle.Name == "No Title")
                {
                    p3D.ChangeTypeId(noTitle.Id);
                }
                return(p3D);
            }

            return(null);
        }
Esempio n. 21
0
        private void AddLegendToSheetView(View legendView, ElementType viewPortType, ViewSheet viewSheet)
        {
            XYZ refPoint = new XYZ(1.355, 0.061, 0);

            if (legendView != null)
            {
                Viewport v1                  = Viewport.Create(_doc, viewSheet.Id, legendView.Id, XYZ.Zero);
                Outline  lvOutline           = v1.GetBoxOutline();
                XYZ      legendViewCenter    = (lvOutline.MaximumPoint + lvOutline.MinimumPoint) / 2.0;
                XYZ      rightCornerToCenter = legendViewCenter - new XYZ(lvOutline.MaximumPoint.X, lvOutline.MinimumPoint.Y, 0);
                v1.ChangeTypeId(viewPortType.Id);
                XYZ diffToMove = refPoint + rightCornerToCenter;
                ElementTransformUtils.MoveElement(_doc, v1.Id, diffToMove);
            }
        }
Esempio n. 22
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp      = commandData.Application;
            UIDocument    uidoc      = uiapp.ActiveUIDocument;
            Application   app        = uiapp.Application;
            Document      doc        = uidoc.Document;
            View          activeView = doc.ActiveView;

            using (var form = new Form1())
            {
                //use ShowDialog to show the form as a modal dialog box.
                form.ShowDialog();

                //if the user hits cancel just drop out of macro
                if (form.DialogResult == forms.DialogResult.Cancel)
                {
                    return(Result.Cancelled);
                }

                string sheetNumber = form.TextString.ToString();

                ViewSheet viewSh = null;

                FilteredElementCollector sheets = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet));
                foreach (ViewSheet sht in sheets)
                {
                    if (sht.SheetNumber == sheetNumber)
                    {
                        viewSh = sht;
                    }
                }


                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Add view to sheet");

                    Viewport newvp = Viewport.Create(doc, viewSh.Id, activeView.Id, new XYZ(1.38, .974, 0));

                    t.Commit();
                }
            }

            return(Result.Succeeded);
        }
Esempio n. 23
0
        public static void AlignSectionsOnSheet(Document doc, List <ElementId> viewsIds, ViewSheet sheet)
        {
            //test reverse viewids

            viewsIds.Reverse();

            //Get scale value of first view

            ViewSection sec1  = doc.GetElement(viewsIds[0]) as ViewSection;
            int         scale = sec1.Scale;

            //Get sheet id
            ElementId sheetId = sheet.Id;

            //Get length of views
            List <double> lengths = new List <double>();

            foreach (ElementId idview in viewsIds)
            {
                Element     viewEl  = doc.GetElement(idview);
                ViewSection viewsec = viewEl as ViewSection;
                double      length  = viewsec.CropBox.Max.X - viewsec.CropBox.Min.X;
                lengths.Add((length / scale));
            }

            double x_coord = 0;

            for (int i = 0; i < viewsIds.Count(); i++)
            {
                if (i == 0)
                {
                    x_coord = 0;
                }

                else
                {
                    x_coord += (lengths[i - 1] + lengths[i]) / 2.0;
                }

                using (Transaction trans = new Transaction(doc, "Place section in sheet"))
                {
                    trans.Start();
                    XYZ      point = new XYZ(x_coord, 0, 0);
                    Viewport v     = Viewport.Create(doc, sheetId, viewsIds[i], point);
                    trans.Commit();
                }
            }
        }
Esempio n. 24
0
        public static bool AddView(Revit.Elements.Views.Sheet sheet, Revit.Elements.Views.View view, Autodesk.DesignScript.Geometry.Point point)
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);

            ElementId sheetId          = sheet.InternalElement.Id;
            ElementId viewId           = view.InternalElement.Id;
            XYZ       viewportLocation = new XYZ(point.X, point.Y, point.Z);

            Viewport.Create(doc, sheetId, viewId, viewportLocation);

            TransactionManager.Instance.TransactionTaskDone();

            return(true);
        }
Esempio n. 25
0
 public void AddViewsToSheet(List <View> views, ElementId viewPortTypeId, bool isDuplicate, ViewDuplicateOption viewDuplicateOption)
 {
     foreach (var v in views)
     {
         var view = v;
         if (isDuplicate)
         {
             try
             {
                 if (view.ViewType == ViewType.Schedule)
                 {
                     var viewid = v.Duplicate(ViewDuplicateOption.Duplicate);
                     view = Doc.GetElement(viewid) as View;
                 }
                 else
                 {
                     var viewid = v.Duplicate(viewDuplicateOption);
                     view = Doc.GetElement(viewid) as View;
                 }
             }
             catch
             {
                 var viewid = v.Duplicate(ViewDuplicateOption.Duplicate);
                 view = Doc.GetElement(viewid) as View;
             }
         }
         try
         {
             var viewname = view.Name;
             if (view.ViewType != ViewType.Schedule)
             {
                 var point = _data.Sel.PickPoint("Pick a Point to Place View:" + viewname);
                 var vp    = Viewport.Create(Doc, Doc.ActiveView.Id, view.Id, point);
                 vp.ChangeTypeId(viewPortTypeId);
             }
             else
             {
                 var point = _data.Sel.PickPoint("Pick a Point to Place View:" + viewname);
                 ScheduleSheetInstance.Create(Doc, Doc.ActiveView.Id, view.Id, point);
             }
         }
         catch
         {
             TaskDialog.Show("Iven EXT:", v.Name + " only can added in one Sheet.");
         }
     }
 }
Esempio n. 26
0
        void CopyView(Viewport viewport, ViewSheet newSheet)
        {
            var viewId = viewport.ViewId;
            var view   = doc.GetElement(viewport.ViewId) as View;
            var point  = viewport.GetBoxCenter();

            if (view.ViewType == ViewType.Legend)
            {
                Viewport.Create(doc, newSheet.Id, viewId, point);
                return;
            }
            else
            {
                var duplicatedViewId = view.Duplicate(ViewDuplicateOption.WithDetailing);
                Viewport.Create(doc, newSheet.Id, duplicatedViewId, point);
            }
        }
Esempio n. 27
0
        private void placeViewsOnNewSheets(Document detailLibrary, Document templateFile, ViewSheet sheet)
        {
            ICollection <ElementId> placedViewports = sheet.GetAllViewports();
            ElementId sourceSheetId = sheet.Id;
            ElementId newSheetId;

            //if (this.sheetIDMap.ContainsKey(sourceSheetId))
            //{
            newSheetId = sheetIDMap[sourceSheetId];
            //}
            ICollection <Viewport> viewsOnSheet = extractViewportsonSheets(detailLibrary, sheet);

            foreach (Viewport viewPort in viewsOnSheet)
            {
                ElementId viewsId = viewPort.ViewId;
                ElementId newViewId;
                //if (this.draftingViewIDMap.ContainsKey(viewsId))
                //{
                newViewId = draftingViewIDMap[viewsId];
                //}
                string      detailNumber = viewPort.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString();
                XYZ         temp         = viewPort.GetBoxCenter();
                ElementId   temp2        = viewPort.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsElementId();
                ElementType type         = detailLibrary.GetElement(temp2) as ElementType;
                ElementId   typeID       = type.GetTypeId();
                string      typeName     = type.Name;

                ElementId viewTitle = temp2;

                Element vpp = new FilteredElementCollector(templateFile).OfCategory(BuiltInCategory.OST_Viewports).FirstOrDefault(q => q.Name == type.Name);

                ElementType type2 = templateFile.GetElement(viewTitle) as ElementType;


                using (Transaction t = new Transaction(templateFile, "Place View"))
                {
                    t.Start();
                    Viewport newvp = Viewport.Create(templateFile, newSheetId, newViewId, temp);
                    newvp.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(detailNumber);
                    newvp.ChangeTypeId(vpp.GetTypeId());
                    t.Commit();
                }
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Generate a new sheet of the Base Level.
        /// </summary>
        public void CreateNewSheet()
        {
            // create a filter to get all the title block type
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.OfCategory(BuiltInCategory.OST_TitleBlocks);
            collector.WhereElementIsElementType();

            // get elementid of first title block type
            ElementId titleblockid = collector.FirstElementId();

            // create the sheet
            ViewSheet viewSheet = ViewSheet.Create(doc, titleblockid);

            viewSheet.Name        = "NEW SHEET TEST";
            viewSheet.SheetNumber = "A-01";

            Viewport.Create(doc, viewSheet.Id, doc.ActiveView.Id, new XYZ(0, 2, 0));
        }
Esempio n. 29
0
        private void AddLegendToSheetView(View legendView, ElementType viewPortType, ViewSheet viewSheet, string position)
        {
            if (legendView != null)
            {
                Viewport v1               = Viewport.Create(_doc, viewSheet.Id, legendView.Id, XYZ.Zero);
                Outline  lvOutline        = v1.GetBoxOutline();
                XYZ      legendViewCenter = (lvOutline.MaximumPoint + lvOutline.MinimumPoint) / 2.0;

                // The position of the legend is Bottom Right by default
                double refX = Default.LEGEND_POSITION_X_MAX;
                double refY = Default.LEGEND_POSITION_Y_MIN_R;

                XYZ legendRefPointToCenter = legendViewCenter - new XYZ(lvOutline.MaximumPoint.X, lvOutline.MinimumPoint.Y, 0);

                if (position.Equals("TopRight"))
                {
                    refX = Default.LEGEND_POSITION_X_MAX;
                    refY = Default.LEGEND_POSITION_Y_MAX_R;

                    legendRefPointToCenter = legendViewCenter - new XYZ(lvOutline.MaximumPoint.X, lvOutline.MaximumPoint.Y, 0);
                }
                else if (position.Equals("BottomLeft"))
                {
                    refX = Default.LEGEND_POSITION_X_MIN;
                    refY = Default.LEGEND_POSITION_Y_MIN_L;

                    legendRefPointToCenter = legendViewCenter - new XYZ(lvOutline.MinimumPoint.X, lvOutline.MinimumPoint.Y, 0);
                }
                else if (position.Equals("TopLeft"))
                {
                    refX = Default.LEGEND_POSITION_X_MIN;
                    refY = Default.LEGEND_POSITION_Y_MAX_L;

                    legendRefPointToCenter = legendViewCenter - new XYZ(lvOutline.MinimumPoint.X, lvOutline.MaximumPoint.Y, 0);
                }

                XYZ refPoint = new XYZ(refX, refY, 0);

                v1.ChangeTypeId(viewPortType.Id);
                XYZ diffToMove = refPoint + legendRefPointToCenter;
                ElementTransformUtils.MoveElement(_doc, v1.Id, diffToMove);
            }
        }
        //
        public void CreateSheetView(View3D view3D)
        {
            // Get an available title block from document
            FilteredElementCollector collector = new FilteredElementCollector(DocSet.doc);

            collector.OfClass(typeof(FamilySymbol));
            collector.OfCategory(BuiltInCategory.OST_TitleBlocks);

            FamilySymbol fs = collector.FirstElement() as FamilySymbol;

            if (fs != null)
            {
                using (Transaction t = new Transaction(DocSet.doc, "Create a new ViewSheet"))
                {
                    t.Start();
                    try
                    {
                        // Create a sheet view
                        ViewSheet viewSheet = ViewSheet.Create(DocSet.doc, fs.Id);
                        if (null == viewSheet)
                        {
                            throw new Exception("Failed to create new ViewSheet.");
                        }

                        // Add passed in view onto the center of the sheet
                        UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2,
                                             (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2);

                        //viewSheet.AddView(view3D, location);
                        Viewport.Create(DocSet.doc, viewSheet.Id, view3D.Id, new XYZ(location.U, location.V, 0));

                        viewSheet.Name = "123456adasqwe";
                        TaskDialog.Show("idsheet", viewSheet.Id.ToString());

                        t.Commit();
                    }
                    catch
                    {
                        t.RollBack();
                    }
                }
            }
        }