void UpdateReferencingSheet(
            ViewSection selectedViewport)
        {
            BuiltInParameter bip
                = BuiltInParameter.VIEW_DISCIPLINE;

            Parameter discipline
                = selectedViewport.get_Parameter(bip);

            int disciplineNo = discipline.AsInteger();

            Document doc = selectedViewport.Document;

            Transaction transaction = new Transaction(doc);

            if (TransactionStatus.Started
                == transaction.Start("Updating the model"))
            {
                //switch( disciplineNo )
                //{
                //  case 1:
                //    discipline.Set( 2 );
                //    break;
                //  default:
                //    discipline.Set( 1 );
                //    break;
                //}
                //discipline.Set( disciplineNo );

                discipline.Set(1 == disciplineNo ? 2 : 1);
                transaction.Commit();
            }
        }
        void UpdateReferencingSheet(
            ViewSection selectedViewport)
        {
            BuiltInParameter bip
            = BuiltInParameter.VIEW_DISCIPLINE;

              Parameter discipline
            = selectedViewport.get_Parameter( bip );

              int disciplineNo = discipline.AsInteger();

              Document doc = selectedViewport.Document;

              Transaction transaction = new Transaction( doc );

              if( TransactionStatus.Started
            == transaction.Start( "Updating the model" ) )
              {
            //switch( disciplineNo )
            //{
            //  case 1:
            //    discipline.Set( 2 );
            //    break;
            //  default:
            //    discipline.Set( 1 );
            //    break;
            //}
            //discipline.Set( disciplineNo );

            discipline.Set( 1 == disciplineNo ? 2 : 1 );
            transaction.Commit();
              }
        }
Exemple #3
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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                m_project = commandData.Application.ActiveUIDocument;

                // Get the selected element and store it to data member.
                if (!GetSelectedElement())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a BoundingBoxXYZ instance which used in NewViewSection() method
                if (!GenerateBoundingBoxXYZ())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a section view.
                Transaction transaction = new Transaction(m_project.Document, "CreateSectionView");
                transaction.Start();
                //ViewSection section = m_project.Document.Create.NewViewSection(m_box);
                ElementId       DetailViewId = new ElementId(-1);
                IList <Element> elems        = new FilteredElementCollector(m_project.Document).OfClass(typeof(ViewFamilyType)).ToElements();
                foreach (Element e in elems)
                {
                    ViewFamilyType v = e as ViewFamilyType;

                    if (v != null && v.ViewFamily == ViewFamily.Detail)
                    {
                        DetailViewId = e.Id;
                        break;
                    }
                }
                ViewSection section = ViewSection.CreateDetail(m_project.Document, DetailViewId, m_box);
                if (null == section)
                {
                    message = "Can't create the ViewSection.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Modify some parameters to make it look better.
                section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2);
                transaction.Commit();

                // If everything goes right, give successful information and return succeeded.
                TaskDialog.Show("Revit", "Create view section succeeded.");
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Exemple #4
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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                m_project = commandData.Application.ActiveUIDocument;

                // Get the selected element and store it to data member.
                if (!GetSelectedElement())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a BoundingBoxXYZ instance which used in NewViewSection() method
                if (!GenerateBoundingBoxXYZ())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a section view.
                Transaction transaction = new Transaction(m_project.Document, "CreateSectionView");
                transaction.Start();
                ViewSection section = m_project.Document.Create.NewViewSection(m_box);
                if (null == section)
                {
                    message = "Can't create the ViewSection.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Modify some parameters to make it look better.
                section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2);
                transaction.Commit();

                // If everything goes right, give successful information and return succeeded.
                MessageBox.Show("Create view section succeeded.", "Revit");
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
        /// <summary>
        /// 获取剖面视图在平面视图上的范围框的点的序列, Z = minZ
        /// </summary>
        /// <param name="viewSection"></param>
        /// <returns></returns>
        public static List <XYZ> GetViewSectionPlanePointsLoop(this ViewSection viewSection)
        {
            BoundingBoxXYZ bbox        = viewSection.CropBox;
            Double         farCropDist = viewSection.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).AsDouble();

            var direct = viewSection.ViewDirection.Normalize();
            var minPt  = bbox.Transform.OfPoint(bbox.Min);
            var maxPt  = bbox.Transform.OfPoint(bbox.Max);

            var p1 = new XYZ(minPt.X, minPt.Y, minPt.Z);
            var p3 = new XYZ(maxPt.X, maxPt.Y, minPt.Z);
            var p2 = p3 - direct * farCropDist;
            var p4 = p1 + direct * farCropDist;

            return(new List <XYZ> {
                p1, p2, p3, p4
            });
        }
        public void PlaceElevations(Document doc, XYZ center, ViewPlan intElevPlan)
        {
            //current scale set to 1/8"
            ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, FindFamilyTypeId(doc), center, 96);
            Parameter       p      = intElevPlan.get_Parameter(BuiltInParameter.VIEW_PHASE);

            marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId());

            for (int markerindex = 0; markerindex < marker.MaximumViewCount; markerindex++)
            {
                Debug($"Writing marker at {markerindex}");
                if (marker.IsAvailableIndex(markerindex))
                {
                    Debug($"Writing market to plan {intElevPlan.Name}");
                    ViewSection intElev = marker.CreateElevation(doc, intElevPlan.Id, markerindex);
                    intElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId());
                }
            }
        }
        /// <summary>
        /// Places interior elevation makers and inter elevation views for the room
        /// </summary>
        /// <param name="doc">UI Document</param>
        /// <param name="center">coordinate where marker will be placed</param>
        /// <param name="intElevPlan">the plan in which the marker will be visible</param>
        /// <param name="selectedFamilyType">user selected view family type</param>
        /// <param name="scale">user selected scale for interior elevations</param>
        /// <returns>a list of the interior elevations created</returns>
        public List <ViewSection> PlaceElevations(Document doc, XYZ center, ViewPlan intElevPlan, ElementId selectedFamilyType, int scale, out ElevationMarker marker)
        {
            marker = ElevationMarker.CreateElevationMarker(doc, selectedFamilyType, center, scale);
            Parameter p = intElevPlan.get_Parameter(BuiltInParameter.VIEW_PHASE);

            marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId());
            List <ViewSection> intElevList = new List <ViewSection>();

            for (int markerindex = 0; markerindex < marker.MaximumViewCount; markerindex++)
            {
                if (marker.IsAvailableIndex(markerindex))
                {
                    ViewSection intElev = marker.CreateElevation(doc, intElevPlan.Id, markerindex);
                    intElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId());
                    intElevList.Add(intElev);
                }
            }

            return(intElevList);
        }
        public ElevationMarker PlaceMarker(Document doc, XYZ elevMarkerPosition, Wall w)
        {
            ViewPlan  plan = DocumentElevPlanViews(doc, w);
            Parameter p    = plan.get_Parameter(BuiltInParameter.VIEW_PHASE);
            //ElementId[] toHide = new ElementId[1];

            //change scale to user input
            ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, FindFamilyTypeId(doc), elevMarkerPosition, 96);

            marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId());
            //toHide[0] = marker.Id;

            //move this back into the if statement when code works

            if (marker.IsAvailableIndex(0))
            {
                ViewSection extElev = marker.CreateElevation(doc, plan.Id, 0);
                extElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId());
            }

            return(marker);
        }
Exemple #9
0
        public List <ViewSection> PlaceElevations(Document doc, XYZ center, ViewPlan intElevPlan)
        {
            //add pop up to input scale
            //current scale set to 1/8"
            ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, FindFamilyTypeId(doc), center, 96);
            Parameter       p      = intElevPlan.get_Parameter(BuiltInParameter.VIEW_PHASE);

            marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId());
            List <ViewSection> intElevList = new List <ViewSection>();

            for (int markerindex = 0; markerindex < marker.MaximumViewCount; markerindex++)
            {
                if (marker.IsAvailableIndex(markerindex))
                {
                    ViewSection intElev = marker.CreateElevation(doc, intElevPlan.Id, markerindex);
                    intElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId());
                    intElevList.Add(intElev);
                }
            }

            return(intElevList);
        }
Exemple #10
0
        public void setup_elevation_markers(Document doc)
        {
            Transaction trans = new Transaction(doc);
            FilteredElementCollector levels_col
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(ElevationMarker));

            while (levels_col.Count() > 0)
            {
                ElevationMarker m = levels_col.Last() as ElevationMarker;
                using (trans = new Transaction(doc))
                {
                    trans.Start("elevation markers");
                    doc.Delete(m.Id);
                    trans.Commit();
                }
            }

            ViewFamilyType vft = new FilteredElementCollector(doc)
                                 .OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>()
                                 .FirstOrDefault <ViewFamilyType>(a => ViewFamily.Elevation == a.ViewFamily);

            XYZ center = new XYZ(60, 10, 0);
            // FIXME : select the Floor plan/Site view
            View view = doc.ActiveView;

            using (trans = new Transaction(doc))
            {
                trans.Start("elevation views");
                ElevationMarker marker        = ElevationMarker.CreateElevationMarker(doc, vft.Id, center, 50);
                ViewSection     elevationView = marker.CreateElevation(doc, view.Id, 0);
                Parameter       p             = elevationView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR);
                p.Set(300.0);
                trans.Commit();
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            #region//Utils
            StringBuilder       sb        = new StringBuilder();
            Collector           collector = new Collector();
            LengthUnitConverter converter = new LengthUnitConverter();
            #endregion

            #region//Application context
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;
            #endregion

            #region//Check if current project is family
            if (doc.IsFamilyDocument)
            {
                Message.Display("Can't use command in family document", WindowType.Warning);
                return(Result.Cancelled);
            }
            #endregion

            #region//Select elements
            List <Element> genericModelList         = collector.GetGenericModels(doc);
            List <Element> List_GenericModels       = new List <Element>();
            List <string>  List_GenericModelStrings = new List <string>();
            FamilyInstance familyInstance           = null;

            foreach (Element genericModel in genericModelList)
            {
                familyInstance = doc.GetElement(genericModel.Id) as FamilyInstance;
                if (familyInstance.SuperComponent == null)
                {
                    if (List_GenericModelStrings.Contains(genericModel.Name))
                    {
                    }
                    else
                    {
                        List_GenericModels.Add(genericModel);
                        List_GenericModelStrings.Add(genericModel.Name);
                    }
                }
            }
            #endregion

            #region//Check if list of generic models is empty
            if (List_GenericModels.Count == 0)
            {
                Message.Display("There aren't any generic models in the project", WindowType.Warning);
                return(Result.Cancelled);
            }
            #endregion

            #region//Execute task for each generic model
            foreach (Element genericModel in List_GenericModels)
            {
                FamilyInstance genericModelFamily = doc.GetElement(genericModel.Id) as FamilyInstance;
                FamilySymbol   genericModelSymbol = genericModelFamily.Symbol;

                #region //Get type parameters of element
                string MDK_merk = genericModelSymbol.LookupParameter("MDK_merk").AsString();
                #endregion

                #region //Get nested family
                FamilyInstance nestedFamily     = null;
                string         nestedFamilyName = "Profiel_1";

                List <double>         nestedFamilyOriginZ = new List <double>();
                List <FamilyInstance> nestedFamilies      = new List <FamilyInstance>();

                FamilyInstance familyContainer = null;
                LocationCurve  curveContainer  = null;
                Line           lineContainer   = null;

                ICollection <ElementId> subComponentIds = genericModelFamily.GetSubComponentIds();
                foreach (ElementId id in subComponentIds)
                {
                    if (doc.GetElement(id).Name == nestedFamilyName)
                    {
                        nestedFamilies.Add(doc.GetElement(id) as FamilyInstance);
                        familyContainer = doc.GetElement(id) as FamilyInstance;
                        curveContainer  = familyContainer.Location as LocationCurve;
                        lineContainer   = curveContainer.Curve as Line;
                        nestedFamilyOriginZ.Add(lineContainer.Origin.Z);
                    }
                }

                double minValue = int.MaxValue;
                int    minIndex;
                int    index = -1;

                foreach (double num in nestedFamilyOriginZ)
                {
                    index++;
                    if (num <= minValue)
                    {
                        minValue = num;
                        minIndex = index;
                    }
                }

                nestedFamily = nestedFamilies[index];

                if (nestedFamily == null)
                {
                    Message.Display("There isn't a nested family in the element with the specified name.", WindowType.Error);
                    return(Result.Cancelled);
                }
                #endregion

                #region//Get direction of family
                LocationCurve locationCurve = nestedFamily.Location as LocationCurve;
                Line          locationLine  = locationCurve.Curve as Line;
                XYZ           dir           = locationLine.Direction.Normalize();;
                #endregion

                #region//Create Boundingbox
                XYZ lineStart      = locationLine.GetEndPoint(0);
                XYZ lineEnd        = locationLine.GetEndPoint(1);
                XYZ lineDifference = lineEnd - lineStart;

                BoundingBoxXYZ genicModelbb = genericModel.get_BoundingBox(null);
                double         minZ         = genicModelbb.Min.Z;
                double         maxZ         = genicModelbb.Max.Z;

                double width     = lineDifference.GetLength();
                double height    = maxZ - minZ;
                double thickness = converter.ConvertToFeet(500);
                double offset    = converter.ConvertToFeet(500);

                XYZ min = new XYZ(-width - converter.ConvertToFeet(1000), minZ - offset, -offset);
                XYZ max = new XYZ(width, maxZ + offset, +offset);

                XYZ midpoint = lineStart + 0.5 * lineDifference;
                XYZ up       = XYZ.BasisZ;
                XYZ viewDir  = dir.CrossProduct(up);

                Transform t = Transform.Identity;
                t.Origin = midpoint;
                t.BasisX = dir;
                t.BasisY = up;
                t.BasisZ = viewDir;

                BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();
                boundingBox.Transform = t;
                boundingBox.Min       = min;
                boundingBox.Max       = max;
                #endregion

                #region//Get viewFamilyType
                ViewFamilyType viewFamily = collector.GetViewFamilyType(doc, ViewFamily.Section).FirstOrDefault();
                #endregion

                #region //Create Section
                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Create Section");

                    ViewSection section = ViewSection.CreateSection(doc, viewFamily.Id, boundingBox);
                    section.Name           = genericModel.Name;
                    section.Scale          = 50;
                    section.CropBoxVisible = false;
                    section.get_Parameter(BuiltInParameter.SECTION_COARSER_SCALE_PULLDOWN_METRIC).Set(1);
                    section.LookupParameter("Subdiscipline").Set("LEGEND");

                    tx.Commit();
                }
                #endregion
            }
            #endregion

            #region//Get all section views
            List <View> sectionViewList   = collector.GetViews(doc, ViewType.Section);
            List <View> List_SectionViews = new List <View>();

            foreach (View sectionView in sectionViewList)
            {
                if (sectionView.Name.Contains("Kozijn"))
                {
                    List_SectionViews.Add(sectionView);
                }
            }
            #endregion

            #region//Execute task for each sectionView
            foreach (View sectionView in List_SectionViews)
            {
                #region//Get DimensionType
                DimensionType genericModelDimension = collector.GetLinearDimensionTypeByName(doc, "hoofdmaatvoering");
                DimensionType nestedFamilyDimension = collector.GetLinearDimensionTypeByName(doc, "stelkozijn");
                #endregion

                #region//Get directions for dimensions
                XYZ widthDirection  = sectionView.RightDirection.Normalize();
                XYZ heigthDirection = new XYZ(0, 0, 1);
                #endregion

                #region//Select elements
                List <Element> genericModelInViewList   = collector.GetGenericModels(doc, sectionView.Id);
                List <Element> List_GenericModelsInView = new List <Element>();
                FamilyInstance familyInstanceInView     = null;

                foreach (Element genericModel in genericModelInViewList)
                {
                    familyInstanceInView = doc.GetElement(genericModel.Id) as FamilyInstance;
                    if (familyInstanceInView.SuperComponent == null)
                    {
                        List_GenericModelsInView.Add(genericModel);
                    }
                }
                #endregion

                #region//Execute task for each generic model
                foreach (Element genericModel in List_GenericModelsInView)
                {
                    FamilyInstance genericModelFamily = doc.GetElement(genericModel.Id) as FamilyInstance;
                    FamilySymbol   genericModelSymbol = genericModelFamily.Symbol;

                    #region//Get nested family 1
                    string         nestedFamilyName1 = "31_MDK_GM_stelkozijn_lijn";
                    FamilyInstance nestedFamily1     = null;

                    ICollection <ElementId> subComponentIds1 = genericModelFamily.GetSubComponentIds();
                    foreach (ElementId id in subComponentIds1)
                    {
                        if (doc.GetElement(id).Name == nestedFamilyName1)
                        {
                            nestedFamily1 = doc.GetElement(id) as FamilyInstance;
                        }
                    }
                    #endregion

                    #region//Get nested family 2
                    FamilyInstance nestedFamily2     = null;
                    string         nestedFamilyName2 = "Profiel_1";

                    List <double>         nestedFamilyOriginZ = new List <double>();
                    List <FamilyInstance> nestedFamilies      = new List <FamilyInstance>();

                    FamilyInstance familyContainer = null;
                    LocationCurve  curveContainer  = null;
                    Line           lineContainer   = null;

                    ICollection <ElementId> subComponentIds2 = genericModelFamily.GetSubComponentIds();
                    foreach (ElementId id in subComponentIds2)
                    {
                        if (doc.GetElement(id).Name == nestedFamilyName2)
                        {
                            nestedFamilies.Add(doc.GetElement(id) as FamilyInstance);
                            familyContainer = doc.GetElement(id) as FamilyInstance;
                            curveContainer  = familyContainer.Location as LocationCurve;
                            lineContainer   = curveContainer.Curve as Line;
                            nestedFamilyOriginZ.Add(lineContainer.Origin.Z);
                        }
                    }

                    double minValue = int.MaxValue;
                    int    minIndex;
                    int    index = -1;

                    foreach (double num in nestedFamilyOriginZ)
                    {
                        index++;
                        if (num <= minValue)
                        {
                            minValue = num;
                            minIndex = index;
                        }
                    }

                    nestedFamily2 = nestedFamilies[index];

                    if (nestedFamily2 == null)
                    {
                        Message.Display("There isn't a nested family in the element with the specified name.", WindowType.Error);
                        return(Result.Cancelled);
                    }
                    #endregion

                    #region//Get type parameters of element
                    double MDK_breedte = genericModelSymbol.LookupParameter("MDK_breedte").AsDouble();
                    #endregion

                    #region//Get instance parameters of element
                    double MDK_offset_vooraanzicht = genericModelFamily.LookupParameter("MDK_offset_vooraanzicht").AsDouble();
                    #endregion

                    #region//Get direction of family
                    LocationCurve locationCurve = nestedFamily2.Location as LocationCurve;
                    Line          locationLine  = locationCurve.Curve as Line;
                    XYZ           dir           = locationLine.Direction.Normalize();;
                    #endregion

                    #region//Check if generic model is in same direction as view
                    double genericModelAngle = Math.Round(Math.Atan2(dir.Y, dir.X) * (180 / Math.PI), 5);
                    double activeViewAngle   = Math.Round(Math.Atan2(widthDirection.Y, widthDirection.X) * (180 / Math.PI), 5);
                    if (genericModelAngle <= 0)
                    {
                        genericModelAngle = genericModelAngle + 180;
                    }
                    else
                    {
                        genericModelAngle = genericModelAngle - 180;
                    }

                    if (genericModelAngle != activeViewAngle)
                    {
                        Message.Display("The generic model isn't parallel to the active view.", WindowType.Error);
                        return(Result.Cancelled);
                    }
                    #endregion

                    #region//Get locationpoint of selected element
                    LocationPoint location      = genericModelFamily.Location as LocationPoint;
                    XYZ           locationpoint = location.Point;
                    #endregion

                    #region// Get references which refer to the reference planes in the family
                    ReferenceArray genericModelHeightref = new ReferenceArray();
                    ReferenceArray genericModelWidthref  = new ReferenceArray();
                    ReferenceArray nestedFamilyHeightref = new ReferenceArray();
                    ReferenceArray nestedFamilyWidthref  = new ReferenceArray();

                    foreach (var e in genericModelFamily.GetReferences(FamilyInstanceReferenceType.Top))
                    {
                        genericModelHeightref.Append(e);
                    }

                    foreach (var e in genericModelFamily.GetReferences(FamilyInstanceReferenceType.Bottom))
                    {
                        genericModelHeightref.Append(e);
                    }

                    foreach (var e in genericModelFamily.GetReferences(FamilyInstanceReferenceType.StrongReference))
                    {
                        genericModelWidthref.Append(e);
                    }

                    foreach (var e in nestedFamily1.GetReferences(FamilyInstanceReferenceType.StrongReference))
                    {
                        nestedFamilyWidthref.Append(e);
                    }

                    foreach (var e in nestedFamily1.GetReferences(FamilyInstanceReferenceType.Top))
                    {
                        nestedFamilyHeightref.Append(e);
                    }

                    foreach (var e in nestedFamily1.GetReferences(FamilyInstanceReferenceType.Bottom))
                    {
                        nestedFamilyHeightref.Append(e);
                    }
                    #endregion

                    #region//Create endpoints for line creation
                    XYZ genericModelHeight = GetDistance(locationpoint, widthDirection, MDK_breedte, 1000);
                    XYZ genericModelWidth  = new XYZ(locationpoint.X, locationpoint.Y, locationpoint.Z + MDK_offset_vooraanzicht - converter.ConvertToFeet(1000));
                    XYZ nestedFamilyHeight = GetDistance(locationpoint, widthDirection, MDK_breedte, 500);
                    XYZ nestedFamilyWidth  = new XYZ(locationpoint.X, locationpoint.Y, locationpoint.Z + MDK_offset_vooraanzicht - converter.ConvertToFeet(500));
                    #endregion

                    #region//Create line for dimension
                    Line genericModelHeightLine = Line.CreateBound(genericModelHeight, genericModelHeight + heigthDirection * 100);
                    Line genericModelWidthLine  = Line.CreateBound(genericModelWidth, genericModelWidth + widthDirection * 100);
                    Line nestedFamilyHeightLine = Line.CreateBound(nestedFamilyHeight, nestedFamilyHeight + heigthDirection * 100);
                    Line nestedFamilyWidthLine  = Line.CreateBound(nestedFamilyWidth, nestedFamilyWidth + widthDirection * 100);
                    #endregion

                    #region//Create Dimensions
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Create Dimensions");

                        #region//Create and set workplane to place dimensions on
                        Plane       plane       = Plane.CreateByNormalAndOrigin(sectionView.ViewDirection, sectionView.Origin);
                        SketchPlane sketchPlane = SketchPlane.Create(doc, plane);
                        sectionView.SketchPlane = sketchPlane;
                        #endregion

                        #region//Create Dimensions
                        doc.Create.NewDimension(sectionView, genericModelHeightLine, genericModelHeightref, genericModelDimension);
                        doc.Create.NewDimension(sectionView, genericModelWidthLine, genericModelWidthref, genericModelDimension);
                        doc.Create.NewDimension(sectionView, nestedFamilyHeightLine, nestedFamilyHeightref, nestedFamilyDimension);
                        doc.Create.NewDimension(sectionView, nestedFamilyWidthLine, nestedFamilyWidthref, nestedFamilyDimension);
                        #endregion

                        tx.Commit();
                    }
                    #endregion
                }
                #endregion
            }
            #endregion
            return(Result.Succeeded);
        }
Exemple #12
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            Selection sel = uidoc.Selection;


            var form_to_show = new LoadExcel(uiapp);

            form_to_show.ShowDialog();


            View3D view = doc.ActiveView as View3D;

            if (null == view)
            {
                message = "Please run this command in a 3D view.";
                return(Result.Failed);
            }

            Element scopeBox
                = new FilteredElementCollector(doc, view.Id)
                  .OfCategory(BuiltInCategory.OST_VolumeOfInterest)
                  .WhereElementIsNotElementType()
                  .FirstElement();
            ElementId scopeBoxName = scopeBox.Id;

            BoundingBoxXYZ viewScopeBox
                = GenerateBoundingBoxXYZ(scopeBox);

            //set up view family type - have to play with this one more
            ViewFamilyType vft
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(ViewFamilyType))
                  .Cast <ViewFamilyType>()
                  .FirstOrDefault <ViewFamilyType>(x =>
                                                   ViewFamily.Section == x.ViewFamily);
            string filenametemp = get_str();

            //make the transaction; should add more sections here later;
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Move And Resize Section Box");
                ViewSection section = ViewSection.CreateSection(doc, vft.Id, viewScopeBox);
                section.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(scopeBoxName);
                section.get_Parameter(BuiltInParameter.VIEW_NAME).Set(get_str());
                GetTitleBlocks(doc);
                GenerateSheet(doc, section);
                //view.SetSectionBox(viewScopeBox);
                tx.Commit();
            }

            return(Result.Succeeded);
        }
        public ElevationMarker PlaceMarker(Document doc, BoundingBoxXYZ wallbb, Wall w)
        {
            XYZ       wallbbmin = wallbb.Min;
            XYZ       wallbbmax = wallbb.Max;
            ViewPlan  plan      = DocumentElevPlanViews(doc);
            Parameter p         = plan.get_Parameter(BuiltInParameter.VIEW_PHASE);
            //Debug("p equals " + p.AsElementId() + " phase called " + p.AsValueString());
            ////Element planPhase = doc.GetElement(p.AsElementId());
            ////Debug("planPhase equals " + planPhase);

            //List<Room> allRooms = RoomHelpers.GetAllRooms(doc);
            //foreach(Room room in allRooms)
            //{
            //    //Parameter roomPhase = room.get_Parameter(BuiltInParameter.VIEW_PHASE);
            //    //Debug("Room Phase View Phase " + room.Name + " - " + roomPhase + " (" + roomPhase.AsValueString() + ")");

            //    Parameter roomPhase2 = room.get_Parameter(BuiltInParameter.PHASE_CREATED);
            //    Debug("Room Phase Phase Created " + room.Name + " - " + roomPhase2.AsElementId().ToString() + " (" + roomPhase2.AsValueString() + ")");

            //    Parameter roomPhase3 = room.get_Parameter(BuiltInParameter.ROOM_PHASE);
            //    Debug("Room Phase Room Phase " + room.Name + " - " + roomPhase3.AsElementId().ToString() + " (" + roomPhase3.AsValueString() + ")");

            //    //ElementId roomPhase1 = room.CreatedPhaseId;
            //    //Debug("Room Phase 1 " + room.Name + " - " + roomPhase1 + " (" + roomPhase1.ToString() + ")");
            //}

            //Debug("Wallbb min " + wallbbmin);
            //Debug("Wallbb max " + wallbbmax);
            //Debug("Plan phase Id " + p.AsElementId().ToString());
            ////Debug("Plan phase Name " + planPhase.Name);

            XYZ wallCenter = new XYZ(
                (wallbbmax.X + wallbbmin.X) / 2,
                (wallbbmax.Y + wallbbmin.Y) / 2,
                wallbbmin.Z
                );

            List <Room> phasedRooms = RoomHelpers.GetPhasedRooms(doc, p.AsElementId());
            //Debug("Phase of wall " + w.CreatedPhaseId.ToString());
            //Debug("Phase of wall name " + w.get_Parameter(BuiltInParameter.PHASE_CREATED).AsValueString());

            XYZ wallCenterYTranslatedPositive = new XYZ(
                wallCenter.X,
                wallCenter.Y + 10,
                wallCenter.Z
                );

            XYZ wallCenterYTranslatedNegative = new XYZ(
                wallCenter.X,
                wallCenter.Y - 10,
                wallCenter.Z
                );

            XYZ wallCenterXTranslatedPositive = new XYZ(
                wallCenter.X + 10,
                wallCenter.Y,
                wallCenter.Z
                );

            XYZ wallCenterXTranslatedNegative = new XYZ(
                wallCenter.X - 10,
                wallCenter.Y,
                wallCenter.Z
                );

            //Debug("wall center " + wallCenter);

            //Debug("wallCenterYTranslatedPositive " + wallCenterYTranslatedPositive);
            //Debug("wallCenterYTranslatedNegative " + wallCenterYTranslatedNegative);
            //Debug("wallCenterXTranslatedPositive " + wallCenterXTranslatedPositive);
            //Debug("wallCenterXTranslatedNegative " + wallCenterXTranslatedNegative);

            XYZ markerLocation = wallCenter;

            Debug("markerLocation before the loops " + markerLocation);
            Debug("length of list phasedrooms " + phasedRooms.Count);

            if ((wallbbmax.X - wallbbmin.X) > (wallbbmax.Y - wallbbmin.Y))
            {
                foreach (Room r in phasedRooms)
                {
                    if (r.IsPointInRoom(wallCenterYTranslatedPositive))
                    {
                        Debug("room name " + r.Name);
                        Debug("is Y positive in room " + r.IsPointInRoom(wallCenterYTranslatedPositive));

                        markerLocation = wallCenterYTranslatedNegative;
                        break;
                    }
                    else if (r.IsPointInRoom(wallCenterYTranslatedNegative))
                    {
                        Debug("room name " + r.Name);
                        Debug("is Y negative in room " + r.IsPointInRoom(wallCenterYTranslatedNegative));
                        markerLocation = wallCenterYTranslatedPositive;
                        break;
                    }
                }
                Debug("is Y check done");
            }
            else
            {
                foreach (Room r in phasedRooms)
                {
                    if (r.IsPointInRoom(wallCenterXTranslatedPositive))
                    {
                        Debug("room name " + r.Name);
                        Debug("is X positive in room " + r.IsPointInRoom(wallCenterXTranslatedPositive));
                        markerLocation = wallCenterXTranslatedNegative;
                        break;
                    }
                    else if (r.IsPointInRoom(wallCenterXTranslatedNegative))
                    {
                        Debug("room name " + r.Name);
                        Debug("is X negative in room " + r.IsPointInRoom(wallCenterXTranslatedNegative));
                        markerLocation = wallCenterXTranslatedPositive;
                        break;
                    }
                }
                Debug("is X check done");
            }

            Debug("selected marker location after loops " + markerLocation);

            //change scale to user input
            ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, FindFamilyTypeId(doc), markerLocation, 96);

            marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId());


            if (marker.IsAvailableIndex(0))
            {
                ViewSection extElev = marker.CreateElevation(doc, plan.Id, 0);

                extElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId());
            }

            return(marker);
        }
Exemple #14
0
        public static ViewSection CreateWallSection(Document linkedDoc, Document doc, Polygon directPolygon, ElementId id, string viewName, double offset)
        {
            Element e = linkedDoc.GetElement(id);

            if (!(e is Wall))
            {
                throw new Exception("Element is not a wall!");
            }
            Wall wall = (Wall)e;
            Line line = (wall.Location as LocationCurve).Curve as Line;

            ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily);

            XYZ        p1 = line.GetEndPoint(0), p2 = line.GetEndPoint(1);
            List <XYZ> ps = new List <XYZ> {
                p1, p2
            }; ps.Sort(new ZYXComparer());

            p1 = ps[0]; p2 = ps[1];

            BoundingBoxXYZ bb = wall.get_BoundingBox(null);
            double         minZ = bb.Min.Z, maxZ = bb.Max.Z;

            double l = GeomUtil.GetLength(GeomUtil.SubXYZ(p2, p1));
            double h = maxZ - minZ;
            double w = wall.WallType.Width;

            XYZ tfMin = new XYZ(-l / 2 - offset, minZ - offset, -w - offset);
            XYZ tfMax = new XYZ(l / 2 + offset, maxZ + offset, w + offset);

            XYZ wallDir = GeomUtil.UnitVector(p2 - p1);
            XYZ upDir   = XYZ.BasisZ;
            XYZ viewDir = GeomUtil.CrossMatrix(wallDir, upDir);

            XYZ midPoint  = (p1 + p2) / 2;
            XYZ pMidPoint = GetProjectPoint(directPolygon.Plane, midPoint);

            XYZ pPnt = GeomUtil.OffsetPoint(pMidPoint, viewDir, w * 10);

            if (GeomUtil.IsBigger(GeomUtil.GetLength(pMidPoint, directPolygon.CentralXYZPoint), GeomUtil.GetLength(pPnt, directPolygon.CentralXYZPoint)))
            {
                wallDir = -wallDir;
                upDir   = XYZ.BasisZ;
                viewDir = GeomUtil.CrossMatrix(wallDir, upDir);
            }
            else
            {
            }

            pPnt = GeomUtil.OffsetPoint(p1, wallDir, offset);
            XYZ min = null, max = null;

            if (GeomUtil.IsBigger(GeomUtil.GetLength(GeomUtil.SubXYZ(pPnt, midPoint)), GeomUtil.GetLength(GeomUtil.SubXYZ(p1, midPoint))))
            {
                min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, wallDir, offset), -viewDir, offset);
                max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, -wallDir, offset), viewDir, offset);
            }
            else
            {
                min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, -wallDir, offset), -viewDir, offset);
                max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, wallDir, offset), viewDir, offset);
            }
            min = new XYZ(min.X, min.Y, minZ - offset);
            max = new XYZ(max.X, max.Y, maxZ + offset);

            Transform tf = Transform.Identity;

            tf.Origin = (p1 + p2) / 2;
            tf.BasisX = wallDir;
            tf.BasisY = XYZ.BasisZ;
            tf.BasisZ = GeomUtil.CrossMatrix(wallDir, upDir);

            BoundingBoxXYZ sectionBox = new BoundingBoxXYZ()
            {
                Transform = tf, Min = tfMin, Max = tfMax
            };
            ViewSection vs = ViewSection.CreateSection(doc, vft.Id, sectionBox);

            tf  = vs.get_BoundingBox(null).Transform.Inverse;
            max = tf.OfPoint(max);
            min = tf.OfPoint(min);
            double maxx = 0, maxy = 0, maxz = 0, minx = 0, miny = 0, minz = 0;

            if (max.Z > min.Z)
            {
                maxz = max.Z;
                minz = min.Z;
            }
            else
            {
                maxz = min.Z;
                minz = max.Z;
            }


            if (Math.Round(max.X, 4) == Math.Round(min.X, 4))
            {
                maxx = max.X;
                minx = minz;
            }
            else if (max.X > min.X)
            {
                maxx = max.X;
                minx = min.X;
            }

            else
            {
                maxx = min.X;
                minx = max.X;
            }

            if (Math.Round(max.Y, 4) == Math.Round(min.Y, 4))
            {
                maxy = max.Y;
                miny = minz;
            }
            else if (max.Y > min.Y)
            {
                maxy = max.Y;
                miny = min.Y;
            }

            else
            {
                maxy = min.Y;
                miny = max.Y;
            }

            BoundingBoxXYZ sectionView = new BoundingBoxXYZ();

            sectionView.Max = new XYZ(maxx, maxy, maxz);
            sectionView.Min = new XYZ(minx, miny, minz);

            vs.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(ElementId.InvalidElementId);

            vs.get_Parameter(BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING).Set(0);

            vs.CropBoxActive  = true;
            vs.CropBoxVisible = true;

            doc.Regenerate();

            vs.CropBox = sectionView;
            vs.Name    = viewName;
            return(vs);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            using (Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Test"))
            {
                try
                {
                    bool isValidSelect = false;
                    do
                    {
                        Reference reference = commandData.Application.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Please select room.");
                        if (reference == null)
                        {
                            TaskDialog.Show("Error", "It is not object!");
                        }
                        else
                        {
                            Element element      = commandData.Application.ActiveUIDocument.Document.GetElement(reference);
                            Room    selectedRoom = element as Room;

                            if (selectedRoom == null)
                            {
                                TaskDialog.Show("Error", "It is not room!");
                            }
                            else
                            {
                                IList <IList <BoundarySegment> > roomSegments = selectedRoom.GetBoundarySegments(new SpatialElementBoundaryOptions {
                                    SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish
                                });
                                Curve curveRight = null;
                                Curve curveLeft  = null;
                                Curve curveUp    = null;
                                Curve curveDown  = null;
                                transaction.Start();
                                foreach (IList <BoundarySegment> segments in roomSegments)
                                {
                                    foreach (BoundarySegment segment in segments)
                                    {
                                        Line    cu   = segment.GetCurve() as Line;
                                        Element e    = commandData.Application.ActiveUIDocument.Document.GetElement(segment.ElementId);
                                        Wall    wall = e as Wall;
                                        if (cu.Direction.X == -1)
                                        {
                                            if (curveUp != null)
                                            {
                                                curveUp = Line.CreateBound(curveUp.GetEndPoint(0), segment.GetCurve().GetEndPoint(1)) as Curve;
                                            }
                                            else
                                            {
                                                curveUp = segment.GetCurve();
                                            }
                                        }
                                        else if (cu.Direction.X == 1)
                                        {
                                            if (curveDown != null)
                                            {
                                                curveDown = Line.CreateBound(curveDown.GetEndPoint(0), segment.GetCurve().GetEndPoint(1)) as Curve;
                                            }
                                            else
                                            {
                                                curveDown = segment.GetCurve();
                                            }
                                        }
                                        else if (cu.Direction.Y == -1)
                                        {
                                            if (curveLeft != null)
                                            {
                                                curveLeft = Line.CreateBound(curveLeft.GetEndPoint(0), segment.GetCurve().GetEndPoint(1)) as Curve;
                                            }
                                            else
                                            {
                                                curveLeft = segment.GetCurve();
                                            }
                                        }
                                        else if (cu.Direction.Y == 1)
                                        {
                                            if (curveRight != null)
                                            {
                                                curveRight = Line.CreateBound(curveRight.GetEndPoint(0), segment.GetCurve().GetEndPoint(1)) as Curve;
                                            }
                                            else
                                            {
                                                curveRight = segment.GetCurve();
                                            }
                                        }
                                    }
                                }

                                IEnumerable <ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document).OfClass(typeof(ViewFamilyType))
                                                                               let type = elem as ViewFamilyType
                                                                                          where type.ViewFamily == ViewFamily.Elevation
                                                                                          select type;

                                ElevationMarker markerUp  = ElevationMarker.CreateElevationMarker(commandData.Application.ActiveUIDocument.Document, viewFamilyTypes.FirstOrDefault().Id, new XYZ(curveUp.GetEndPoint(0).X, curveUp.GetEndPoint(0).Y - 1, curveUp.GetEndPoint(0).Z), 1);
                                ViewSection     sectionUp = markerUp.CreateElevation(commandData.Application.ActiveUIDocument.Document, commandData.Application.ActiveUIDocument.Document.ActiveView.Id, 1);
                                sectionUp.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).Set(3);

                                ElevationMarker markerDown  = ElevationMarker.CreateElevationMarker(commandData.Application.ActiveUIDocument.Document, viewFamilyTypes.FirstOrDefault().Id, new XYZ(curveDown.GetEndPoint(0).X, curveDown.GetEndPoint(0).Y + 1, curveDown.GetEndPoint(0).Z), 1);
                                ViewSection     sectionDown = markerDown.CreateElevation(commandData.Application.ActiveUIDocument.Document, commandData.Application.ActiveUIDocument.Document.ActiveView.Id, 3);
                                sectionDown.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).Set(3);

                                ElevationMarker markerLeft  = ElevationMarker.CreateElevationMarker(commandData.Application.ActiveUIDocument.Document, viewFamilyTypes.FirstOrDefault().Id, new XYZ(curveLeft.GetEndPoint(0).X + 1, curveLeft.GetEndPoint(0).Y, curveLeft.GetEndPoint(0).Z), 1);
                                ViewSection     sectionLeft = markerLeft.CreateElevation(commandData.Application.ActiveUIDocument.Document, commandData.Application.ActiveUIDocument.Document.ActiveView.Id, 0);
                                sectionLeft.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).Set(3);

                                ElevationMarker markerRight  = ElevationMarker.CreateElevationMarker(commandData.Application.ActiveUIDocument.Document, viewFamilyTypes.FirstOrDefault().Id, new XYZ(curveRight.GetEndPoint(0).X - 1, curveRight.GetEndPoint(0).Y, curveRight.GetEndPoint(0).Z), 1);
                                ViewSection     sectionRight = markerRight.CreateElevation(commandData.Application.ActiveUIDocument.Document, commandData.Application.ActiveUIDocument.Document.ActiveView.Id, 2);
                                sectionRight.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).Set(3);
                                transaction.Commit();
                                isValidSelect = true;
                            }
                        }
                    } while (!isValidSelect);
                }
                catch (Exception e)
                {
                    return(Result.Failed);
                }
            }
            return(Result.Succeeded);
        }
        /// <summary>
        /// 在房间X的中心创建四个方向的立面
        /// Create four Elevations on the center of the "X" of the selRoom
        /// </summary>
        /// <param name="elevationOffset"></param>
        /// <param name="FloorThickness"></param>
        public void CreateElevations(double elevationOffset, double FloorThickness)
        {
            int i = 0;//循环用

            //获取立面的familytype     Get the familyType of Elevation
            FilteredElementCollector collector = new FilteredElementCollector(DocSet.doc);

            collector.OfClass(typeof(ViewFamilyType));

            var viewFamilyTypes = from elem in collector
                                  let type = elem as ViewFamilyType
                                             where type.ViewFamily == ViewFamily.Elevation
                                             select type;

            ElementId viewTypeId;

            if (viewFamilyTypes.Count() > 0)
            {
                viewTypeId = viewFamilyTypes.First().Id;
            }
            else
            {
                return;
            }


            using (Transaction tran = new Transaction(DocSet.doc))
            {
                //房间的"X"的交点
                LocationPoint pt = DocSet.selRoom.Location as LocationPoint;

                tran.Start("newElvation");
                ElevationMarker marker = ElevationMarker.CreateElevationMarker(DocSet.doc, viewTypeId, pt.Point, 50);
                for (; i < 4; i++)
                {
                    ViewSection sv = marker.CreateElevation(DocSet.doc, DocSet.doc.ActiveView.Id, i);

                    //设定立面的 远剪裁偏移
                    sv.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).SetValueString("10000");

                    //设定每个立面的名称
                    XYZ    normal        = null;//法向量
                    string elevationName = "ELE -";
                    switch (i)
                    {
                    case 0:
                        elevationName += " West " + _SoANumber;
                        normal         = new XYZ(-1, 0, 0);
                        sv.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set("ELEVATION WEST");
                        break;

                    case 1:
                        elevationName += " North" + _SoANumber;
                        normal         = new XYZ(0, 1, 0);
                        sv.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set("ELEVATION NORTH");
                        break;

                    case 2:
                        elevationName += " East" + _SoANumber;
                        normal         = new XYZ(1, 0, 0);
                        sv.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set("ELEVATION EAST");
                        break;

                    case 3:
                        elevationName += " South" + _SoANumber;
                        normal         = new XYZ(0, -1, 0);
                        sv.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set("ELEVATION SOUTH");
                        break;
                    }
                    sv.ViewName = elevationName;

                    //不能删 必须先保存修改才能获取上面的元素
                    tran.Commit();
                    tran.Start("change elevation crop shape");

                    //小指型房间专用修改
                    if (cbSpRoom.IsChecked == true)
                    {
                        if (i == 1 || i == 2)
                        {
                            normal = -normal;
                        }
                        spRoomElevationChange(sv, elevationOffset, normal, FloorThickness);
                    }
                    else
                    {
                        //修改立面底边的高度
                        XYZ pt1 = null;
                        XYZ pt2 = null;
                        XYZ pt3 = null;
                        XYZ pt4 = null;
                        sv.CropBoxActive = true;
                        ViewCropRegionShapeManager vcrShanpMgr = sv.GetCropRegionShapeManager();
                        CurveLoop         loop     = vcrShanpMgr.GetCropShape().First();
                        CurveLoopIterator iterator = loop.GetCurveLoopIterator();

                        //分辨点的位置
                        while (iterator.MoveNext())
                        {
                            Curve curve = iterator.Current;
                            XYZ   pt0   = curve.GetEndPoint(0);
                            if (-1 < pt0.Z - pt.Point.Z && pt0.Z - pt.Point.Z < 1)
                            {
                                if (pt1 == null)
                                {
                                    pt1 = pt0;
                                }
                                else
                                {
                                    pt2 = pt0;
                                }
                            }

                            else
                            {
                                if (pt3 == null)
                                {
                                    pt3 = pt0;
                                }
                                else
                                {
                                    pt4 = pt0;
                                }
                            }
                        }

                        //重新生成一个边界框
                        //TaskDialog.Show("1", pt1.ToString() + "\n" + pt2.ToString() + "\n" + pt3.ToString() + "\n" + pt4.ToString());
                        pt1 = new XYZ(pt1.X, pt1.Y, pt1.Z + FloorThickness / 300);
                        pt2 = new XYZ(pt2.X, pt2.Y, pt1.Z);

                        Line lineBottom = Line.CreateBound(pt1, pt2);
                        Line lineRight  = Line.CreateBound(pt2, pt4);
                        Line lineTop    = Line.CreateBound(pt4, pt3);
                        Line lineLeft   = Line.CreateBound(pt3, pt1);

                        CurveLoop profile = new CurveLoop();
                        profile.Append(lineBottom);
                        profile.Append(lineRight);
                        profile.Append(lineTop);
                        profile.Append(lineLeft);

                        profile = CurveLoop.CreateViaOffset(profile, elevationOffset / 300, -normal);
                        vcrShanpMgr.SetCropShape(profile);
                    }
                }

                tran.Commit();
            }
        }