Example #1
0
 //改变图元 投影线/截面线 的颜色_当前视图
 public void ViewElementOverride(Document doc, ElementId eleId, ICollection <ElementId> eleIds, OverrideGraphicSettings ogs)
 {
     Autodesk.Revit.DB.View vie = doc.GetElement(eleId) as Autodesk.Revit.DB.View;
     foreach (ElementId tempEId in eleIds)
     {
         vie.SetElementOverrides(tempEId, ogs);
     }
 }
Example #2
0
        public static bool IsHiddenOnView(Revit.Elements.Element element, Revit.Elements.Views.View view)
        {
            // Unwrap elements
            Autodesk.Revit.DB.Element elem      = element.InternalElement;
            Autodesk.Revit.DB.View    inputView = (Autodesk.Revit.DB.View)view.InternalElement;

            return(elem.IsHidden(inputView));
        }
Example #3
0
 public ViewLegendCopyForm(Document _doc, View _TempLegend)
 {
     InitializeComponent();
     //set the Doc variable with the one passed to the Form
     Doc = _doc;
     //set the TempLegen varaible with the one pass to the From
     TempLegend = _TempLegend;
 }
Example #4
0
        public DBViewItem(RView dbView, Document dbDoc)
        {
            ElementType viewType = dbDoc.GetElement(dbView.GetTypeId()) as ElementType;

            Name     = viewType.Name + " " + dbView.Name;
            Id       = dbView.Id;
            UniqueId = dbView.UniqueId;
        }
Example #5
0
 public DoubleTeeInfo(Document doc, FamilyInstance familyInstance)
 {
     this.Parent      = familyInstance;
     this.document    = doc;
     this._activeView = doc.ActiveView;
     this._plane      = Plane.CreateByNormalAndOrigin(this._activeView.ViewDirection, this._activeView.Origin);
     this.CalculatePoint();
 }
Example #6
0
        private bool SetupSheetList()
        {
            ListViewItem lvItem;
            ListViewItem lvItemSave = null;

            bool boolIsViewSheet = false;

            // make sure that we have some sheets to show
            if (_DBMgr.SheetCount == 0)
            {
                return(false);
            }


            // get the ActiveView
            Autodesk.Revit.DB.View vActive = _DBMgr.ActiveView;

            if (vActive.ViewType == ViewType.DrawingSheet)
            {
                boolIsViewSheet = true;
            }



            // clear the list box
            listViewSheets.Items.Clear();

            // fill the list box
            foreach (ViewSheet vs in _DBMgr.AllViewSheets())
            {
                // create the ListViewItem for the row - sheet number first
                lvItem = new ListViewItem(vs.SheetNumber);
                // add the sheet name
                lvItem.SubItems.Add(vs.Name);

                // add the ListViewItem to the ListView control
                listViewSheets.Items.Add(lvItem);

                // check to see if ViewSheet matches the ActiveView
                if ((boolIsViewSheet) && (vActive.UniqueId.Equals(vs.UniqueId)))
                {
                    lvItemSave = lvItem;
                }
            }

            // do we pre-select a sheet
            if (lvItemSave != null)
            {
                // a sheetview is the active view - preselect
                intSelItemIdx          = listViewSheets.Items.IndexOf(lvItemSave);
                listViewSheets.TopItem = lvItemSave;
            }

            SelectSheet(intSelItemIdx);

            // setup and populated
            return(true);
        }
Example #7
0
        /// <summary>
        /// Animate the transparency of an element. This will export images of the element, then revert the element back to where it was.
        /// Inspired by the Bad Monkeys team.
        /// </summary>
        /// <param name="element">The element to set transparency to.</param>
        /// <param name="startPercentage">The transparency start percent.</param>
        /// <param name="endPercentage">The transparency end percent.</param>
        /// <param name="iterations">Numnber of images.</param>
        /// <param name="directoryPath">Where to save the images.</param>
        /// <param name="view">View to export from.</param>
        /// <returns name="element">The element.</returns>
        /// <search>
        ///  rhythm
        /// </search>
        public static object AnimateTransparency(List <global::Revit.Elements.Element> element, int startPercentage, int endPercentage, int iterations, string directoryPath, global::Revit.Elements.Element view)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            UIDocument uiDocument          = new UIDocument(doc);

            Autodesk.Revit.DB.View internalView = (Autodesk.Revit.DB.View)view.InternalElement;
            //create a new form!
            DefaultProgressForm statusBar = new DefaultProgressForm("Exporting Images", "Exporting image {0} of " + iterations.ToString(), "Animate Element Transparency", iterations + 1);
            double d           = (endPercentage - startPercentage) / (iterations - 1.0);
            int    incrementor = Convert.ToInt32(d);


            //starts a transaction group so we can roolback the changes after
            using (TransactionGroup transactionGroup = new TransactionGroup(doc, "group"))
            {
                TransactionManager.Instance.ForceCloseTransaction();
                transactionGroup.Start();
                using (Transaction t2 = new Transaction(doc, "Modify parameter"))
                {
                    int num2 = 0;
                    while (startPercentage <= endPercentage)
                    {
                        statusBar.Activate();
                        t2.Start();
                        //declare the graphic settings overrides
                        OverrideGraphicSettings ogs = new OverrideGraphicSettings();
                        //solid fill id
                        ElementId pattId = new ElementId(20);
                        //set the overrides to the graphic settings
                        ogs.SetSurfaceTransparency(startPercentage);
                        foreach (var e in element)
                        {
                            //apply the changes to view
                            internalView.SetElementOverrides(e.InternalElement.Id, ogs);
                        }
                        t2.Commit();

                        uiDocument.RefreshActiveView();
                        var exportOpts = new ImageExportOptions
                        {
                            FilePath              = directoryPath + num2.ToString(),
                            FitDirection          = FitDirectionType.Horizontal,
                            HLRandWFViewsFileType = ImageFileType.PNG,
                            ImageResolution       = ImageResolution.DPI_300,
                            ShouldCreateWebSite   = false
                        };
                        doc.ExportImage(exportOpts);
                        ++num2;
                        startPercentage = startPercentage + incrementor;
                        statusBar.Increment();
                    }
                }
                transactionGroup.RollBack();
            }
            statusBar.Close();

            return(element);
        }
Example #8
0
        private void btn_Select_Click(object sender, EventArgs e)
        {
            List <ViewType> viewTypes = new List <ViewType>();
            List <View>     views     = new List <View>();

            List <ViewType> allowedViewTypes = new List <ViewType>()
            {
                ViewType.FloorPlan,
                ViewType.CeilingPlan,
                ViewType.Elevation,
                ViewType.ThreeD,
                ViewType.Legend,
                ViewType.Schedule,
                ViewType.DrawingSheet,
                ViewType.Walkthrough,
                ViewType.Section,
                ViewType.Undefined,
                ViewType.AreaPlan,
                ViewType.EngineeringPlan,
                ViewType.Rendering,
                ViewType.PanelSchedule,
                ViewType.Internal,
                ViewType.DraftingView
            };

            FilteredElementCollector viewCollector = new FilteredElementCollector(this.Doc);

            viewCollector.OfClass(typeof(View));

            foreach (Element viewElement in viewCollector)
            {
                View view = viewElement as View;
                if (allowedViewTypes.Contains(view.ViewType))
                {
                    if (!viewTypes.Contains(view.ViewType))
                    {
                        viewTypes.Add(view.ViewType);
                    }
                    views.Add(view);
                }
            }
            SelectForm   selectForm   = new SelectForm(viewTypes, views);
            DialogResult dialogResult = selectForm.ShowDialog();

            switch (dialogResult)
            {
            case DialogResult.OK:
                this.SelectedViews = selectForm.GetCheckedViews();
                break;

            case DialogResult.Cancel:
                this.SelectedViews = new List <View>()
                {
                    this.Doc.ActiveView
                };
                break;
            }
        }
Example #9
0
 public REXView(REXView argRV)
 {
     this.ifChecked   = argRV.ifChecked;
     this.ifVisible   = argRV.ifVisible;
     this.Tag         = argRV.Tag;
     this.ifView      = argRV.ifView;
     this.Name        = argRV.Name;
     this.ViewElement = argRV.ViewElement;
 }
Example #10
0
 public XvForm(Document dbdoc, UIDocument uidoc, Autodesk.Revit.DB.View uiview)
 {
     InitializeComponent();
     this.dbdoc   = dbdoc;
     this.uidoc   = uidoc;
     view         = uiview;
     uiApp        = uidoc.Application;
     txtJson.Text = uidoc.Document.Title;
 }
Example #11
0
        private void OnRevitViewChanged(View newView)
        {
            var handler = RevitViewChanged;

            if (handler != null)
            {
                handler(newView);
            }
        }
Example #12
0
        private void btnMostrar_Click(object sender, EventArgs e)
        {
            int elemento = Convert.ToInt32(dataGridView1.CurrentRow.Cells["INTEGER_VALUE"].Value);

            revitDB.RevisionCloud nuvem = uiDoc.GetElement(new revitDB.ElementId(elemento)) as revitDB.RevisionCloud;
            revitDB.View          view  = uiDoc.GetElement(nuvem.OwnerViewId) as revitDB.View;
            uiApp.ActiveUIDocument.ActiveView = view;
            uiApp.ActiveUIDocument.ShowElements(nuvem);
        }
Example #13
0
        //判断文本的起始坐标位置---此处为---自定义墙身---的处理方式
        //判断字体是否旋转---通过对创建文本选项中的Rotation属性进行修改

        public TextNote AddrotateText_customWall(Document doc, Element ele, Autodesk.Revit.DB.View eleView, string field)
        {
            //获取实例元素的xyz定位坐标
            FamilyInstance fi = ele as FamilyInstance;
            XYZ            facingOrientation = fi.FacingOrientation;
            XYZ            min          = ele.get_BoundingBox(eleView).Min;
            XYZ            max          = ele.get_BoundingBox(eleView).Max;
            XYZ            middleEleXYZ = (min + max) / 2;
            //求距离
            double distance_X = Math.Abs(min.X - max.X) / 2.0;
            double distance_Y = Math.Abs(min.Y - max.Y) / 2.0;

            //声明变量
            TextNote tnt;
            double   x;
            double   y;
            double   z;
            XYZ      textLoc;
            double   angle;

            //条件判断
            if (facingOrientation.Y == 1 || facingOrientation.Y == -1)//横向
            {
                angle = 0;
                //文字左上角坐标点定位
                x       = middleEleXYZ.X;
                y       = middleEleXYZ.Y;
                z       = middleEleXYZ.Z;
                textLoc = new XYZ(x, y, z);
                tnt     = AddNewTextNote(doc, eleView.Id, textLoc, field, angle);
                return(tnt);
            }
            else if (facingOrientation.X == 1 || facingOrientation.X == -1)//纵向
            {
                angle = Math.PI / 2;
                //文字左上角坐标点定位

                x       = middleEleXYZ.X;
                y       = middleEleXYZ.Y;
                z       = middleEleXYZ.Z;
                textLoc = new XYZ(x, y, z);
                tnt     = AddNewTextNote(doc, eleView.Id, textLoc, field, angle);
                return(tnt);
            }
            else
            {
                angle = 0;
                //文字左上角坐标点定位

                x       = middleEleXYZ.X;
                y       = middleEleXYZ.Y;
                z       = middleEleXYZ.Z;
                textLoc = new XYZ(x, y, z);
                tnt     = AddNewTextNote(doc, eleView.Id, textLoc, field, angle);
                return(tnt);
            }
        }
Example #14
0
        /// <summary>
        /// Resets the rotation of a view by setting its orientation to true north and then back to project north.
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        private static bool ResetRotation(Autodesk.Revit.DB.View view)
        {
            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
            view.get_Parameter(BuiltInParameter.PLAN_VIEW_NORTH).Set(1);
            view.get_Parameter(BuiltInParameter.PLAN_VIEW_NORTH).Set(0);
            TransactionManager.Instance.TransactionTaskDone();

            return(true);
        }
Example #15
0
        //创建文字事务组
        public void transCreatMoveTNT(Document doc, ElementId eleId, Autodesk.Revit.DB.View view, ICollection <ElementId> lst_eles_4_ids, ICollection <ElementId> collector_DoWn_ids, ICollection <ElementId> lst_collector_glasswall_ids)
        {
            TextNote textNote = null;

            using (Transaction addCommandSingleMark = new Transaction(doc)) //事务结束
            {
                addCommandSingleMark.Start("addCommandSingleMark");         //开启事务
                if (lst_eles_4_ids.Contains(eleId))                         //元素id属于自定义门窗
                {
                    Element ele   = doc.GetElement(eleId);
                    string  field = ele.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString();
                    if (field == null || field == "")
                    {
                        return;
                    }
                    textNote = AddrotateText_customWall(doc, ele, view, field); //将自定义墙身元素标记值转化为文字注释
                }
                else if (collector_DoWn_ids.Contains(eleId))                    //元素id属于内建门窗
                {
                    Element ele   = doc.GetElement(eleId);
                    string  field = ele.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString();
                    if (field == null || field == "")
                    {
                        return;
                    }
                    textNote = AddrotateText(doc, ele, view, field);  //将元素标记值转化为文字注释
                }
                else if (lst_collector_glasswall_ids.Contains(eleId)) //元素id属于幕墙
                {
                    Element ele   = doc.GetElement(eleId);
                    string  field = ele.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString();
                    //玻璃幕墙注释文字需要单独处理
                    if (field == null || field == "")
                    {
                        return;
                    }
                    textNote = AddrotateText_glassWall(doc, ele, view, field);//将玻璃幕墙元素的注释元素标记值转化为文字注释
                }
                else
                {
                    ShowTaskDialog("Revit2020-操作失败提示", "所选元素不属于门、窗、玻璃幕墙类型");
                    throw new NotImplementedException("所选元素不属于门窗类型");
                }
                addCommandSingleMark.Commit();//提交事务
            }
            //启动两个事务是因为,只要元素存在Revit文档中后,才可以继续对其操作
            if (textNote != null)
            {
                using (Transaction moveTextNote = new Transaction(doc)) //事务结束
                {
                    moveTextNote.Start("moveTextNote");                 //开启事务
                    MoveTextNote(textNote, view);                       //移动文字至中心位置
                    moveTextNote.Commit();                              //提交事务
                }
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;

            View   acView   = uidoc.ActiveView;
            UIView acuiview = uidoc.ActiveUiview();


            Transaction ts = new Transaction(doc, "******");

            try
            {
                ts.Start();

                //重要的属性: category类别, location, levelId标高, group组, id, uniqueId唯一id
                //重要的方法: get.materials,


                //通过点选,选择一个元素
                Reference pickedEleReference = sel.PickObject(ObjectType.Element);
                //通过引用,选取到选中的元素.  (群里大佬指点, 用reference是正常方法)
                Element elem = doc.GetElement(pickedEleReference);

                FamilyInstance familyInstance = elem as FamilyInstance;


                string family       = familyInstance.Category.Name;
                string familySymbol = familyInstance.Name;


                string info = "选择的元素属性如下";

                info += "\n\t" + "族名称是:" + family;

                info += "\n\t" + "族类型名称是:" + familySymbol;


                TaskDialog.Show("提示", info);


                ts.Commit();
            }

            catch (Exception)
            {
                if (ts.GetStatus() == TransactionStatus.Started)
                {
                    ts.RollBack();
                }
            }

            return(Result.Succeeded);
        }
        private SpatialFieldManager SetSpatialFieldManager(Autodesk.Revit.DB.View view, out int index)
        {
            SpatialFieldManager sfm = null;

            index = -1;
            try
            {
                sfm = SpatialFieldManager.GetSpatialFieldManager(view);

                using (Transaction trans = new Transaction(m_doc))
                {
                    trans.Start("Create Spatial Manager");
                    try
                    {
                        if (null == sfm)
                        {
                            sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1);
                            List <string> names        = new List <string>();
                            List <string> descriptions = new List <string>();
                            names.Add("Visibility Index");
                            descriptions.Add("0: area with no views, 1: area with views");
                            sfm.SetMeasurementNames(names);
                            sfm.SetMeasurementDescriptions(descriptions);
                        }

                        IList <int> resultIndices = sfm.GetRegisteredResults();

                        foreach (int i in resultIndices)
                        {
                            AnalysisResultSchema resultSchema = sfm.GetResultSchema(i);
                            if (resultSchema.Name == "View Analysis")
                            {
                                index = i;
                            }
                        }
                        if (index == -1)
                        {
                            AnalysisResultSchema resultSchema = new AnalysisResultSchema("View Analysis", "Calculating area with views");
                            index = sfm.RegisterResult(resultSchema);
                        }

                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        string message = ex.Message;
                        trans.RollBack();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Set Spatial Field Manager.\n" + ex.Message, "Set Spatial Field Manager", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(sfm);
        }
Example #18
0
        /// <summary>
        /// Init Tag element
        /// </summary>
        /// <param name="view"></param>
        /// <param name="host"></param>
        /// <param name="orientation"></param>
        /// <param name="mode"></param>
        /// <param name="addLeader"></param>
        /// <param name="vector"></param>
        private void Init(
            Autodesk.Revit.DB.View view,
            Autodesk.Revit.DB.Element host,
            Autodesk.Revit.DB.TagOrientation orientation,
            Autodesk.Revit.DB.TagMode mode,
            bool addLeader,
            Autodesk.Revit.DB.XYZ vector)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.EnsureInTransaction(document);

            var tagElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.IndependentTag>(document);

            var hostElementIds   = new List <ElementId>();
            var linkedElementIds = new List <ElementId>();

            if (tagElem != null)
            {
                hostElementIds.AddRange(tagElem.GetTaggedElementIds().Select(x => x.HostElementId));
                linkedElementIds.AddRange(tagElem.GetTaggedElementIds().Select(x => x.LinkedElementId));
            }

            // create a new tag if the existing tag is null or its host view is not the selected one
            // or the host is neither set a host or linked element.
            if (tagElem == null || view.Id != tagElem.OwnerViewId ||
                (!hostElementIds.Contains(host.Id) && !linkedElementIds.Contains(host.Id)))
            {
                tagElem = IndependentTag.Create(Document, view.Id, new Autodesk.Revit.DB.Reference(host), addLeader, mode, orientation, vector);
            }
            else
            {
                // apply properties
                if (tagElem.TagOrientation != orientation)
                {
                    tagElem.TagOrientation = orientation;
                }

                if (tagElem.HasLeader != addLeader)
                {
                    tagElem.HasLeader = addLeader;
                }

                if (!tagElem.TagHeadPosition.Equals(vector))
                {
                    tagElem.TagHeadPosition = vector;
                }
            }

            double rotation = (orientation == TagOrientation.Horizontal) ? 0 : 90;

            InternalSetType(tagElem.TagText, tagElem.TagHeadPosition, rotation);
            InternalSetElement(tagElem);

            TransactionManager.Instance.TransactionTaskDone();
            ElementBinder.SetElementForTrace(this.InternalElement);
        }
        // Submits the geometry for rendering.
        public void RenderScene(Autodesk.Revit.DB.View view, DisplayStyle displayStyle)
        {
            try
            {
                // Populate geometry buffers if they are not initialized or need updating.
                if (UpdateAll ||
                    m_nonTransparentFaceBufferStorage == null || m_nonTransparentFaceBufferStorage.needsUpdate(displayStyle) ||
                    m_transparentFaceBufferStorage == null || m_transparentFaceBufferStorage.needsUpdate(displayStyle) ||
                    m_edgeBufferStorage == null || m_edgeBufferStorage.needsUpdate(displayStyle))
                {
                    Options         options  = new Options();
                    GeometryElement geomElem = m_element.get_Geometry(options);

                    CreateBufferStorageForElement(geomElem, displayStyle);
                }

                // Submit a subset of the geometry for drawing. Determine what geometry should be submitted based on
                // the type of the rendering pass (opaque or transparent) and DisplayStyle (wireframe or shaded).

                // If the server is requested to submit transparent geometry, DrawContext().IsTransparentPass()
                // will indicate that the current rendering pass is for transparent objects.
                RenderingPassBufferStorage faceBufferStorage = DrawContext.IsTransparentPass() ? m_transparentFaceBufferStorage : m_nonTransparentFaceBufferStorage;

                // Conditionally submit triangle primitives (for non-wireframe views).
                if (displayStyle != DisplayStyle.Wireframe &&
                    faceBufferStorage.PrimitiveCount > 0)
                {
                    DrawContext.FlushBuffer(faceBufferStorage.VertexBuffer,
                                            faceBufferStorage.VertexBufferCount,
                                            faceBufferStorage.IndexBuffer,
                                            faceBufferStorage.IndexBufferCount,
                                            faceBufferStorage.VertexFormat,
                                            faceBufferStorage.EffectInstance, PrimitiveType.TriangleList, 0,
                                            faceBufferStorage.PrimitiveCount);
                }

                // Conditionally submit line segment primitives.
                if (displayStyle != DisplayStyle.Shading &&
                    m_edgeBufferStorage.PrimitiveCount > 0)
                {
                    DrawContext.FlushBuffer(m_edgeBufferStorage.VertexBuffer,
                                            m_edgeBufferStorage.VertexBufferCount,
                                            m_edgeBufferStorage.IndexBuffer,
                                            m_edgeBufferStorage.IndexBufferCount,
                                            m_edgeBufferStorage.VertexFormat,
                                            m_edgeBufferStorage.EffectInstance, PrimitiveType.LineList, 0,
                                            m_edgeBufferStorage.PrimitiveCount);
                }

                UpdateAll = false;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Example #20
0
        //视图复制
        public void viewduplicate_duplicate(UIApplication uiapp, ViewDuplicateOption Duplicate)
        {
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            Autodesk.Revit.DB.View activeView = doc.ActiveView;

            //让用户选择哪几个PLOT视图需要复制生成
            if (CMD.selectedViewNames.Count() <= 0)//判断是否选择不存在INTF视图的PLOT视图
            {
                TaskDialog.Show("Revit2020", "未选择任何视图");
            }
            else
            {
                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start("view_duplicate");
                    if (CMD.changStr == "_actiView")
                    {
                        Autodesk.Revit.DB.View destinationView = CreateDependentCopy(doc, activeView.Id, Duplicate);//复制PLOT视图为指定字段视图
                    }
                    else if (CMD.changStr == "_work")
                    {
                        ICollection <ElementId> selPlotViewIds = getSelPlotViewIds(doc, CMD.selectedViewNames, CMD.workViewIds);
                        foreach (ElementId eleId in selPlotViewIds)
                        {
                            Autodesk.Revit.DB.View destinationView = CreateDependentCopy(doc, eleId, Duplicate);//复制PLOT视图为指定字段视图
                        }
                    }
                    else if (CMD.changStr == "_plot")
                    {
                        ICollection <ElementId> selPlotViewIds = getSelPlotViewIds(doc, CMD.selectedViewNames, CMD.plotViewIds);
                        foreach (ElementId eleId in selPlotViewIds)
                        {
                            Autodesk.Revit.DB.View destinationView = CreateDependentCopy(doc, eleId, Duplicate);//复制PLOT视图为指定字段视图
                        }
                    }
                    else if (CMD.changStr == "_INTF")
                    {
                        ICollection <ElementId> selPlotViewIds = getSelPlotViewIds(doc, CMD.selectedViewNames, CMD.INTFViewIds);
                        foreach (ElementId eleId in selPlotViewIds)
                        {
                            Autodesk.Revit.DB.View destinationView = CreateDependentCopy(doc, eleId, Duplicate);//复制PLOT视图为指定字段视图
                        }
                    }
                    trans.Commit();
                }
                showSuccess(" !");

                CMD.selectedViewNames = new List <string>(); //避免选项会被累计的问题
                CMD.selectedViewNames = new List <string>(); //避免选项会被累计的问题

                //所有视图列表需要设置尾部更新-窗口列表更新
                CMD.GetViews_All(doc);//获取视图列表合辑
            }
        }//main
Example #21
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public virtual Result Execute(ExternalCommandData commandData
                                      , ref string message, ElementSet elements)
        {
            try
            {
                Document document           = commandData.Application.ActiveUIDocument.Document;
                Autodesk.Revit.DB.View view = commandData.Application.ActiveUIDocument.ActiveView;
                datumDic.Clear();
                ICollection <ElementId> datums = commandData.Application.ActiveUIDocument.Selection.GetElementIds();
                if (datums == null || datums.Count == 0)
                {
                    return(Result.Cancelled);
                }

                foreach (ElementId datumRef in datums)
                {
                    DatumPlane datum = document.GetElement(datumRef) as DatumPlane;
                    if (!datumDic.Keys.Contains(datum.Name))
                    {
                        datumDic.Add(datum.Name, datum);
                    }
                }

                //// Show UI
                using (AlignmentSetting settingForm = new AlignmentSetting())
                {
                    if (settingForm.ShowDialog() == DialogResult.OK)
                    {
                        DatumPlane selectedDatum = datumDic[settingForm.datumList.SelectedItem.ToString()];
                        Curve      baseCurve     = selectedDatum.GetCurvesInView(DatumExtentType.ViewSpecific, view).ElementAt(0);
                        Line       baseLine      = baseCurve as Line;
                        XYZ        baseDirect    = baseLine.Direction;

                        using (Transaction tran = new Transaction(document, "DatumAlignment"))
                        {
                            tran.Start();

                            foreach (DatumPlane datum in datumDic.Values)
                            {
                                Curve curve    = datum.GetCurvesInView(datum.GetDatumExtentTypeInView(DatumEnds.End0, view), view).ElementAt(0);
                                XYZ   direct   = (curve as Line).Direction;
                                Curve newCurve = CalculateCurve(curve, baseLine, baseDirect);
                                datum.SetCurveInView(datum.GetDatumExtentTypeInView(DatumEnds.End0, view), view, newCurve);
                            }
                            tran.Commit();
                        }
                    }
                }
                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Example #22
0
 /// <summary>
 /// Tag by Element
 /// </summary>
 /// <param name="view"></param>
 /// <param name="host"></param>
 /// <param name="orientation"></param>
 /// <param name="mode"></param>
 /// <param name="addLeader"></param>
 /// <param name="point"></param>
 private Tag(
     Autodesk.Revit.DB.View view,
     Autodesk.Revit.DB.Element host,
     Autodesk.Revit.DB.TagOrientation orientation,
     Autodesk.Revit.DB.TagMode mode,
     bool addLeader,
     Autodesk.Revit.DB.XYZ vector)
 {
     SafeInit(() => Init(view, host, orientation, mode, addLeader, vector));
 }
Example #23
0
        /// <summary>
        /// Wraps a Revit view template for use in Dynamo.  Returns null if the view is not a template.
        /// </summary>
        /// <param name="viewTemplate">A Autodesk.Revit.DB.View view template.  Returns null if the view is not a template.</param>
        /// <returns name="View Template">A view template.</returns>
        public static ViewTemplate Wrap(revitView viewTemplate)
        {
            ViewTemplate vt = null;

            if (viewTemplate.IsTemplate)
            {
                vt = new ViewTemplate(viewTemplate);
            }
            return(vt);
        }
Example #24
0
        private void comboBoxImportView_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedViewName = this.comboBoxImportView.SelectedItem.ToString();

            Autodesk.Revit.DB.View selectedView = GetViewByName(selectedViewName);
            if (selectedView != null)
            {
                uiapp.ActiveUIDocument.ActiveView = selectedView;
            }
        }
Example #25
0
        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elems)
        {
            Result result;

            try
            {
                Snoop.CollectorExts.CollectorExt.m_app = cmdData.Application;
                UIDocument revitDoc = cmdData.Application.ActiveUIDocument;
                Document   dbdoc    = revitDoc.Document;
                Snoop.CollectorExts.CollectorExt.m_activeDoc = dbdoc; // TBD: see note in CollectorExt.cs
                Autodesk.Revit.DB.View view = dbdoc.ActiveView;

                //ElementSet ss = cmdData.Application.ActiveUIDocument.Selection.Elements; // 2015, jeremy: 'Selection.Selection.Elements' is obsolete: 'This property is deprecated in Revit 2015. Use GetElementIds() and SetElementIds instead.'
                //if (ss.Size == 0)
                //{
                //  FilteredElementCollector collector = new FilteredElementCollector( revitDoc.Document, view.Id );
                //  collector.WhereElementIsNotElementType();
                //  FilteredElementIterator i = collector.GetElementIterator();
                //  i.Reset();
                //  ElementSet ss1 = cmdData.Application.Application.Create.NewElementSet();
                //  while( i.MoveNext() )
                //  {
                //    Element e = i.Current as Element;
                //    ss1.Insert( e );
                //  }
                //  ss = ss1;
                //}

                ICollection <ElementId> ids = cmdData.Application.ActiveUIDocument.Selection.GetElementIds(); // 2016, jeremy
                if (0 == ids.Count)
                {
                    FilteredElementCollector collector
                        = new FilteredElementCollector(revitDoc.Document, view.Id)
                          .WhereElementIsNotElementType();
                    ids = collector.ToElementIds();
                }

                //ICollection<Element> elements
                //  = new List<Element>( ids.Select<ElementId,Element>(
                //    id => dbdoc.GetElement( id ) ) );

                Snoop.Forms.Objects form = new Snoop.Forms.Objects(dbdoc, ids);
                ActiveDoc.UIApp = cmdData.Application;
                form.ShowDialog();

                result = Result.Succeeded;
            }
            catch (System.Exception e)
            {
                msg    = e.Message;
                result = Result.Failed;
            }

            return(result);
        }
Example #26
0
        }// excute

        //以下为各种method---------------------------------分割线---------------------------------

        //获取视图列表名称
        public IList<string> getIcollecionNames(Document doc, ICollection<ElementId> eleIds)
        {
            IList<string> strs = new List<string>();
            foreach (ElementId vieId in eleIds)
            {
                Autodesk.Revit.DB.View vie = doc.GetElement(vieId) as Autodesk.Revit.DB.View;
                string vieName = vie.Name;
                strs.Add(vieName);
            }
            return strs;
        }
Example #27
0
        public ViewsOICBRequest(UIApplication uiApp, String text)
        {
            UIDocument uidoc = uiApp.ActiveUIDocument;
            //Collect all viewers and viewports
            var viewerCollector   = new FilteredElementCollector(uidoc.Document).OfCategory(BuiltInCategory.OST_Viewers);
            var viewportCollector = new FilteredElementCollector(uidoc.Document).OfClass(typeof(Viewport)).ToElements();
            //Generate an OverrideGraphicsSetting
            OverrideGraphicSettings orgs = new OverrideGraphicSettings();

            //Use the solid line pattern
            orgs.SetProjectionLinePatternId(LinePatternElement.GetSolidPatternId());
            //Set the line weight to the property value
            orgs.SetProjectionLineWeight(Properties.Settings.Default.RevitOverrideInteriorCropWeight);

            //Start a new transaction and cycle through the viewports
            Transaction t1 = new Transaction(uidoc.Document, "OverrideInteriorElevationCrops");

            t1.Start();
            foreach (Viewport viewport in viewportCollector)
            {
                //Get the view associated with the viewport, then get its ViewType
                ElementId viewId   = viewport.ViewId;
                Element   viewElem = uidoc.Document.GetElement(viewId);
                Autodesk.Revit.DB.View viewElemView = viewElem as Autodesk.Revit.DB.View;
                ElementId typeId          = viewElem.GetTypeId();
                Element   typeElement     = uidoc.Document.GetElement(typeId);
                string    typeElementName = typeElement.Name.ToString();
                //If the view is a derivative of a section, its type is an Elevation, and its type name contains Interior, continue
                if (viewElem.GetType().ToString() == "Autodesk.Revit.DB.ViewSection" && viewElemView.ViewType == ViewType.Elevation && typeElementName.Contains("Interior"))
                {
                    //Get the viewers and cycle through them
                    var viewers = new FilteredElementCollector(uidoc.Document).OfCategory(BuiltInCategory.OST_Viewers);
                    foreach (Element viewer in viewerCollector)
                    {
                        //If the viewer's name is equal to the view's name, continue
                        if (viewer.Name.ToString() == viewElem.Name.ToString())
                        {
                            //Override the view element's viewer with the settings
                            Autodesk.Revit.DB.View viewToOverride = viewElem as Autodesk.Revit.DB.View;
                            viewToOverride.SetElementOverrides(viewer.Id, orgs);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    continue;
                }
            }
            t1.Commit();
        }
Example #28
0
 public void StoreOriginalVisibility(Autodesk.Revit.DB.View view)
 {
     foreach (Category category in doc.Settings.Categories)
     {
         if (category.get_AllowsVisibilityControl(view))
         {
             bool visiblity = category.get_Visible(view);
             visDictionary.Add(category, visiblity);
         }
     }
 }
Example #29
0
        //中点
        public static XYZ BoundingBoxPOINT(FamilyInstance fi, Autodesk.Revit.DB.View view)
        {
            if (fi.get_BoundingBox(view) == null)
            {
                return(null);
            }

            XYZ xyzpositionPoint = new XYZ(fi.get_BoundingBox(view).Min.X + (fi.get_BoundingBox(view).Max.X - fi.get_BoundingBox(view).Min.X) / 2.0, fi.get_BoundingBox(view).Min.Y + (fi.get_BoundingBox(view).Max.Y - fi.get_BoundingBox(view).Min.Y) / 2.0, fi.get_BoundingBox(view).Min.Z + (fi.get_BoundingBox(view).Max.Z - fi.get_BoundingBox(view).Min.Z) / 2.0);

            return(xyzpositionPoint);
        }
Example #30
0
        public static Element Wrap(Autodesk.Revit.DB.View view, bool isRevitOwned)
        {
            switch (view.ViewType)
            {
            case ViewType.Legend:
                return(Legend.FromExisting(view, isRevitOwned));

            default:
                return(UnknownElement.FromExisting(view, true));
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="revit">
        /// The application object for the active instance of Autodesk Revit.
        /// </param>
        public DataGenerator(RevitApplication revitApp, Document doc, RevitView view)
        {
            //initialize the member variable
            if (revitApp != null)
            {
                m_RevitApp = revitApp;
                m_ActiveDocument = doc;
                m_ActiveView = view;

                m_ViewOptions = m_RevitApp.Create.NewGeometryOptions();
                m_ViewOptions.View = m_ActiveView;
            }
        }
Example #32
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                               ref string message,
                                               ElementSet elements)
        {
            try
            {
                m_activeView = commandData.Application.ActiveUIDocument.Document.ActiveView;

                //// Create a new instance of class DataManager
                RoofsManager.CS.RoofsManager roofsManager = new RoofsManager.CS.RoofsManager(commandData);
                LevelConverter.SetStandardValues(roofsManager.Levels);

                // Create a form to create and edit a roof.
                DialogResult result = System.Windows.Forms.DialogResult.None;
                while (result == DialogResult.None || result == DialogResult.Retry)
                {
                    if (result == DialogResult.Retry)
                    {
                        roofsManager.WindowSelect();
                    }

                    using (RoofForms.CS.RoofForm mainForm = new RoofForms.CS.RoofForm(roofsManager))
                    {
                        result = mainForm.ShowDialog();
                    }
                }

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    return Autodesk.Revit.UI.Result.Succeeded;
                }
                else
                {
                    return Autodesk.Revit.UI.Result.Cancelled;
                }
            }
            catch (Exception ex)
            {
                // If there are something wrong, give error information and return failed
                message = ex.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
        }
Example #33
0
        private void UpdateDocument(Document document)
        {
            activeDoc = document;
            activeView = document.ActiveView;
            allElements = new FilteredElementCollector(activeDoc)
                .WhereElementIsNotElementType()
                .WhereElementIsViewIndependent();

            structuralElements = from elements in allElements
                                 where elements.Category != null && elements.Category.HasMaterialQuantities
                                 select elements;
        }
Example #34
0
 /// <summary>
 /// The method is used to create common class variables in this class 
 /// </summary>
 private void CreateCommon()
 {
     //create common
     m_dimensionCreator = new CreateDimension(m_application.Application, m_document);
     m_extrusionCreator = new CreateExtrusion(m_application.Application, m_document);
     m_rightView = Utility.GetViewByName("Right", m_application, m_document);
 }
Example #35
0
        private Autodesk.Revit.DB.View m_view; // current view

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of TagBeamData. 
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command</param>
        public TagBeamData(ExternalCommandData commandData)
        {
            //Get beams selected
               m_revitDoc = commandData.Application.ActiveUIDocument;
               m_docCreator = m_revitDoc.Document.Create;
               m_view = m_revitDoc.Document.ActiveView;

               SelElementSet elementSet = m_revitDoc.Selection.Elements;
            ElementSetIterator itor = elementSet.ForwardIterator();
            while (itor.MoveNext())
            {
                FamilyInstance familyInstance = itor.Current as FamilyInstance;
                if ((familyInstance != null) && (familyInstance.StructuralType == Autodesk.Revit.DB.Structure.StructuralType.Beam))
                {
                    m_beamList.Add(familyInstance);
                }
            }
            if (m_beamList.Count < 1)
            {
                throw new ApplicationException("there is no beam selected");
            }

            //Get the family symbols of tag in this document.
            FilteredElementCollector collector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document);
            IList<Element> elements = collector.OfClass(typeof(Family)).ToElements();

            foreach (Family family in elements)
            {
               if (family != null && family.Symbols != null)
               {
                  FamilySymbolSetIterator it = family.Symbols.ForwardIterator();
                  while (it.MoveNext())
                  {
                     try
                     {
                        FamilySymbol tagSymbol = it.Current as FamilySymbol;
                        if (tagSymbol != null)
                        {
                           switch (tagSymbol.Category.Name)
                           {
                              case "Structural Framing Tags":
                                 m_categoryTagTypes.Add(new FamilySymbolWrapper(tagSymbol));
                                 continue;
                              case "Material Tags":
                                 m_materialTagTypes.Add(new FamilySymbolWrapper(tagSymbol));
                                 continue;
                              case "Multi-Category Tags":
                                 m_multiCategoryTagTypes.Add(new FamilySymbolWrapper(tagSymbol));
                                 continue;
                              default:
                                 continue;
                           }
                        }
                     }
                     catch (Exception)
                     {
                        continue;
                     }
                  }
               }
            }
        }
Example #36
0
 private void UpdateActiveView(ViewActivatedEventArgs e)
 {
     if (e.Status == EventStatus.Succeeded)
         activeView = e.CurrentActiveView;
 }