/// <summary>
        /// 建立新的3D视图,并将其剖面框设为选择房间的大小
        /// create a new 3D view and change the section box fix the selected room
        /// </summary>
        /// <returns></returns>
        public View3D Create3DView()
        {
            using (Transaction tran = new Transaction(DocSet.doc))
            {
                var collector       = new FilteredElementCollector(DocSet.doc).OfClass(typeof(ViewFamilyType));
                var viewFamilyTypes = from elem in collector
                                      let type = elem as ViewFamilyType
                                                 where type.ViewFamily == ViewFamily.ThreeDimensional
                                                 select type;

                tran.Start("Create A new 3Dview");
                View3D view = View3D.CreateIsometric(DocSet.doc, viewFamilyTypes.First().Id);

                //设定一个新的截面框
                BoundingBoxXYZ boxXyz = new BoundingBoxXYZ();
                XYZ            max    = DocSet.selRoom.get_BoundingBox(view).Max;
                XYZ            min    = DocSet.selRoom.get_BoundingBox(view).Min;
                boxXyz.Max = new XYZ(max.X + 2, max.Y + 2, max.Z);
                boxXyz.Min = new XYZ(min.X - 2, min.Y - 2, min.Z - 0.5);

                view.OrientTo(new XYZ(1, 1, -1));//将3D视角转到左上
                view.SetSectionBox(boxXyz);

                string name = "ISO ";
                name         += _SoANumber;
                view.ViewName = name;
                var par = view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name + " - ISOMETRIC");
                tran.Commit();
                //view.SetOrientation(new ViewOrientation3D )

                return(view);
            }
        }
Exemple #2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            // Get application and document objects
            UIApplication uiApp = commandData.Application;
            Document      doc   = uiApp.ActiveUIDocument.Document;
            UIDocument    uidoc = uiApp.ActiveUIDocument;

            try
            {
                if (!doc.IsWorkshared)
                {
                    TaskDialog.Show("Workset 3D View", "Project doesn't have any Worksets.");
                }
                else
                {
                    ViewFamilyType vft = new FilteredElementCollector(doc)
                                         .OfClass(typeof(ViewFamilyType))
                                         .Cast <ViewFamilyType>()
                                         .FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional);

                    using (Transaction t = new Transaction(doc, "Workset View Creation"))
                    {
                        t.Start();
                        int i = 0;
                        // Loop through all User Worksets only
                        foreach (Workset wst in new FilteredWorksetCollector(doc)
                                 .WherePasses(new WorksetKindFilter(WorksetKind.UserWorkset)))
                        {
                            // Create a 3D View
                            View3D view = View3D.CreateIsometric(doc, vft.Id);

                            // Set the name of the view to match workset
                            view.Name = "WORKSET - " + wst.Name;

                            // Isolate elements in the view using a filter to find elements only in this workset
                            view.IsolateElementsTemporary(new FilteredElementCollector(doc)
                                                          .WherePasses(new ElementWorksetFilter(wst.Id))
                                                          .Select(q => q.Id)
                                                          .ToList());
                            i++;
                        }
                        t.Commit();
                        TaskDialog.Show("Workset 3D View", i.ToString() + " Views Created Successfully!");
                    }
                }
                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
        public static View3D CreatePhase3DView(Document doc, ItemInfo itemInfo, ViewFamilyType view3dFamilyType, bool overwrite)
        {
            View3D view3D = null;

            try
            {
                string viewName = "PH - 3D - " + itemInfo.ItemName;
                using (Transaction trans = new Transaction(doc))
                {
                    FilteredElementCollector collector = new FilteredElementCollector(doc);
                    List <View3D>            view3ds   = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList();
                    var views = from view in view3ds where view.Name == viewName select view;
                    if (views.Count() > 0)
                    {
                        if (overwrite)
                        {
                            view3D = views.First();
                        }
                        else
                        {
                            return(view3D);
                        }
                    }

                    if (null == view3D)
                    {
                        trans.Start("Create 3D View");
                        try
                        {
                            view3D      = View3D.CreateIsometric(doc, view3dFamilyType.Id);
                            view3D.Name = viewName;
                            if (view3D.CanModifyViewDiscipline())
                            {
                                view3D.Discipline = ViewDiscipline.Coordination;
                            }

                            Parameter param = view3D.get_Parameter(BuiltInParameter.VIEW_PHASE);
                            if (null != param)
                            {
                                if (!param.IsReadOnly)
                                {
                                    param.Set(itemInfo.ItemId);
                                }
                            }
                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            trans.RollBack();
                            MessageBox.Show("Failed to create 3d view by phases.\n" + ex.Message, "Create 3D View", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create 3d views by phases.\n" + ex.Message, "Create 3D Views by Phases", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(view3D);
        }
Exemple #4
0
        public static View3D Create3DView(ViewOrientation3D orient, string name, bool isPerspective)
        {
            //http://adndevblog.typepad.com/aec/2012/05/viewplancreate-method.html

            IEnumerable <ViewFamilyType> viewFamilyTypes = from elem in new
                                                           FilteredElementCollector(dynRevitSettings.Doc.Document).OfClass(typeof(ViewFamilyType))
                                                           let type = elem as ViewFamilyType
                                                                      where type.ViewFamily == ViewFamily.ThreeDimensional
                                                                      select type;

            //create a new view
            View3D view = isPerspective ?
                          View3D.CreatePerspective(dynRevitSettings.Doc.Document, viewFamilyTypes.First().Id) :
                          View3D.CreateIsometric(dynRevitSettings.Doc.Document, viewFamilyTypes.First().Id);

            view.SetOrientation(orient);
            view.SaveOrientationAndLock();
            try
            {
                //will fail if name is not unique
                view.Name = name;
            }
            catch
            {
                view.Name = CreateUniqueViewName(name);
            }


            return(view);
        }
        public static View3D Create3DView(Document doc)
        {
            View3D view = null;

            try
            {
                using (Transaction t = new Transaction(doc, "Create view"))
                {
                    t.Start();
                    //Find a 3D view type
                    var collector       = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType));
                    var viewFamilyTypes = from elem in collector
                                          let vftype = elem as ViewFamilyType
                                                       where vftype.ViewFamily == ViewFamily.ThreeDimensional
                                                       select vftype;
                    // Create a new View3D
                    if (viewFamilyTypes.Count() == 0)
                    {
                        return(null);
                    }
                    view = View3D.CreateIsometric(doc, viewFamilyTypes.First().Id);

                    if (view.CanModifyViewDiscipline())
                    {
                        view.Discipline = ViewDiscipline.Coordination;
                    }
                    if (view.CanModifyDetailLevel())
                    {
                        view.DetailLevel = ViewDetailLevel.Fine;
                    }
                    if (view.CanModifyDisplayStyle())
                    {
                        view.DisplayStyle = DisplayStyle.Realistic;
                    }

                    // show all categories
                    foreach (Category cat in doc.Settings.Categories)
                    {
                        if (view.GetCategoryHidden(cat.Id))
                        {
                            view.SetCategoryHidden(cat.Id, false);
                        }
                    }
                    // hide annotations
                    view.AreAnnotationCategoriesHidden = true;

                    // disable the crop box or section box
                    view.CropBoxActive      = false;
                    view.CropBoxVisible     = false;
                    view.IsSectionBoxActive = false;

                    t.Commit();
                }
                return(view);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public View3D Get3dView(Document doc)
        {
            FilteredElementCollector val = new FilteredElementCollector(doc).OfClass(typeof(View3D));
            Regex regex  = new Regex("^Shadow Analysis 2 Export [0-9]*$");
            Regex regex2 = new Regex("[0-9]*$");
            int   num    = 0;

            foreach (Element item in val)
            {
                View3D val2  = item;
                Match  match = regex.Match(val2.get_Name());
                if (match.Success)
                {
                    int num2 = int.Parse(regex2.Match(match.Value).Value);
                    if (num < num2)
                    {
                        num = num2;
                    }
                }
            }
            Transaction val3 = new Transaction(doc);

            val3.Start("Create 3D view");
            ViewFamilyType val4 = ((IEnumerable) new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>((Func <ViewFamilyType, bool>)((ViewFamilyType x) => 102 == (int)x.get_ViewFamily()));
            View3D         val5 = View3D.CreateIsometric(doc, val4.get_Id());

            val5.set_Name("Shadow Analysis 2 Export " + (num + 1).ToString());
            val3.Commit();
            return(val5);
        }
        /// <summary>
        /// Создает отдельный вид для просмотра коллизий
        /// или возвращает его, если он существует
        /// </summary>
        /// <returns></returns>
        static public View3D GetView(Document doc, string name)
        {
            View3D[] views = new FilteredElementCollector(doc).OfClass(typeof(View3D))
                             .WhereElementIsNotElementType().ToElements().Cast <View3D>().ToArray();
            var v = views.Where(x => x.Name == name);

            if (v.Count() == 0)
            {
                var viewType = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).ToElements()
                               .Cast <ViewFamilyType>().Where(x => x.ViewFamily == ViewFamily.ThreeDimensional).First();
                View3D view;
                using (var tr = new Transaction(doc, "Создание 3D вида"))
                {
                    tr.Start();
                    view      = View3D.CreateIsometric(doc, viewType.Id);
                    view.Name = name;
                    tr.Commit();
                }
                return(view);
            }
            else
            {
                return(v.First());
            }
        }
        // We need to create a 3dview because the when we open a new project file a 3d view does not exist and raytracers need 3dviews
        private View3D createView3d()
        {
            FilteredElementCollector collector0 = new FilteredElementCollector(_doc).OfClass(typeof(View3D));

            foreach (View3D item in collector0)
            {
                if (!item.IsTemplate)
                {
                    return(item);
                }
            }
            FilteredElementCollector collector1 = new FilteredElementCollector(_doc);

            collector1 = collector1.OfClass(typeof(ViewFamilyType));
            IEnumerable <ViewFamilyType> viewFamilyTypes = from elem in collector1 let vftype = elem as ViewFamilyType where (vftype.ViewFamily == ViewFamily.ThreeDimensional) select vftype;

            using (Transaction createView3D = new Transaction(_doc))
            {
                createView3D.Start("Create 3D View");
                View3D view3D = View3D.CreateIsometric(_doc, viewFamilyTypes.First <ViewFamilyType>().Id);
                if (null != view3D)
                {
                    XYZ eye     = new XYZ(10, 10, 10);
                    XYZ up      = new XYZ(0, 1, 1);
                    XYZ forward = new XYZ(0, 1, -1);
                    ViewOrientation3D viewOrientation3D = new ViewOrientation3D(eye, up, forward);
                    view3D.SetOrientation(viewOrientation3D);
                    view3D.Name = "RayTracer View";
                }
                createView3D.Commit();
                return(view3D);
            }
        }
Exemple #9
0
        /// <summary>
        /// Get all 3D views in current document
        /// </summary>
        private void Get3DViews()
        {
            m_view3DList = new List <Autodesk.Revit.DB.Element>();
            FilteredElementCollector collector = new FilteredElementCollector(m_document);
            var query = from elem in collector.OfClass(typeof(View3D))
                        let viewElem = elem as View3D
                                       where null != viewElem && !viewElem.IsTemplate
                                       select elem;

            m_view3DList = query.ToList <Element>();
            if (m_view3DList.Count == 0)
            {
                //View3D view3D = m_document.Create.NewView3D(new Autodesk.Revit.DB.XYZ (0, 0, 1));
                IList <Element> viewFamilyTypes = new FilteredElementCollector(m_document).OfClass(typeof(ViewFamilyType)).ToElements();
                ElementId       View3DId        = new ElementId(-1);
                foreach (Element e in viewFamilyTypes)
                {
                    if (e.Name == "3D View")
                    {
                        View3DId = e.Id;
                    }
                }
                View3D            view3D            = View3D.CreateIsometric(m_document, View3DId);
                ViewOrientation3D viewOrientation3D = new ViewOrientation3D(new XYZ(1, 1, -1), new XYZ(0, 0, 1), new XYZ(0, 1, 0));
                view3D.SetOrientation(viewOrientation3D);
                view3D.SaveOrientation();
                m_view3DList.Add(view3D);
            }
        }
Exemple #10
0
        public static View3D GetOrCreateDefault3DView(this Document doc)
        {
            var view3d = new FilteredElementCollector(doc)
                         .OfClass(typeof(View3D))
                         .Cast <View3D>()
                         .Where(v => v.Name.ToUpper() == "{3D}")
                         .FirstOrDefault();

            if (view3d == null)
            {
                // Create a new 3d view (rare)
                // Grab the view family type.
                var vft = new FilteredElementCollector(doc)
                          .OfClass(typeof(ViewFamilyType))
                          .Cast <ViewFamilyType>()
                          .Where(v => v.ViewFamily == ViewFamily.ThreeDimensional)
                          .FirstOrDefault();

                using (var tr = new Transaction(doc))
                {
                    tr.Start("Create 3D view for export to gltf");
                    try
                    {
                        view3d = View3D.CreateIsometric(doc, vft.Id);
                        tr.Commit();
                    }
                    catch (Exception e)
                    {
                        tr.RollBack();
                    }
                }
            }

            return(view3d);
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        /// <param name="view3D"></param>
        /// <returns></returns>
        private static Revit.Element CloneElement(Autodesk.Revit.UI.UIApplication app, View3D view3D)
        {
            XYZ    viewDir     = view3D.ViewDirection;
            View3D view3DClone = View3D.CreateIsometric(app.ActiveUIDocument.Document, view3D.GetTypeId());

            Utils.ParamUtil.SetParameters(view3DClone.Parameters, view3D.Parameters);
            return(view3DClone);
        }
Exemple #12
0
        public static View3D New3DView(this Document document, string name)
        {
            var viewFamilyType =
                new FilteredElementCollector(document).OfClass(typeof(ViewFamilyType))
                .Cast <ViewFamilyType>()
                .FirstOrDefault(type => type.ViewFamily == ViewFamily.ThreeDimensional);

            return(null == viewFamilyType ? null : View3D.CreateIsometric(document, viewFamilyType.Id));
        }
Exemple #13
0
        public void ViewCreate()
        {
            Document doc = this.ActiveUIDocument.Document;



            // get a ViewFamilyType for a 3D View. created new instance of ViewFamilYType calle 'viewFamilyType'

            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).
                                             // Creates new filteredElementCollector to select all ViewFamilyTypes
                                             OfClass(typeof(ViewFamilyType)).

                                             Cast <ViewFamilyType>()

                                             where v.ViewFamily == ViewFamily.ThreeDimensional

                                             select v).First();


            Categories categories = doc.Settings.Categories;

            Category dim = categories.get_Item(BuiltInCategory.OST_Dimensions);

            Category line = categories.get_Item(BuiltInCategory.OST_Lines);

            XYZ eye = new XYZ(100, 100, 100);

            XYZ forward = new XYZ(-1, 1, -1);

            XYZ up = new XYZ(-1, 1, 2);

            ViewOrientation3D vOrient = new ViewOrientation3D(eye, up, forward);


            using (Transaction t = new Transaction(doc, "Create view"))

            {
                t.Start();

                View3D view = View3D.CreateIsometric(doc, viewFamilyType.Id);

                view.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE)
                .Set(4);


                view.SetOrientation(vOrient);

                view.HideCategoryTemporary(dim.Id);

                view.HideCategoryTemporary(line.Id);

                view.SaveOrientationAndLock();


                t.Commit();
            }
        }
        public View Create3DView(Document doc, PickedBox pickedbox)
        {
            var viewfamilytypes = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                  .Cast <ViewFamilyType>().Where(m => m.ViewFamily == ViewFamily.ThreeDimensional);
            var targetviewfamilytypeId = viewfamilytypes.First().Id;
            var result = View3D.CreateIsometric(doc, targetviewfamilytypeId);

            return(result);
        }
Exemple #15
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            if (FilesOption())
            {
                foreach (var file in files)
                {
                    string     codeBase        = Assembly.GetExecutingAssembly().CodeBase;
                    UriBuilder uri             = new UriBuilder(codeBase);
                    string     path            = Uri.UnescapeDataString(uri.Path);
                    var        placeholderFile = Path.GetDirectoryName(path) + @"\placeholderFile.rte";

                    UIApplication uiapp = commandData.Application;
                    UIDocument    uidoc = uiapp.OpenAndActivateDocument(file);
                    Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                    Document doc             = uidoc.Document;
                    AssetSet objlibraryAsset = app.get_Assets(AssetType.Appearance);

                    #region///判断是否为空视图,若为空视图,切换为3d视图
                    View3D view = doc.ActiveView as View3D;
                    if (null == view)
                    {
                        IEnumerable <ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                                                       let type = elem as ViewFamilyType
                                                                                  where type.ViewFamily == ViewFamily.ThreeDimensional
                                                                                  select type;
                        Transaction ts = new Transaction(doc, "Change3D");
                        try
                        {
                            ts.Start();
                            XYZ    direction = new XYZ(-1, 1, -1);
                            View3D view3D    = View3D.CreateIsometric(doc, viewFamilyTypes.First().Id);
                            //View3D view3D = uiDoc.Document.Create.NewView3D(new XYZ(-1, 1, -1));//斜视45度
                            ts.Commit();
                            //切换视图必须在事务结束后,否则会提示错误:
                            //Cannot change the active view of a modifiable document
                            uidoc.ActiveView = view3D;
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("ex", ex.ToString());
                            ts.RollBack();
                        }
                        //Util.ErrorMsg("You must be in a 3D view to export.");
                    }
                    #endregion

                    ExportView3D(doc.ActiveView as View3D, CreatFilePath(doc), objlibraryAsset);

                    //通过占位文件关闭当前文件
                    var docPlaceholder = commandData.Application.OpenAndActivateDocument(placeholderFile);
                    doc.Close(false);
                }
                MessageBox.Show("导出成功!", "通知");
            }
            return(Result.Succeeded);
        }
        public static View3D Create3DView(this Document currentDocument)
        {
            // Filters the model for 3D Views
            FilteredElementCollector fec3DViews =
                new FilteredElementCollector(currentDocument);

            // creates an Isometric 3D View
            return(View3D.CreateIsometric(
                       currentDocument,
                       fec3DViews.OfType <View3D>().First().Id));
        }
Exemple #17
0
        private static View3D GetOrCreate3DView(Document doc)
        {
            var view3D = Get3DView(doc) ?? View3D.CreateIsometric(doc, GetViewFamilyTypeId(doc));

            view3D.Name = "OsmDemoView";

            var settings = new FilteredElementCollector(doc).OfClass(typeof(StartingViewSettings)).Single() as StartingViewSettings;

            settings.ViewId = view3D.Id;

            return(view3D);
        }
        ////[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        private bool CreateWinterViews(ModelSetupWizard.TransactionLog log)
        {
            var id = GetViewFamilyId(doc, ViewFamily.ThreeDimensional);

            // FIXME add error message here
            if (id == null)
            {
                log.AddFailure("Could not gererate 3d view. FamilyId not found");
                return(false);
            }

            while (StartTime <= EndTime)
            {
                using (var t = new Transaction(doc))
                {
                    t.Start("Create Solar View");
                    View view = View3D.CreateIsometric(doc, id);
                    view.ViewTemplateId = ElementId.InvalidElementId;
                    var niceMinutes = "00";
                    if (StartTime.Minute > 0)
                    {
                        niceMinutes = StartTime.Minute.ToString(CultureInfo.CurrentCulture);
                    }
                    var vname = "SOLAR ACCESS - " + StartTime.ToShortDateString() + "-" + StartTime.Hour + "." +
                                niceMinutes;
                    view.Name = GetNiceViewName(doc, vname);
                    var sunSettings = view.SunAndShadowSettings;
                    sunSettings.StartDateAndTime = StartTime;

                    if (StartTime <= sunSettings.GetSunrise(StartTime).ToLocalTime() || StartTime >= sunSettings.GetSunset(EndTime).ToLocalTime())
                    {
                        doc.Delete(view.Id);
                        log.AddFailure("Cannot rotate a view that is not in daylight hours: " + vname);
                        StartTime = StartTime.Add(ExportTimeInterval);
                        continue;
                    }

                    sunSettings.SunAndShadowType = SunAndShadowType.StillImage;
                    t.Commit();

                    if (!RotateView(view))
                    {
                        doc.Delete(view.Id);
                        log.AddFailure("Could not rotate view: " + vname);
                        continue;
                    }
                    log.AddSuccess("View created: " + vname);
                    StartTime = StartTime.Add(ExportTimeInterval);
                }
            }
            return(true);
        }
        public static View3D CreateDesignOption3DView(Document doc, ItemInfo itemInfo, ViewFamilyType view3dFamilyType, bool overwrite)
        {
            View3D view3D = null;

            try
            {
                string viewName = "OP - 3D - " + itemInfo.ItemName;
                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start("Create 3D View");
                    try
                    {
                        FilteredElementCollector collector = new FilteredElementCollector(doc);
                        List <View3D>            view3ds   = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList();
                        var views = from view in view3ds where view.Name == viewName select view;
                        if (views.Count() > 0)
                        {
                            if (overwrite)
                            {
                                view3D = views.First();
                            }
                            else
                            {
                                return(view3D);
                            }
                        }

                        if (view3D == null)
                        {
                            view3D      = View3D.CreateIsometric(doc, view3dFamilyType.Id);
                            view3D.Name = viewName;
                            if (view3D.CanModifyViewDiscipline())
                            {
                                view3D.Discipline = ViewDiscipline.Coordination;
                            }

                            trans.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.RollBack();
                        MessageBox.Show("Failed to create a 3d view for the design option, " + itemInfo.ItemName + "\n" + ex.Message, "Create 3D View", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create 3d views by design options.\n" + ex.Message, "Create 3D Views by Design Options", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(view3D);
        }
Exemple #20
0
        public static View3D GetMatching3DView(this View view, Document doc)
        {
            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).
                                             OfClass(typeof(ViewFamilyType)).
                                             Cast <ViewFamilyType>()
                                             where v.ViewFamily == ViewFamily.ThreeDimensional
                                             select v).First();

            View3D view3d = View3D.CreateIsometric(doc, viewFamilyType.Id);

            view3d.Name = view.Name + " 3D temp view";

            ViewBox myviewbox = GetViewBox(view);

            if (myviewbox.bbox == null)
            {
                BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();



                boundingBoxXYZ.Min = myviewbox.P1;
                boundingBoxXYZ.Max = myviewbox.P2;
                view3d.SetSectionBox(boundingBoxXYZ);
            }
            else
            {
                view3d.SetSectionBox(myviewbox.bbox);
            }
            view3d.SetOrientation(new ViewOrientation3D(myviewbox.EyePosition, myviewbox.DirectionUp, myviewbox.DirectionView));



            foreach (Category cat in doc.Settings.Categories)
            {
                try
                {
                    if (cat.CategoryType == CategoryType.Model && cat.get_AllowsVisibilityControl(view3d))
                    {
                        view3d.SetVisibility(cat, view.GetVisibility(cat));
                    }
                }
                catch (System.Exception e) { }
            }


            doc.Regenerate();

            return(view3d);
        }
        private View3D CreateDefaultOrthoView()
        {
            View3D view3D = null;

            try
            {
                var viewName  = "SmartBCF - Orthogonal - " + Environment.UserName;
                var collector = new FilteredElementCollector(ActiveDoc);
                var view3ds   = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList();
#if RELEASE2015 || RELEASE2016 || RELEASE2017 || RELEASE2018
                var viewfound = from view in view3ds where view.IsTemplate == false && view.IsPerspective == false && view.ViewName == viewName select view;
#else
                var viewfound = from view in view3ds where view.IsTemplate == false && view.IsPerspective == false && view.Name == viewName select view;
#endif
                if (viewfound.Any())
                {
                    view3D = viewfound.First();
                }
                else
                {
                    var viewFamilyTypeId = GetViewFamilyTypeId();
                    if (viewFamilyTypeId != ElementId.InvalidElementId)
                    {
                        using (var trans = new Transaction(ActiveDoc))
                        {
                            trans.Start("Create View");
                            try
                            {
                                view3D      = View3D.CreateIsometric(ActiveDoc, viewFamilyTypeId);
                                view3D.Name = viewName;
                                trans.Commit();
                            }
                            catch (Exception)
                            {
                                trans.RollBack();
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }

            return(view3D);
        }
Exemple #22
0
        /// <summary>
        /// 创建3D视图
        /// </summary>
        /// <param name="transaction"></param>
        /// <param name="doc"></param>
        /// <param name="viewName"></param>
        /// <returns></returns>
        public static View3D Create3DView(Document doc, string viewName)
        {
            var sampleViewId = Get3DProjectViewId(doc);

            if (sampleViewId == null)
            {
                throw new NotImplementedException("当前工程没有三维视图模版!请点击默认三维视图或创建模版后再操作!");
            }
            var    viewTypeId = doc.GetElement(sampleViewId).get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsElementId();
            View3D view       = View3D.CreateIsometric(doc, viewTypeId);

            view.Name         = viewName;
            view.DetailLevel  = ViewDetailLevel.Fine;
            view.DisplayStyle = DisplayStyle.Shading;
            return(view);
            //view.get_Parameter(BuiltInParameter.VIEW_NAME).Set(viewName);
        }
        public static View3D CreateTweakedView3D(this Document document)
        {
            View3D view3D;

            using (var transaction = new Transaction(document, "Switch to 3D view and tweak it"))
            {
                transaction.Start();

                var viewTypeId = FindViewTypes(document, ViewType.ThreeD).FirstOrDefault()?.Id;
                view3D = View3D.CreateIsometric(document, viewTypeId);
                view3D.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(3);
                view3D.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE).Set(6);

                transaction.Commit();
            }

            return(view3D);
        }
Exemple #24
0
        public static Dictionary <string, object> createNavisView(Document document)
        {
            string message = "";

            //Document doc = DocumentManager.Instance.CurrentDBDocument;
            //Document openedDoc = null;
            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

            //ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath);
            //OpenOptions openOpt = new OpenOptions();
            try
            {
                //openedDoc = app.OpenDocumentFile(path, openOpt);
                var direction      = new XYZ(-1, 1, -1);
                var collector      = new FilteredElementCollector(document);
                var viewFamilyType = collector.OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>()
                                     .FirstOrDefault(x => x.ViewFamily == ViewFamily.ThreeDimensional);

                using (Transaction ttNew = new Transaction(document, "abc"))
                {
                    ttNew.Start();
                    View3D navisView = View3D.CreateIsometric(document, viewFamilyType.Id);
                    navisView.SetOrientation(new ViewOrientation3D(direction, new XYZ(0, 1, 1), new XYZ(0, 1, -1)));
                    navisView.ViewName = "Navisworks";
                    ttNew.Commit();
                    message = "Created";
                    //document.Close(true);
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            return(new Dictionary <string, object>
            {
                { "document", document },
                { "message", message }
            });
        }
Exemple #25
0
        public Result setup_sections()
        {
            // get a ViewFamilyType for a 3D View
            ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc).
                                             OfClass(typeof(ViewFamilyType)).
                                             Cast <ViewFamilyType>()
                                             where v.ViewFamily == ViewFamily.ThreeDimensional
                                             select v).First();

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

                // Create the 3d view
                View3D view = View3D.CreateIsometric(doc, viewFamilyType.Id);

                // Set the name of the view
                view.Name = "Basement Section Box";

                // Set the name of the transaction
                // A transaction can be renamed after it has been started
                t.SetName("Create view " + view.Name);

                // Create a new BoundingBoxXYZ to define a 3D rectangular space
                BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();

                // Set the lower left bottom corner of the box
                // Use the Z of the current level.
                // X & Y values have been hardcoded based on this RVT geometry
                boundingBoxXYZ.Min = new XYZ(-2, 2, level.Elevation - 5);

                boundingBoxXYZ.Max = new XYZ(500 / 12, 500 / 12, 50);

                // Apply this bouding box to the view's section box
                view.SetSectionBox(boundingBoxXYZ);

                t.Commit();
            }
            return(Result.Succeeded);
        }
        public View3D CreateView3D(int scale)
        {
            Document _doc = Level?.Document;

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

            View3D _view3D = View3D.CreateIsometric(_doc, _3DViewFamilyType.Id);

            _view3D.SetSectionBox(Bounds);
            string _viewName = GetViewName("3D");

            if (string.IsNullOrWhiteSpace(_viewName) == false)
            {
                _view3D.Name = _viewName;
            }
            _view3D.Scale = scale;

            return(_view3D);
        }
Exemple #27
0
        public static bool InitByDocument(UIDocument uidoc)
        {
            UIDoc = uidoc;
            Doc   = UIDoc.Document;
            string viewName = "土方分块";

            View3D = Revit_Document_Helper.GetElementByNameAs <View3D>(Doc, viewName);
            if (View3D == null)
            {
                using (var transaction = new Transaction(Doc, "EarthworkBlocking." + nameof(InitByDocument)))
                {
                    transaction.Start();
                    try
                    {
                        var viewFamilyType = new FilteredElementCollector(Doc).OfClass(typeof(ViewFamilyType)).ToElements().FirstOrDefault(c => (c as ViewFamilyType).FamilyName == "三维视图" || (c as ViewFamilyType).FamilyName == "3D View");
                        if (viewFamilyType == null)
                        {
                            TaskDialog.Show("消息", "该功能需在三维视图下操作");
                            return(false);
                        }
                        View3D      = View3D.CreateIsometric(Doc, viewFamilyType.Id);
                        View3D.Name = viewName;
                        transaction.Commit();
                        TaskDialog.Show("消息", "三维视图(土方分块)新建成功");
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        transaction.RollBack();
                        TaskDialog.Show("消息", "视图(土方分块)新建失败,错误详情:" + ex.ToString());
                        return(false);
                    }
                }
            }
            else
            {
                return(true);
            }
        }
Exemple #28
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;

            var acview = doc.ActiveView;

            var viewfamilytype = doc.TCollector <ViewFamilyType>()
                                 .Where(m => m.ViewFamily == ViewFamily.ThreeDimensional).First();

            var elementRefs = sel.PickObjects(ObjectType.Element,
                                              doc.GetSelectionFilter(m => { return(m.Category.CategoryType == CategoryType.Model); }));
            var eles   = elementRefs.Select(m => m.ElementId.GetElement(doc));
            var eleids = elementRefs.Select(m => m.ElementId).ToList();

            var tembox = default(BoundingBoxXYZ);

            Transaction temtran = new Transaction(doc, "temTran");

            temtran.Start();
            var group = doc.Create.NewGroup(eleids);

            tembox = group.get_BoundingBox(acview);
            temtran.RollBack();

            var newAcview = default(View);

            doc.Invoke(m =>
            {
                var _3dview = View3D.CreateIsometric(doc, viewfamilytype.Id);
                _3dview.SetSectionBox(tembox);
                newAcview = _3dview;
            }, "框选三维");

            uidoc.ActiveView = newAcview;
            return(Result.Succeeded);
        }
Exemple #29
0
        public static List <Revit.Elements.Element> ThreeDViewByRoom(List <Revit.Elements.Room> Rooms, List <String> Names, double Offset = 500)
        {
            var ThreeDViews = new List <Revit.Elements.Element>();
            var doc         = DocumentManager.Instance.CurrentDBDocument;
            var vtype       = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault(a => a.ViewFamily == ViewFamily.ThreeDimensional);

            TransactionManager.Instance.EnsureInTransaction(doc);
            foreach (var elem in Rooms.Zip(Names, Tuple.Create))
            {
                BoundingBoxXYZ bbox       = elem.Item1.InternalElement.get_BoundingBox(doc.ActiveView);
                var            newbbox    = Utility.crop_box(bbox, Offset / 304.8);
                View3D         ThreeDView = View3D.CreateIsometric(doc, vtype.Id);
                ThreeDView.Name = elem.Item2;
                ThreeDView.SetSectionBox(newbbox);
                ThreeDView.CropBoxActive  = true;
                ThreeDView.CropBoxVisible = true;
                ThreeDView.Scale          = 50;
                ThreeDViews.Add(ThreeDView.ToDSType(true));
            }
            TransactionManager.Instance.TransactionTaskDone();

            return(ThreeDViews);
        }
Exemple #30
0
        public static void IntegrateEnergyResults(UIDocument uidoc, Document doc, IDFFile.Building Bui, string massName, Dictionary <string, double[]> resultsDF, Dictionary <string, Element> masses)
        {
            Bui.AssociateProbabilisticEnergyPlusResults(resultsDF);
            View3D v1 = (new FilteredElementCollector(doc).OfClass(typeof(View3D)).Cast <View3D>()).First(v => v.Name.Contains("Op - " + massName));

            using (Transaction tx = new Transaction(doc, "Simplified EP"))
            {
                uidoc.ActiveView = v1;
                tx.Start();
                View3D v2 = View3D.CreateIsometric(doc, v1.GetTypeId());
                v2.Name = "SimplifiedEP-" + massName;
                IEnumerable <Element> allElements = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Mass);
                allElements = allElements.Concat(new FilteredElementCollector(doc).WherePasses(new ElementClassFilter(typeof(CurveElement))));
                v2.HideElements(allElements.Select(e => e.Id).ToList());
                v2.UnhideElements(new List <ElementId>()
                {
                    masses[massName].Id
                });
                tx.Commit();

                uidoc.ActiveView = v2;
            }
        }