Exemplo n.º 1
0
        /// <summary>
        /// Gets a representative view generated by the level.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="viewType">The view type.</param>
        /// <param name="level">The level.</param>
        /// <returns>A view associate with the level.</returns>
        /// <remarks>This function will return the first view it finds with a bottom range set to an offset of the generating level.
        /// If no such view is found, but a view based on the generating level exists, that view will be returned.</remarks>
        public static View FindViewByLevel(Document document, ViewType viewType, Level level)
        {
            View possibleView = null;

            ElementFilter            elementFilter = new ElementClassFilter(typeof(View));
            FilteredElementCollector collector     = new FilteredElementCollector(document);

            collector.WherePasses(elementFilter);
            foreach (View view in collector)
            {
                if (view.ViewType != viewType)
                {
                    continue;
                }
                if (view.GenLevel != null && view.GenLevel.Id == level.Id)
                {
                    PlanViewRange viewRange         = (view as ViewPlan).GetViewRange();
                    ElementId     bottomClipPlaneId = viewRange.GetLevelId(PlanViewPlane.BottomClipPlane);
                    if (bottomClipPlaneId != level.Id)
                    {
                        possibleView = view;
                        continue;
                    }
                    return(view);
                }
            }
            return(possibleView);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 为选中房间创建专门的floorPlan和ceilingPlan
        /// Ctrate a New FloorPlan and CeilingPlan for the selected selRoom
        /// </summary>
        /// <param name="viewOffseet"></param>
        /// <param name="view3d"></param>
        public void CreateNewViewPlan(double viewOffseet, View3D view3d)
        {
            //过滤所有的ViewFamilyType
            var classFilter = new ElementClassFilter(typeof(ViewFamilyType));
            FilteredElementCollector collector = new FilteredElementCollector(DocSet.doc);

            collector = collector.WherePasses(classFilter);
            ViewPlan view = null;

            using (Transaction tran = new Transaction(DocSet.doc))
            {
                foreach (ViewFamilyType viewFamilyType in collector)
                {
                    //当类型为FloorPlan或者CeilingPlan时创建同类型视图
                    if (viewFamilyType.ViewFamily == ViewFamily.FloorPlan ||
                        viewFamilyType.ViewFamily == ViewFamily.CeilingPlan)
                    {
                        tran.Start("Creat view of type " + viewFamilyType.ViewFamily);
                        //创建视图时需要 视图类型ID 相关标高ID
                        view = ViewPlan.Create(DocSet.doc, viewFamilyType.Id, DocSet.selRoom.LevelId);

                        //TaskDialog.Show("CreatLevelView", "A new level's view has been Created");

                        view.Name = DocSet.selRoom.Name;//生成平面的名称

                        view.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION).Set(1);
                        view.AreAnalyticalModelCategoriesHidden = false;
                        view.PartsVisibility = PartsVisibility.ShowPartsAndOriginal;
                        view.Scale           = 50;
                        view.CropBoxActive   = true;
                        view.CropBoxVisible  = true;

                        string viewName = "PLAN ";
                        view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name);

                        if (viewFamilyType.ViewFamily == ViewFamily.CeilingPlan)
                        {
                            PlanViewRange range = view.GetViewRange();
                            range.SetLevelId(PlanViewPlane.TopClipPlane, DocSet.selRoom.UpperLimit.Id);
                            range.SetLevelId(PlanViewPlane.ViewDepthPlane, DocSet.selRoom.UpperLimit.Id);
                            range.SetLevelId(PlanViewPlane.CutPlane, DocSet.selRoom.LevelId);
                            range.SetLevelId(PlanViewPlane.BottomClipPlane, DocSet.selRoom.LevelId);
                            range.SetOffset(PlanViewPlane.CutPlane, 7.874);
                            range.SetOffset(PlanViewPlane.BottomClipPlane, 7.874);
                            view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name);
                            view.SetViewRange(range);

                            viewName = "RCP ";
                            view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name + " - RCP");
                        }
                        viewName     += _SoANumber + "_" + DocSet.selRoom.Level.Name;
                        view.ViewName = viewName;
                        tran.Commit();
                        ChangeViewFitRoom(view, tran, viewOffseet);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static ViewBox getPlanViewBox(ViewPlan vp)
        {
            System.Diagnostics.Debug.WriteLine("ViewPlan: " + vp.Id + " Outline: " + vp.Outline.Min.U + "," + vp.Outline.Min.V + " to " + vp.Outline.Max.U + "," + vp.Outline.Max.V);
            System.Diagnostics.Debug.WriteLine("ViewPlan Scale: " + vp.Scale);


            XYZ tmp1 = vp.Origin.Add(new XYZ(vp.Outline.Min.U * (double)vp.Scale, vp.Outline.Min.V * (double)vp.Scale, 0));
            XYZ tmp2 = vp.Origin.Add(new XYZ(vp.Outline.Max.U * (double)vp.Scale, vp.Outline.Max.V * (double)vp.Scale, 0));

            // double check the cropbox, if it is smaller...
            if (vp.CropBoxActive)
            {
                tmp1 = vp.CropBox.Min;
                tmp2 = vp.CropBox.Max;
            }

            // in a plan view, we will work with the cropbox (if it is set?)
            ViewBox box = new ViewBox()
            {
                P1 = tmp1, P2 = tmp2
            };

            // now reset by the level and the viewdepth
            if (vp.GenLevel != null)
            {
                PlanViewRange pvr   = vp.GetViewRange();
                ElementId     topId = pvr.GetLevelId(PlanViewPlane.TopClipPlane);

                ElementId bottomId = pvr.GetLevelId(PlanViewPlane.ViewDepthPlane);
                if (bottomId.IntegerValue == -4)
                {
                    bottomId = pvr.GetLevelId(PlanViewPlane.BottomClipPlane);
                }
                if (bottomId.IntegerValue == -4)
                {
                    bottomId = pvr.GetLevelId(PlanViewPlane.UnderlayBottom);
                }

                if (topId != ElementId.InvalidElementId)
                {
                    Level top = vp.Document.GetElement(topId) as Level;
                    box.P2 = new XYZ(box.P2.X, box.P2.Y, top.Elevation + pvr.GetOffset(PlanViewPlane.TopClipPlane));
                }
                if (bottomId != ElementId.InvalidElementId)
                {
                    Level bottom = vp.Document.GetElement(bottomId) as Level;
                    box.P1 = new XYZ(box.P1.X, box.P1.Y, bottom.Elevation + pvr.GetOffset(PlanViewPlane.ViewDepthPlane));
                }
            }

            // set the transform
            box.TransformationMatrix = Transform.Identity;
            box.DirectionUp          = vp.UpDirection;
            box.EyePosition          = vp.Origin.Add(vp.ViewDirection.Multiply(10));
            box.DirectionView        = vp.ViewDirection.Negate();
            return(box);
        }
Exemplo n.º 4
0
        public bool CopyGridExtent(Document doc, View sourceView, Reference selectedGrid)
        {
            DatumPlane selectedDatum = doc.GetElement(selectedGrid) as DatumPlane;
            Curve      baseCurve     = selectedDatum.GetCurvesInView(DatumExtentType.ViewSpecific, sourceView).ElementAt(0);
            XYZ        basePoint0    = baseCurve.GetEndPoint(0);
            XYZ        basePoint1    = baseCurve.GetEndPoint(1);
            Line       baseLine      = baseCurve as Line;

            Curve newCurve   = selectedDatum.GetCurvesInView(DatumExtentType.ViewSpecific, doc.ActiveView).ElementAt(0);
            XYZ   newCurvePt = newCurve.GetEndPoint(0);
            Line  newLine    = newCurve as Line;

            //sb.AppendLine("Source view end0 " + baseLine.GetEndPoint(0).X.ToString() + " - " + baseLine.GetEndPoint(0).Y.ToString() + " - " + baseLine.GetEndPoint(0).Z.ToString());
            //sb.AppendLine("Active view end0 " + newLine.GetEndPoint(0).X.ToString() + " - " + newLine.GetEndPoint(0).Y.ToString() + " - " + newLine.GetEndPoint(0).Z.ToString());

            //sb.AppendLine("Source view end1 " + baseLine.GetEndPoint(1).X.ToString() + " - " + baseLine.GetEndPoint(1).Y.ToString() + " - " + baseLine.GetEndPoint(1).Z.ToString());
            //sb.AppendLine("Active view end1 " + newLine.GetEndPoint(1).X.ToString() + " - " + newLine.GetEndPoint(1).Y.ToString() + " - " + newLine.GetEndPoint(1).Z.ToString());

            ISet <ElementId> par = new List <ElementId>() as ISet <ElementId>;

            View destination = doc.ActiveView;

            ViewPlan vp = destination as ViewPlan;

            PlanViewRange pvr = vp.GetViewRange();

            Level l = vp.GenLevel;

            double zLevel = pvr.GetOffset(PlanViewPlane.CutPlane) + l.Elevation; //Z point for Datum curve

            //Curve projectedCurve = Line.CreateBound(new XYZ(basePoint0.X, basePoint0.Y, newCurvePt.Z), new XYZ(basePoint1.X, basePoint1.Y, newCurvePt.Z));

            Curve projectedCurve = Line.CreateBound(new XYZ(basePoint0.X, basePoint0.Y, zLevel), new XYZ(basePoint1.X, basePoint1.Y, zLevel));

            //par.Add(destination);

            //TaskDialog.Show("r", par.Count.ToString());


            Grid g = doc.GetElement(selectedGrid) as Grid;

            //g.SetDatumExtentType(DatumEnds.End1, destination, DatumExtentType.ViewSpecific);

            g.SetCurveInView(g.GetDatumExtentTypeInView(DatumEnds.End1, sourceView), destination, projectedCurve);

            //TaskDialog.Show("r", sb.ToString());
            //g.PropagateToViews(source, par);

            return(true);
        }
Exemplo n.º 5
0
        Stream(ArrayList data, PlanViewRange plvr)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PlanViewRange)));

            data.Add(new Snoop.Data.ElementId("Level Id for CutPlane", plvr.GetLevelId(PlanViewPlane.CutPlane), m_app.ActiveUIDocument.Document));
            data.Add(new Snoop.Data.Double("Offset assiciated with CutPlane", plvr.GetOffset(PlanViewPlane.CutPlane)));
            data.Add(new Snoop.Data.ElementId("Level Id for Bottom Clib Plane", plvr.GetLevelId(PlanViewPlane.BottomClipPlane), m_app.ActiveUIDocument.Document));
            data.Add(new Snoop.Data.Double("Offset assiciated with Bottom Clib Plane", plvr.GetOffset(PlanViewPlane.BottomClipPlane)));
            data.Add(new Snoop.Data.ElementId("Level Id for Top Clib Plane", plvr.GetLevelId(PlanViewPlane.TopClipPlane), m_app.ActiveUIDocument.Document));
            data.Add(new Snoop.Data.Double("Offset assiciated with Top Clib Plane", plvr.GetOffset(PlanViewPlane.TopClipPlane)));
            data.Add(new Snoop.Data.ElementId("Level Id for Underlay Bottom", plvr.GetLevelId(PlanViewPlane.UnderlayBottom), m_app.ActiveUIDocument.Document));
            data.Add(new Snoop.Data.Double("Offset assiciated with Underlay Bottom Plane", plvr.GetOffset(PlanViewPlane.UnderlayBottom)));
            data.Add(new Snoop.Data.ElementId("Level Id for View Depth Plane", plvr.GetLevelId(PlanViewPlane.ViewDepthPlane), m_app.ActiveUIDocument.Document));
            data.Add(new Snoop.Data.Double("Offset assiciated with View Depth Plane", plvr.GetOffset(PlanViewPlane.ViewDepthPlane)));
        }
Exemplo n.º 6
0
        public static Outline Outline(this ViewPlan viewPlan, Transform transform = null)
        {
            if (viewPlan == null)
            {
                return(null);
            }

            PlanViewRange planViewRange = viewPlan.GetViewRange();

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

            Document document = viewPlan.Document;

            ElementId elementId_Level = null;

            elementId_Level = planViewRange.GetLevelId(PlanViewPlane.TopClipPlane);
            Level  level_TopClipPlane  = document.GetElement(elementId_Level) as Level;
            double offset_TopClipPlane = planViewRange.GetOffset(PlanViewPlane.TopClipPlane);

            elementId_Level = planViewRange.GetLevelId(PlanViewPlane.BottomClipPlane);
            Level  level_BottomClipPlane  = document.GetElement(elementId_Level) as Level;
            double offset_BottomClipPlane = planViewRange.GetOffset(PlanViewPlane.BottomClipPlane);

            BoundingBoxXYZ boundingBoxXYZ = viewPlan.CropBox;

            boundingBoxXYZ.Min = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Min.Y, level_BottomClipPlane.Elevation + offset_BottomClipPlane);
            boundingBoxXYZ.Max = new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Max.Y, level_TopClipPlane.Elevation + offset_TopClipPlane);

            if (transform != null)
            {
                boundingBoxXYZ.Transform = transform.Inverse;
            }

            return(new Outline(boundingBoxXYZ.Min, boundingBoxXYZ.Max));
        }
Exemplo n.º 7
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication           uiapp        = commandData.Application;
            UIDocument              uidoc        = uiapp.ActiveUIDocument;
            Application             app          = uiapp.Application;
            Document                doc          = uidoc.Document;
            Selection               SelectedObjs = uidoc.Selection;
            ICollection <ElementId> ids          = uidoc.Selection.GetElementIds();
            ViewPlan                viewPlan     = uidoc.ActiveView as ViewPlan;
            PlanViewRange           VR           = null;

            foreach (ElementId eid in ids)
            {
                Element elem = doc.GetElement(eid);
                if (elem.Category.Name == "Views")
                {
                    ViewPlan selectPlan = elem as ViewPlan;
                    VR = selectPlan.GetViewRange();
                    TaskDialog.Show("Copying VR from", selectPlan.Title);
                }
            }
            if (VR == null)
            {
                TaskDialog.Show("error", "error");
            }
            using (Transaction t = new Transaction(doc, "Set View Range"))
            {
                t.Start();
                viewPlan.SetViewRange(VR);
                t.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 8
0
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false); // why did someone else send us the message?
                return;
            }

            // see if it is a type we are responsible for
            Color color = e.ObjToSnoop as Color;

            if (color != null)
            {
                Stream(snoopCollector.Data(), color);
                return;
            }

            LayoutRule layoutRule = e.ObjToSnoop as LayoutRule;

            if (layoutRule != null)
            {
                Stream(snoopCollector.Data(), layoutRule);
                return;
            }

            FormatOptions formatOptions = e.ObjToSnoop as FormatOptions;

            if (formatOptions != null)
            {
                Stream(snoopCollector.Data(), formatOptions);
                return;
            }

            CurtainGrid curtainGrid = e.ObjToSnoop as CurtainGrid;

            if (curtainGrid != null)
            {
                Stream(snoopCollector.Data(), curtainGrid);
                return;
            }

            CurtainCell curtainCell = e.ObjToSnoop as CurtainCell;

            if (curtainCell != null)
            {
                Stream(snoopCollector.Data(), curtainCell);
                return;
            }

            RebarHostData rebarHostData = e.ObjToSnoop as RebarHostData;

            if (rebarHostData != null)
            {
                Stream(snoopCollector.Data(), rebarHostData);
                return;
            }

            Leader leader = e.ObjToSnoop as Leader;

            if (leader != null)
            {
                Stream(snoopCollector.Data(), leader);
                return;
            }

            AreaVolumeSettings areaSettings = e.ObjToSnoop as AreaVolumeSettings;

            if (areaSettings != null)
            {
                Stream(snoopCollector.Data(), areaSettings);
                return;
            }

            ViewSheetSetting viewSheetSetting = e.ObjToSnoop as ViewSheetSetting;

            if (viewSheetSetting != null)
            {
                Stream(snoopCollector.Data(), viewSheetSetting);
                return;
            }

            Autodesk.Revit.UI.Events.DialogBoxData dlgBoxData = e.ObjToSnoop as Autodesk.Revit.UI.Events.DialogBoxData;
            if (dlgBoxData != null)
            {
                Stream(snoopCollector.Data(), dlgBoxData);
                return;
            }

            Construction construct = e.ObjToSnoop as Construction;

            if (construct != null)
            {
                Stream(snoopCollector.Data(), construct);
                return;
            }

            FamilyElementVisibility famElemVisib = e.ObjToSnoop as FamilyElementVisibility;

            if (famElemVisib != null)
            {
                Stream(snoopCollector.Data(), famElemVisib);
                return;
            }

            FamilyManager famManager = e.ObjToSnoop as FamilyManager;

            if (famManager != null)
            {
                Stream(snoopCollector.Data(), famManager);
                return;
            }

            FamilyParameter famParam = e.ObjToSnoop as FamilyParameter;

            if (famParam != null)
            {
                Stream(snoopCollector.Data(), famParam);
                return;
            }

            FamilyType famType = e.ObjToSnoop as FamilyType;

            if (famType != null)
            {
                Stream(snoopCollector.Data(), famType);
                return;
            }

            MEPSpaceConstruction mepSpaceConstuct = e.ObjToSnoop as MEPSpaceConstruction;

            if (mepSpaceConstuct != null)
            {
                Stream(snoopCollector.Data(), mepSpaceConstuct);
                return;
            }

            BuildingSiteExportOptions bldSiteExpOptions = e.ObjToSnoop as BuildingSiteExportOptions;

            if (bldSiteExpOptions != null)
            {
                Stream(snoopCollector.Data(), bldSiteExpOptions);
                return;
            }

            DGNExportOptions dgnExpOptions = e.ObjToSnoop as DGNExportOptions;

            if (dgnExpOptions != null)
            {
                Stream(snoopCollector.Data(), dgnExpOptions);
                return;
            }

            DWFExportOptions dwfExpOptions = e.ObjToSnoop as DWFExportOptions;

            if (dwfExpOptions != null)
            {
                Stream(snoopCollector.Data(), dwfExpOptions);
                return;
            }

            DWGExportOptions dwgExpOptions = e.ObjToSnoop as DWGExportOptions;

            if (dwgExpOptions != null)
            {
                Stream(snoopCollector.Data(), dwgExpOptions);
                return;
            }

            DWGImportOptions dwgImpOptions = e.ObjToSnoop as DWGImportOptions;

            if (dwgImpOptions != null)
            {
                Stream(snoopCollector.Data(), dwgImpOptions);
                return;
            }

            FBXExportOptions fbxExpOptions = e.ObjToSnoop as FBXExportOptions;

            if (fbxExpOptions != null)
            {
                Stream(snoopCollector.Data(), fbxExpOptions);
                return;
            }

            TrussMemberInfo trussInfo = e.ObjToSnoop as TrussMemberInfo;

            if (trussInfo != null)
            {
                Stream(snoopCollector.Data(), trussInfo);
                return;
            }

            VertexIndexPair vertIndPair = e.ObjToSnoop as VertexIndexPair;

            if (vertIndPair != null)
            {
                Stream(snoopCollector.Data(), vertIndPair);
                return;
            }

            PointElementReference ptElemRef = e.ObjToSnoop as PointElementReference;

            if (ptElemRef != null)
            {
                Stream(snoopCollector.Data(), ptElemRef);
                return;
            }

            Autodesk.Revit.DB.Architecture.BoundarySegment boundSeg = e.ObjToSnoop as Autodesk.Revit.DB.Architecture.BoundarySegment;
            if (boundSeg != null)
            {
                Stream(snoopCollector.Data(), boundSeg);
                return;
            }

            PointLocationOnCurve ptLocOnCurve = e.ObjToSnoop as PointLocationOnCurve;

            if (ptLocOnCurve != null)
            {
                Stream(snoopCollector.Data(), ptLocOnCurve);
                return;
            }

            Entity entity = e.ObjToSnoop as Entity;

            if (entity != null)
            {
                Stream(snoopCollector.Data(), entity);
                return;
            }

            Field field = e.ObjToSnoop as Field;

            if (field != null)
            {
                Stream(snoopCollector.Data(), field);
                return;
            }

            ExtensibleStorageField storeagefield = e.ObjToSnoop as ExtensibleStorageField;

            if (storeagefield != null)
            {
                Stream(snoopCollector.Data(), storeagefield);
                return;
            }

            IList <Autodesk.Revit.DB.BoundarySegment> boundSegs = e.ObjToSnoop as
                                                                  IList <Autodesk.Revit.DB.BoundarySegment>;

            if (boundSegs != null)
            {
                Stream(snoopCollector.Data(), boundSegs);
                return;
            }

            if (e.ObjToSnoop is KeyValuePair <String, String> )
            {
                KeyValuePair <String, String> stringspair = (KeyValuePair <String, String>)e.ObjToSnoop;
                Stream(snoopCollector.Data(), stringspair);
                return;
            }

            Schema schema = e.ObjToSnoop as Schema;

            if (schema != null)
            {
                Stream(snoopCollector.Data(), schema);
                return;
            }

            ElementId elemId = e.ObjToSnoop as ElementId;

            if (elemId != null)
            {
                Stream(snoopCollector.Data(), elemId);
                return;
            }

            PlanViewRange plvr = e.ObjToSnoop as PlanViewRange;

            if (plvr != null)
            {
                Stream(snoopCollector.Data(), plvr);
                return;
            }
            //TF
            RebarConstraintsManager rbcm = e.ObjToSnoop as RebarConstraintsManager;

            if (rbcm != null)
            {
                Stream(snoopCollector.Data(), rbcm);
                return;
            }

            RebarConstrainedHandle rbch = e.ObjToSnoop as RebarConstrainedHandle;

            if (rbch != null)
            {
                Stream(snoopCollector.Data(), rbch);
                return;
            }

            RebarConstraint rbc = e.ObjToSnoop as RebarConstraint;

            if (rbc != null)
            {
                Stream(snoopCollector.Data(), rbc);
                return;
            }

            //TFEND

            if (Utils.IsSupportedType(e.ObjToSnoop) && e.ObjToSnoop != null)
            {
                Utils.StreamWithReflection(snoopCollector.Data(), e.ObjToSnoop.GetType(), e.ObjToSnoop);
            }
        }
Exemplo n.º 9
0
 public PlanViewRangeGetOffset(string label, PlanViewRange planViewRange) : base(label)
 {
     _planViewRange = planViewRange;
 }
Exemplo n.º 10
0
      Stream(ArrayList data, PlanViewRange plvr)
      {
          data.Add(new Snoop.Data.ClassSeparator(typeof(PlanViewRange)));

          data.Add(new Snoop.Data.ElementId("Level Id for CutPlane", plvr.GetLevelId(PlanViewPlane.CutPlane), m_app.ActiveUIDocument.Document));
          data.Add(new Snoop.Data.Double("Offset assiciated with CutPlane", plvr.GetOffset(PlanViewPlane.CutPlane)));
          data.Add(new Snoop.Data.ElementId("Level Id for Bottom Clib Plane", plvr.GetLevelId(PlanViewPlane.BottomClipPlane), m_app.ActiveUIDocument.Document));
          data.Add(new Snoop.Data.Double("Offset assiciated with Bottom Clib Plane", plvr.GetOffset(PlanViewPlane.BottomClipPlane)));
          data.Add(new Snoop.Data.ElementId("Level Id for Top Clib Plane", plvr.GetLevelId(PlanViewPlane.TopClipPlane), m_app.ActiveUIDocument.Document));
          data.Add(new Snoop.Data.Double("Offset assiciated with Top Clib Plane", plvr.GetOffset(PlanViewPlane.TopClipPlane)));
          data.Add(new Snoop.Data.ElementId("Level Id for Underlay Bottom", plvr.GetLevelId(PlanViewPlane.UnderlayBottom), m_app.ActiveUIDocument.Document));
          data.Add(new Snoop.Data.Double("Offset assiciated with Underlay Bottom Plane", plvr.GetOffset(PlanViewPlane.UnderlayBottom)));
          data.Add(new Snoop.Data.ElementId("Level Id for View Depth Plane", plvr.GetLevelId(PlanViewPlane.ViewDepthPlane), m_app.ActiveUIDocument.Document));
          data.Add(new Snoop.Data.Double("Offset assiciated with View Depth Plane", plvr.GetOffset(PlanViewPlane.ViewDepthPlane)));
      }
        private void settingCompleted()
        {
            if (!double.TryParse(this.ObstacleSetting.Text, out this.MinimumHeight))
            {
                MessageBox.Show("Enter a valid number for the 'Minimum Height of Visual Obstacles'!\n(Larger than zero)");
                return;
            }
            else if (this.MinimumHeight < 0)
            {
                MessageBox.Show("Enter a valid number for the 'Minimum Height of Visual Obstacles'!\n(Larger than zero)");
                return;
            }
            if (!double.TryParse(this.CurveApproximationLength_.Text, out this.CurveApproximationLength))
            {
                MessageBox.Show("Enter a valid number for 'Curve Approximation Length'!");
                return;
            }
            if (!double.TryParse(this.MinimumCurveLength_.Text, out this.MinimumCurveLength))
            {
                MessageBox.Show("Enter a valid number for 'Minimum Curve Approximation Length'!\n(This length should be smaller than curve approximation length and larger than zero)");
                return;
            }
            else if (this.MinimumCurveLength >= this.CurveApproximationLength || this.MinimumCurveLength <= 0f)
            {
                MessageBox.Show("Enter a valid number for 'Minimum Curve Approximation Length'!\n(This length should be smaller than curve approximation length and larger than zero)");
                return;
            }
            if (this.FloorPlan == null)
            {
                MessageBox.Show("Select a floor plan to continue!");
                return;
            }
            using (Transaction t = new Transaction(this.uidoc.Document, "Update View Range"))
            {
                t.Start();
                try
                {
                    PlanViewRange viewRange          = this.FloorPlan.GetViewRange();
                    ElementId     topClipPlane       = viewRange.GetLevelId(PlanViewPlane.TopClipPlane);
                    double        revitMinimumHeight = UnitConversion.Convert(this.MinimumHeight, this.unitType, Length_Unit_Types.FEET);


                    if (viewRange.GetOffset(PlanViewPlane.TopClipPlane) < revitMinimumHeight)
                    {
                        viewRange.SetOffset(PlanViewPlane.CutPlane, revitMinimumHeight);
                        viewRange.SetOffset(PlanViewPlane.TopClipPlane, revitMinimumHeight);
                    }
                    else
                    {
                        viewRange.SetOffset(PlanViewPlane.CutPlane, revitMinimumHeight);
                    }
                    this.FloorPlan.SetViewRange(viewRange);
                }
                catch (Exception ex)
                {
                    t.Commit();
                    MessageBox.Show(ex.Report());
                }
                t.Commit();
            }
            uidoc.ActiveView    = this.FloorPlan;
            this.floorPlanNames = null;
            this.DialogResult   = true;
            this.Close();
        }
Exemplo n.º 12
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            if (!(doc.ActiveView is ViewPlan viewPlan))
            {
                TaskDialog.Show("Please select Plan view", "Select Plan view to change it's View Range");
                return(Result.Succeeded);
            }
            PlanViewRange viewRange  = viewPlan.GetViewRange();
            double        CCut       = viewRange.GetOffset(PlanViewPlane.CutPlane);
            double        CTop       = viewRange.GetOffset(PlanViewPlane.TopClipPlane);
            RibbonPanel   inputpanel = null;
            ComboBox      inputbox   = null;

            foreach (RibbonPanel panel in uiapp.GetRibbonPanels("Exp. Add-Ins"))
            {
                if (panel.Name == "View Tools")
                {
                    inputpanel = panel;
                }
            }
            foreach (RibbonItem item in inputpanel.GetItems())
            {
                if (item.Name == "ShiftRange")
                {
                    inputbox = (ComboBox)item;
                }
            }
            List <Double> vrOpts = new List <Double> {
                StoreExp.vrOpt1, StoreExp.vrOpt2, StoreExp.vrOpt3,
                StoreExp.vrOpt4, StoreExp.vrOpt5, StoreExp.vrOpt6
            };
            double mod = vrOpts[Int32.Parse(inputbox.Current.Name)];

            if (viewPlan.ViewType != ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.CutPlane, CCut + mod);
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, CCut + mod);
            }
            if (viewPlan.ViewType == ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, CTop + mod);
                viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, CTop + mod);
            }
            using (Transaction t = new Transaction(doc, "Set View Range"))
            {
                try
                {
                    t.Start();
                    viewPlan.SetViewRange(viewRange);
                    t.Commit();
                }
                catch
                { TaskDialog.Show("Error", "Cannot shift ViewRange this way."); }
            }
            return(Result.Succeeded);
        }
Exemplo n.º 13
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            if (!(doc.ActiveView is ViewPlan viewPlan))
            {
                TaskDialog.Show("Please select Plan view", "Select Plan view to change it's View Range");
                return(Result.Succeeded);
            }
            Level  level    = viewPlan.GenLevel;
            View3D view3d   = null;
            string source3d = StoreExp.ThreeDview;

            if (source3d == "Same Name")
            {
                source3d = viewPlan.Name;
            }
            try
            {
                view3d = (from v in new FilteredElementCollector(doc).OfClass(typeof(View3D)).Cast <View3D>() where v.Name == source3d select v).First();
            }
            catch
            {
                TaskDialog.Show("Please rename 3D view or Select in Options", "Rename 3D view to match:" + Environment.NewLine + "'" + viewPlan.Name +
                                "'" + Environment.NewLine + " or, Select source 3D view in Options");
                return(Result.Succeeded);
            }
            BoundingBoxXYZ bbox        = view3d.GetSectionBox();
            Transform      transform   = bbox.Transform;
            double         bboxOriginZ = transform.Origin.Z;
            double         minZ        = bbox.Min.Z + bboxOriginZ;
            double         maxZ        = bbox.Max.Z + bboxOriginZ;

            PlanViewRange viewRange = viewPlan.GetViewRange();

            viewRange.SetLevelId(PlanViewPlane.TopClipPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.CutPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.BottomClipPlane, level.Id);
            viewRange.SetLevelId(PlanViewPlane.ViewDepthPlane, level.Id);
            if (viewPlan.ViewType == ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.CutPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.BottomClipPlane, minZ - level.Elevation);
            }
            if (viewPlan.ViewType != ViewType.CeilingPlan)
            {
                viewRange.SetOffset(PlanViewPlane.CutPlane, maxZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.BottomClipPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.ViewDepthPlane, minZ - level.Elevation);
                viewRange.SetOffset(PlanViewPlane.TopClipPlane, maxZ - level.Elevation);
            }
            using (Transaction t = new Transaction(doc))
            {
                t.Start("Set View Range");
                viewPlan.SetViewRange(viewRange);
                t.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 14
0
 public PlanViewRangeGetLevelIdData(string label, PlanViewRange planViewRange, Document doc) : base(label)
 {
     _planViewRange = planViewRange;
     _document      = doc;
 }
Exemplo n.º 15
0
        public static void getCurrentView(Document doc, out ViewItem viewItem)
        {
            viewItem = new ViewItem();
            double topPoint;
            double cutPoint;
            double bottPoint;
            double depthPoint;
            double topToCut;
            double cutToBott;
            double bottToDepth;
            double totalRange;

            double originElevOff;
            double originElev = 0;

            originPosition(doc, out originElev);
            originElevOff = 0 - originElev;

            ViewPlan      vP        = doc.ActiveView as ViewPlan;
            PlanViewRange viewRange = vP.GetViewRange();
            Level         hostLevel = doc.GetElement(vP.LevelId) as Level;

            #region view range info
            //Get top clip data
            Level  topClipLevel  = doc.GetElement(viewRange.GetLevelId(PlanViewPlane.TopClipPlane) as ElementId) as Level;
            double topClipElev   = topClipLevel.Elevation + originElevOff;
            double topClipOffset = viewRange.GetOffset(PlanViewPlane.TopClipPlane);
            topPoint = topClipElev + topClipOffset;

            //Get cut plane
            Level  cutLevel     = doc.GetElement(viewRange.GetLevelId(PlanViewPlane.CutPlane) as ElementId) as Level;
            double cutElevation = cutLevel.Elevation + originElevOff;
            double cutOffset    = viewRange.GetOffset(PlanViewPlane.CutPlane);
            cutPoint = cutElevation + cutOffset;

            //Get bottom clip data
            Level  bottClipLevel  = doc.GetElement(viewRange.GetLevelId(PlanViewPlane.BottomClipPlane) as ElementId) as Level;
            double bottClipElev   = bottClipLevel.Elevation + originElevOff;
            double bottClipOffset = viewRange.GetOffset(PlanViewPlane.BottomClipPlane);
            bottPoint = bottClipElev + bottClipOffset;

            //Get depth clip data
            Level  depthClipLevel  = doc.GetElement(viewRange.GetLevelId(PlanViewPlane.ViewDepthPlane) as ElementId) as Level;
            double depthClipElev   = bottClipLevel.Elevation + originElevOff;
            double depthClipOffset = viewRange.GetOffset(PlanViewPlane.ViewDepthPlane);
            depthPoint = depthClipElev + depthClipOffset;

            topToCut    = topPoint - cutPoint;
            cutToBott   = cutPoint - bottPoint;
            bottToDepth = bottPoint - depthPoint;
            totalRange  = topPoint - depthPoint;
            #endregion

            #region add data to ViewItem.
            viewItem.id              = vP.Id;
            viewItem.name            = vP.Name;
            viewItem.hostLevel       = hostLevel;
            viewItem.topClipLevel    = topClipLevel;
            viewItem.topClipOffset   = topClipOffset;
            viewItem.cutLevel        = cutLevel;
            viewItem.cutOffset       = cutOffset;
            viewItem.bottClipLevel   = bottClipLevel;
            viewItem.bottClipOffset  = bottClipOffset;
            viewItem.depthCLipLevel  = depthClipLevel;
            viewItem.depthClipOffset = depthClipOffset;
            viewItem.topToCut        = topToCut;
            viewItem.cutToBott       = cutToBott;
            viewItem.bottToDepth     = bottToDepth;
            viewItem.totalRange      = totalRange;
            #endregion
        }
Exemplo n.º 16
0
        public RoomsCDRTRequest(UIApplication uiApp, String text)
        {
            RVTDocument doc = uiApp.ActiveUIDocument.Document;

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

            //Verify the active view is a floor plan view
            if (activeView.ViewType != ViewType.FloorPlan)
            {
                MessageBox.Show("Please run from a demo floor plan view.");
            }
            else
            {
                //Get the current phase of the active view
                Phase     currentPhase    = doc.GetElement(activeView.get_Parameter(BuiltInParameter.VIEW_PHASE).AsElementId()) as Phase;
                ElementId currentPhaseId  = currentPhase.Id;
                ElementId previousPhaseId = null;
                //Collect the phases of the document
                PhaseArray phaseArray = doc.Phases;

                //Cycle through the phases in the project to get the previous phase
                for (int i = 0; i < phaseArray.Size; i++)
                {
                    //By finding the index of the current phase, which must not be the first phase, the phase in the previous index can be obtained
                    if (phaseArray.get_Item(i).ToString() == currentPhase.ToString() && i != 0)
                    {
                        previousPhaseId = phaseArray.get_Item(i - 1).Id;
                    }
                    i++;
                }

                //Collect the rooms in the current view where their phase is equal to the active view's phase
                List <Room>   currentVisibleRooms       = new FilteredElementCollector(doc, activeView.Id).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements().Cast <Room>().Where(r => r.get_Parameter(BuiltInParameter.ROOM_PHASE).AsElementId() == currentPhaseId).ToList();
                List <string> currentVisibleRoomNumbers = new List <string>();

                //Get the list of currently visible rooms' numbers
                foreach (Room room in currentVisibleRooms)
                {
                    currentVisibleRoomNumbers.Add(room.Number);
                }

                //Only continue if the previous phase was found
                if (previousPhaseId != null)
                {
                    List <Room> previousRoomsToTag = new List <Room>();
                    Outline     outline            = null;
                    try
                    {
                        //This portion will require a new outline from the view's bounding box
                        BoundingBoxXYZ viewBBox = activeView.get_BoundingBox(activeView);
                        //Get the active view as a plan view so the view range can be obtained for the height of the outline
                        ViewPlan      viewPlan      = activeView as ViewPlan;
                        PlanViewRange planViewRange = viewPlan.GetViewRange();
                        double        minX          = viewBBox.Min.X;
                        double        minY          = viewBBox.Min.Y;
                        //The bottom Z point of the outline will be the elevation of the view's level plus the bottom offset
                        double minZ = activeView.GenLevel.Elevation + planViewRange.GetOffset(PlanViewPlane.BottomClipPlane);
                        double maxX = viewBBox.Max.X;
                        double maxY = viewBBox.Max.Y;
                        //The top Z point of the outline will be the elevation of the view's level plust the top offset
                        double maxZ = activeView.GenLevel.Elevation + planViewRange.GetOffset(PlanViewPlane.TopClipPlane);
                        //Generate the minimum and maximum points
                        XYZ minPoint = new XYZ(minX, minY, minZ);
                        XYZ maxPoint = new XYZ(maxX, maxY, maxZ);
                        //Make a new outline from the points
                        outline = new Outline(minPoint, maxPoint);

                        //Establish a new bounding box filter using the outline
                        BoundingBoxIntersectsFilter bboxFilter = new BoundingBoxIntersectsFilter(outline);
                        //The previous rooms will be those that pass the bounding box intersects filter (their bounding boxes intersect the view bounding box) and they belong to the previous phase
                        var previousNonVisibleRooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().WherePasses(bboxFilter).ToElements().Where(r => r.get_Parameter(BuiltInParameter.ROOM_PHASE).AsElementId() == previousPhaseId);
                        foreach (Element elem in previousNonVisibleRooms)
                        {
                            //Get the rooms and their numbers
                            Room   room       = elem as Room;
                            string roomNumber = room.Number;
                            //Verify the room number is not in the current view's list of visible room numbers
                            if (!currentVisibleRoomNumbers.Contains(roomNumber))
                            {
                                previousRoomsToTag.Add(room);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        //If something went wrong in getting the demoed rooms, report an error
                        MessageBox.Show(e.ToString(), "Getting Demo Rooms Error");
                    }

                    //Start a transaction to make the new tags
                    Transaction t = new Transaction(doc, "Create Demo Room Tags");
                    t.Start();
                    FamilySymbol symbol = null;
                    //Create a new instance of the load options
                    IFamilyLoadOptions loadOptions = new RVTFamilyLoadOptions();

                    try
                    {
                        //Get the versioned symbol family to use as a "tag"
                        string roomTagSymbolPath = RVTOperations.GetVersionedFamilyFilePath(uiApp, Properties.Settings.Default.RevitRoomTagSymbol);
                        try
                        {
                            //Load only the particular type of tag
                            doc.LoadFamilySymbol(roomTagSymbolPath, Properties.Settings.Default.RevitRoomTagSymbolType, loadOptions, out FamilySymbol symb);
                            symbol = symb;
                        }
                        catch
                        {
                            //If it could not be loaded, let the user know it needs added to the family for the script to work
                            MessageBox.Show(String.Format("The family type {0} could not be found in {1}. Please add it for this tool to work.",
                                                          Properties.Settings.Default.RevitRoomTagSymbolType,
                                                          Properties.Settings.Default.RevitRoomTagSymbol));
                        }
                    }
                    catch
                    {
                        //If the family itself could not be loaded, let the user know where the family was expected to be found.
                        MessageBox.Show(String.Format("The {0} family could not be found at {1}. Please place the {0} family in the {1} folder for this tool to work.",
                                                      Path.GetFileNameWithoutExtension(Properties.Settings.Default.RevitRoomTagSymbol),
                                                      Path.GetDirectoryName(Properties.Settings.Default.RevitRoomTagSymbol)));
                    }

                    try
                    {
                        //Verify there are rooms to tag and the family symbol to use is not null
                        if (previousRoomsToTag.Count > 0 && symbol != null)
                        {
                            //Cycle through the demoed rooms
                            foreach (Room demoRoom in previousRoomsToTag)
                            {
                                //Get the location point of the demo room as a point
                                LocationPoint roomLocationPoint = demoRoom.Location as LocationPoint;
                                //Make a new symbol at the locatoin
                                FamilyInstance newSymbol = doc.Create.NewFamilyInstance(roomLocationPoint.Point, symbol, activeView);
                                //Update the parameter values for room Name and Number in the symbol
                                newSymbol.GetParameters("Name").First().Set(demoRoom.get_Parameter(BuiltInParameter.ROOM_NAME).AsString());
                                newSymbol.GetParameters("Number").First().Set(demoRoom.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString());
                            }
                        }
                        t.Commit();
                    }
                    catch (Exception f)
                    {
                        //Well, crap, the symbol didn't place in the view
                        MessageBox.Show(f.ToString(), "Placement Error");
                        t.RollBack();
                    }
                }
                else
                {
                    //If the previous phase was null, then the current phase of the view is the first phase, so let the user know
                    MessageBox.Show("The currently viewed phase is the earliest phase in the project. Please verify you are viewing a new construction phase, but showing previous and demoed elements.");
                }
            }
        }