예제 #1
0
        public static List <RefPlane> CollectRefPlanes(Document famDoc)
        {
            List <RefPlane> rps = new FilteredElementCollector(famDoc)
                                  .OfClass(typeof(ReferencePlane))
                                  .Cast <ReferencePlane>()
                                  .Select(i => new RefPlane(i))
                                  .ToList();

            List <RefPlane> levels = new FilteredElementCollector(famDoc)
                                     .OfClass(typeof(Level))
                                     .Cast <Level>()
                                     .Select(i => new RefPlane(i))
                                     .ToList();

            rps.AddRange(levels);

            List <RefPlane> sketchPlanes = new FilteredElementCollector(famDoc)
                                           .OfClass(typeof(SketchPlane))
                                           .Cast <SketchPlane>()
                                           .Select(i => new RefPlane(i))
                                           .ToList();

            rps.AddRange(sketchPlanes);


            return(rps);
        }
예제 #2
0
        public IEnumerable <CW_Element> Get(string documentTitle, string uniqueId)
        {
            var cwElements = new List <CW_Element>();

            if (GetDocument(documentTitle) is Document document)
            {
                var rvtElements = new List <Element>();

                if (string.IsNullOrEmpty(uniqueId))
                {
                    rvtElements = new FilteredElementCollector(document).WhereElementIsNotElementType().ToList();
                    var typeElements = new FilteredElementCollector(document).WhereElementIsElementType();
                    rvtElements.AddRange(typeElements);
                }
                else if (int.TryParse(uniqueId, out int elementId))
                {
                    var element = document.GetElement(new ElementId(elementId));
                    if (element != null)
                    {
                        rvtElements.Add(element);
                    }
                }
                else
                {
                    var element = document.GetElement(uniqueId);
                    if (element != null)
                    {
                        rvtElements.Add(element);
                    }
                }

                foreach (var element in rvtElements)
                {
                    var cwElement = RvtToCwElementConverter.ConvertElementToCW_Element(element);
                    if (cwElement != null)
                    {
                        cwElements.Add(cwElement);
                    }
                }
            }

            return(cwElements);
        }
예제 #3
0
        /// <summary>
        /// Given the filter in use by a stream returns the document elements that match it.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        private List <Element> GetSelectionFilterObjects(ISelectionFilter filter)
        {
            var doc = CurrentDoc.Document;

            var selection = new List <Element>();

            switch (filter.Name)
            {
            case "Category":
                var catFilter  = filter as ListSelectionFilter;
                var bics       = new List <BuiltInCategory>();
                var categories = ConnectorRevitUtils.GetCategories(doc);
                IList <ElementFilter> elementFilters = new List <ElementFilter>();

                foreach (var cat in catFilter.Selection)
                {
                    elementFilters.Add(new ElementCategoryFilter(categories[cat].Id));
                }

                var categoryFilter = new LogicalOrFilter(elementFilters);

                selection = new FilteredElementCollector(doc)
                            .WhereElementIsNotElementType()
                            .WhereElementIsViewIndependent()
                            .WherePasses(categoryFilter).ToList();
                return(selection);

            case "View":
                var viewFilter = filter as ListSelectionFilter;

                var views = new FilteredElementCollector(doc)
                            .WhereElementIsNotElementType()
                            .OfClass(typeof(View))
                            .Where(x => viewFilter.Selection.Contains(x.Name));

                foreach (var view in views)
                {
                    var ids = selection.Select(x => x.UniqueId);

                    var viewElements = new FilteredElementCollector(doc, view.Id)
                                       .WhereElementIsNotElementType()
                                       .WhereElementIsViewIndependent()
                                       .Where(x => x.IsPhysicalElement())
                                       .Where(x => !ids.Contains(x.UniqueId)) //exclude elements already added from other views
                                       .ToList();

                    selection.AddRange(viewElements);
                }
                return(selection);

            case "Project Info":
                var projectInfoFilter = filter as ListSelectionFilter;

                if (projectInfoFilter.Selection.Contains("Project Info"))
                {
                    selection.Add(doc.ProjectInformation);
                }

                if (projectInfoFilter.Selection.Contains("Views 2D"))
                {
                    selection.AddRange(new FilteredElementCollector(doc)
                                       .WhereElementIsNotElementType()
                                       .OfCategory(BuiltInCategory.OST_Views)
                                       .Cast <View>()
                                       .Where(x => x.ViewType == ViewType.CeilingPlan ||
                                              x.ViewType == ViewType.FloorPlan ||
                                              x.ViewType == ViewType.Elevation ||
                                              x.ViewType == ViewType.Section)
                                       .ToList());
                }

                if (projectInfoFilter.Selection.Contains("Views 3D"))
                {
                    selection.AddRange(new FilteredElementCollector(doc)
                                       .WhereElementIsNotElementType()
                                       .OfCategory(BuiltInCategory.OST_Views)
                                       .Cast <View>()
                                       .Where(x => x.ViewType == ViewType.ThreeD)
                                       .ToList());
                }

                if (projectInfoFilter.Selection.Contains("Levels"))
                {
                    selection.AddRange(new FilteredElementCollector(doc)
                                       .WhereElementIsNotElementType()
                                       .OfCategory(BuiltInCategory.OST_Levels).ToList());
                }

                if (projectInfoFilter.Selection.Contains("Families & Types"))
                {
                    //get all the elementtypes of the categories we support
                    var allCategoryFilter = new LogicalOrFilter(ConnectorRevitUtils.GetCategories(doc).Select(x => new ElementCategoryFilter(x.Value.Id)).Cast <ElementFilter>().ToList());

                    selection.AddRange(new FilteredElementCollector(doc)
                                       .WhereElementIsElementType()
                                       .WherePasses(allCategoryFilter).ToList());
                }
                return(selection);

            case "Parameter":
                try
                {
                    var propFilter = filter as PropertySelectionFilter;
                    var query      = new FilteredElementCollector(doc)
                                     .WhereElementIsNotElementType()
                                     .WhereElementIsNotElementType()
                                     .WhereElementIsViewIndependent()
                                     .Where(x => x.IsPhysicalElement())
                                     .Where(fi => fi.LookupParameter(propFilter.PropertyName) != null);

                    propFilter.PropertyValue = propFilter.PropertyValue.ToLowerInvariant();

                    switch (propFilter.PropertyOperator)
                    {
                    case "equals":
                        query = query.Where(fi =>
                                            GetStringValue(fi.LookupParameter(propFilter.PropertyName)) == propFilter.PropertyValue);
                        break;

                    case "contains":
                        query = query.Where(fi =>
                                            GetStringValue(fi.LookupParameter(propFilter.PropertyName)).Contains(propFilter.PropertyValue));
                        break;

                    case "is greater than":
                        query = query.Where(fi => UnitUtils.ConvertFromInternalUnits(
                                                fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                                fi.LookupParameter(propFilter.PropertyName).DisplayUnitType) >
                                            double.Parse(propFilter.PropertyValue));
                        break;

                    case "is less than":
                        query = query.Where(fi => UnitUtils.ConvertFromInternalUnits(
                                                fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                                fi.LookupParameter(propFilter.PropertyName).DisplayUnitType) <
                                            double.Parse(propFilter.PropertyValue));
                        break;
                    }

                    selection = query.ToList();
                }
                catch (Exception e)
                {
                    Log.CaptureException(e);
                }
                return(selection);
            }

            return(selection);
        }
예제 #4
0
        public void Execute(UIApplication uiapp)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document; // myListView_ALL_Fam_Master.Items.Add(doc.GetElement(uidoc.Selection.GetElementIds().First()).Name);

                if (uidoc.Selection.GetElementIds().Count != 1)
                {
                    MessageBox.Show("Please select ONE Wall.");
                    return;
                }

                Element myElementWall = doc.GetElement(uidoc.Selection.GetElementIds().First());


                if (myElementWall.GetType() == typeof(FamilyInstance))
                {
                    FamilyInstance myFamilyInstance = myElementWall as FamilyInstance;

                    myElementWall = myFamilyInstance.Host;

                    if (myElementWall == null)
                    {
                        MessageBox.Show("Family instance must be hosted to a wall.");
                        return;
                    }
                }

                ///          TECHNIQUE 07 OF 19 (EE07_RotatingEntities.cs)
                ///↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ROTATING ENTITIES ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                ///
                /// Interfaces and ENUM's:
                ///
                ///
                /// Demonstrates classes:
                ///     FamilyInstance
                ///     Line
                ///     Wall
                ///     Curve
                ///     ElementTransformUtils
                ///
                ///
                /// Key methods:
                ///     ((LocationPoint)myFamilyInstance.Location).Point;
                ///     Line.CreateUnbound(
                ///     myFamilyInstance.GetTransform().BasisZ
                ///
                ///     ((LocationCurve)myWall.Location).Curve
                ///     XYZ myXYZ = (myCurve.GetEndPoint(1) + myCurve.GetEndPoint(0)) / 2;
                ///
                ///     ElementTransformUtils.RotateElement(
                ///
                ///
                ///
                ///	https://github.com/joshnewzealand/Revit-API-Playpen-CSharp
                ///

                List <Element> myListOfStuffOnWall = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_GenericModel).Where(x => (((FamilyInstance)x).Host != null)).Where(x => ((FamilyInstance)x).Host.Id == myElementWall.Id).ToList();
                List <Element> myListOfFurniture   = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Furniture).Where(x => (((FamilyInstance)x).Host != null)).Where(x => ((FamilyInstance)x).Host.Id == myElementWall.Id).ToList();
                myListOfStuffOnWall.AddRange(myListOfFurniture);

                if (myListOfStuffOnWall.Count() > 0)
                {
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Rotate People");

                        foreach (FamilyInstance myFI in myListOfStuffOnWall)
                        {
                            FamilyInstance myFamilyInstance = myFI as FamilyInstance;

                            XYZ myXYZInstance = ((LocationPoint)myFamilyInstance.Location).Point;

                            Line myLineBasisY = Line.CreateUnbound(myXYZInstance, myFamilyInstance.GetTransform().BasisZ); //  tf_01072_4 = Transform.CreateRotation(myTransform_FakeBasis2.BasisZ, d1 / 10 * myInt_DivideInteger);

                            ElementTransformUtils.RotateElement(doc, myFamilyInstance.Id, myLineBasisY, Math.PI / 4);
                        }

                        tx.Commit();
                    }
                }

                if (myWindow1.myCheckBoxWithWall.IsChecked.Value)
                {
                    if (myElementWall.Category.Name == "Walls")
                    {
                        Wall myWall = myElementWall as Wall;

                        using (Transaction tx = new Transaction(doc))
                        {
                            tx.Start("Rotate Wall");

                            Curve myCurve = ((LocationCurve)myWall.Location).Curve;

                            XYZ myXYZ = (myCurve.GetEndPoint(1) + myCurve.GetEndPoint(0)) / 2;

                            Line myLineBasisZ = Line.CreateUnbound(myXYZ, XYZ.BasisZ);

                            ElementTransformUtils.RotateElement(doc, myWall.Id, myLineBasisZ, Math.PI / 20);

                            tx.Commit();
                        }
                    }
                }
            }
            #region catch and finally
            catch (Exception ex)
            {
                _952_PRLoogleClassLibrary.DatabaseMethods.writeDebug("EE07_RotatingEntities" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true);
            }
            finally
            {
            }
            #endregion
        }
예제 #5
0
        /// <summary>
        /// Given the filter in use by a stream returns the document elements that match it.
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        private List <Element> GetSelectionFilterObjects(ISelectionFilter filter)
        {
            var doc = CurrentDoc.Document;

            var selection = new List <Element>();

            switch (filter.Slug)
            {
            case "all":
                selection.AddRange(doc.SupportedElements()); // includes levels
                selection.Add(doc.ProjectInformation);
                selection.AddRange(doc.Views2D());
                selection.AddRange(doc.Views3D());
                selection.AddRange(doc.SupportedTypes());
                return(selection);

            case "category":
                var catFilter  = filter as ListSelectionFilter;
                var bics       = new List <BuiltInCategory>();
                var categories = ConnectorRevitUtils.GetCategories(doc);
                IList <ElementFilter> elementFilters = new List <ElementFilter>();

                foreach (var cat in catFilter.Selection)
                {
                    elementFilters.Add(new ElementCategoryFilter(categories[cat].Id));
                }

                var categoryFilter = new LogicalOrFilter(elementFilters);

                selection = new FilteredElementCollector(doc)
                            .WhereElementIsNotElementType()
                            .WhereElementIsViewIndependent()
                            .WherePasses(categoryFilter).ToList();
                return(selection);

            case "view":
                var viewFilter = filter as ListSelectionFilter;

                var views = new FilteredElementCollector(doc)
                            .WhereElementIsNotElementType()
                            .OfClass(typeof(View))
                            .Where(x => viewFilter.Selection.Contains(x.Name));

                foreach (var view in views)
                {
                    var ids = selection.Select(x => x.UniqueId);

                    var viewElements = new FilteredElementCollector(doc, view.Id)
                                       .WhereElementIsNotElementType()
                                       .WhereElementIsViewIndependent()
                                       .Where(x => x.IsPhysicalElement())
                                       .Where(x => !ids.Contains(x.UniqueId)) //exclude elements already added from other views
                                       .ToList();

                    selection.AddRange(viewElements);
                }
                return(selection);

            case "project-info":
                var projectInfoFilter = filter as ListSelectionFilter;

                if (projectInfoFilter.Selection.Contains("Project Info"))
                {
                    selection.Add(doc.ProjectInformation);
                }

                if (projectInfoFilter.Selection.Contains("Views 2D"))
                {
                    selection.AddRange(doc.Views2D());
                }

                if (projectInfoFilter.Selection.Contains("Views 3D"))
                {
                    selection.AddRange(doc.Views3D());
                }

                if (projectInfoFilter.Selection.Contains("Levels"))
                {
                    selection.AddRange(doc.Levels());
                }

                if (projectInfoFilter.Selection.Contains("Families & Types"))
                {
                    selection.AddRange(doc.SupportedTypes());
                }

                return(selection);

            case "param":
                try
                {
                    var propFilter = filter as PropertySelectionFilter;
                    var query      = new FilteredElementCollector(doc)
                                     .WhereElementIsNotElementType()
                                     .WhereElementIsNotElementType()
                                     .WhereElementIsViewIndependent()
                                     .Where(x => x.IsPhysicalElement())
                                     .Where(fi => fi.LookupParameter(propFilter.PropertyName) != null);

                    propFilter.PropertyValue = propFilter.PropertyValue.ToLowerInvariant();

                    switch (propFilter.PropertyOperator)
                    {
                    case "equals":
                        query = query.Where(fi =>
                                            GetStringValue(fi.LookupParameter(propFilter.PropertyName)) == propFilter.PropertyValue);
                        break;

                    case "contains":
                        query = query.Where(fi =>
                                            GetStringValue(fi.LookupParameter(propFilter.PropertyName)).Contains(propFilter.PropertyValue));
                        break;

                    case "is greater than":
                        query = query.Where(fi => RevitVersionHelper.ConvertFromInternalUnits(
                                                fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                                fi.LookupParameter(propFilter.PropertyName)) >
                                            double.Parse(propFilter.PropertyValue));
                        break;

                    case "is less than":
                        query = query.Where(fi => RevitVersionHelper.ConvertFromInternalUnits(
                                                fi.LookupParameter(propFilter.PropertyName).AsDouble(),
                                                fi.LookupParameter(propFilter.PropertyName)) <
                                            double.Parse(propFilter.PropertyValue));
                        break;
                    }

                    selection = query.ToList();
                }
                catch (Exception e)
                {
                    Log.CaptureException(e);
                }
                return(selection);
            }

            return(selection);
        }
예제 #6
0
        public void Execute(UIApplication uiapp)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document; // myListView_ALL_Fam_Master.Items.Add(doc.GetElement(uidoc.Selection.GetElementIds().First()).Name);

                if (uidoc.Selection.GetElementIds().Count != 1)
                {
                    MessageBox.Show("Please select ONE Wall.");
                    return;
                }

                Element myElementWall = doc.GetElement(uidoc.Selection.GetElementIds().First());

                if (myElementWall.GetType() == typeof(FamilyInstance))
                {
                    FamilyInstance myFamilyInstance = myElementWall as FamilyInstance;

                    myElementWall = myFamilyInstance.Host;

                    if (myElementWall == null)
                    {
                        MessageBox.Show("Family instance must be hosted to a wall.");
                        return;
                    }
                }

                ///                             TECHNIQUE 08 OF 19 (EE08_MoveElementAroundHostingSurface.cs)
                ///↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ MOVING ELEMENTS AROUND A HOSTING SURFACE ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                /// The people walk around the perimeter of the wall, and it will work on any surface
                ///
                ///
                /// Interfaces and ENUM's:
                ///
                ///
                /// Demonstrates classes:
                ///     Reference
                ///     Face
                ///     Transform
                ///     PlanarFace
                ///     CurveLoop
                ///
                ///
                /// Key methods:
                ///     myElementWall.GetGeometryObjectFromReference(pickedRef) as Face
                ///     pickedRef.ConvertToStableRepresentation(doc).Contains("INSTANCE"))
                ///     (myElementWall as FamilyInstance).GetTotalTransform();
                ///     myFace.GetBoundingBox().Min
                ///     myFace.Evaluate(myUV_Min)
                ///
                ///     myXYZ_FamilyTransform.OfPoint(myXYZ_CornerOne)
                ///     myXYZ_FamilyTransform.OfVector(myPlanarFace.XVector);
                ///     myCurveLoop.GetExactLength();
                ///
                ///
                ///     L1.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong);
                ///	ElementTransformUtils.MoveElement(doc, myFamilyInstance.Id, myXYZ_MoveThisMuch);
                ///
                /// * class is actually part of the .NET framework (not Revit API)
                ///
                ///
                ///
                ///	https://github.com/joshnewzealand/Revit-API-Playpen-CSharp

                List <Element> myListOfStuffOnWall = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_GenericModel).Where(x => (((FamilyInstance)x).Host != null)).Where(x => ((FamilyInstance)x).Host.Id == myElementWall.Id).ToList();
                List <Element> myListOfFurniture   = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Furniture).Where(x => (((FamilyInstance)x).Host != null)).Where(x => ((FamilyInstance)x).Host.Id == myElementWall.Id).ToList();
                myListOfStuffOnWall.AddRange(myListOfFurniture);

                if (myListOfStuffOnWall.Count() > 0)
                {
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Rotate People");

                        foreach (FamilyInstance myFI in myListOfStuffOnWall)
                        {
                            FamilyInstance myFamilyInstance = myFI as FamilyInstance;

                            Reference pickedRef = myFI.HostFace;

                            ////doc.Delete(myListElementID);
                            ////myListElementID.Clear();

                            Face myFace = myElementWall.GetGeometryObjectFromReference(pickedRef) as Face;
                            if (myFace == null)
                            {
                                return;
                            }

                            Transform myXYZ_FamilyTransform = Transform.Identity;

                            if (pickedRef.ConvertToStableRepresentation(doc).Contains("INSTANCE"))
                            {
                                myXYZ_FamilyTransform = (myElementWall as FamilyInstance).GetTotalTransform();
                            }

                            Transform myTransform = Transform.Identity;

                            if (myFace.GetType() != typeof(PlanarFace))
                            {
                                return;
                            }

                            PlanarFace myPlanarFace = myFace as PlanarFace;

                            UV myUV_Min = myFace.GetBoundingBox().Min;
                            UV myUV_Max = myFace.GetBoundingBox().Max;

                            XYZ myXYZ_CornerOne = myFace.Evaluate(myUV_Min);

                            myTransform.Origin = myXYZ_FamilyTransform.OfPoint(myXYZ_CornerOne);
                            myTransform.BasisX = myXYZ_FamilyTransform.OfVector(myPlanarFace.XVector);
                            myTransform.BasisY = myXYZ_FamilyTransform.OfVector(myPlanarFace.YVector);
                            myTransform.BasisZ = myXYZ_FamilyTransform.OfVector(myPlanarFace.FaceNormal);

                            XYZ myXYZ_Centre = XYZ.Zero;

                            XYZ myXYZ_Min = new XYZ(myUV_Min.U, myUV_Min.V, 0);
                            XYZ myXYZ_Max = new XYZ(myUV_Max.U, myUV_Max.V, 0);

                            XYZ myXYZ_UV_CornerOne = (((myXYZ_Max - myXYZ_Min) * 0.1)); //; + myXYZ_Min;
                            XYZ myXYZ_UV_CornerTwo = (((myXYZ_Max - myXYZ_Min) * 0.9)); // + myXYZ_Min;

                            XYZ myXYZ_UV_Corner01 = new XYZ(myXYZ_UV_CornerOne.X, myXYZ_UV_CornerOne.Y, 0);
                            XYZ myXYZ_UV_Corner02 = new XYZ(myXYZ_UV_CornerTwo.X, myXYZ_UV_CornerOne.Y, 0);
                            XYZ myXYZ_UV_Corner03 = new XYZ(myXYZ_UV_CornerTwo.X, myXYZ_UV_CornerTwo.Y, 0);
                            XYZ myXYZ_UV_Corner04 = new XYZ(myXYZ_UV_CornerOne.X, myXYZ_UV_CornerTwo.Y, 0);

                            Line L1 = Line.CreateBound(myTransform.OfPoint(myXYZ_UV_Corner01), myTransform.OfPoint(myXYZ_UV_Corner02));
                            Line L2 = Line.CreateBound(myTransform.OfPoint(myXYZ_UV_Corner02), myTransform.OfPoint(myXYZ_UV_Corner03));
                            Line L3 = Line.CreateBound(myTransform.OfPoint(myXYZ_UV_Corner03), myTransform.OfPoint(myXYZ_UV_Corner04));
                            Line L4 = Line.CreateBound(myTransform.OfPoint(myXYZ_UV_Corner04), myTransform.OfPoint(myXYZ_UV_Corner01));

                            CurveLoop myCurveLoop = new CurveLoop();
                            myCurveLoop.Append(L1);
                            myCurveLoop.Append(L2);
                            myCurveLoop.Append(L3);
                            myCurveLoop.Append(L4);

                            double myDouble_ExactLength        = myCurveLoop.GetExactLength();
                            double myDouble_ExactLength_Twenty = myDouble_ExactLength / 40;

                            XYZ myXYZ_Result = myTransform.OfPoint((myXYZ_Max - myXYZ_Min) / 2);

                            int myIntCurrentSpinnerValue = myWindow1.myIntegerUpDown_OneToTwentyCount.Value.Value;
                            int myInt_Positioning        = (40 / myListOfStuffOnWall.Count()) * (myListOfStuffOnWall.IndexOf(myFI) + 1);
                            myIntCurrentSpinnerValue = (40 - myInt_Positioning) + myIntCurrentSpinnerValue;
                            if (myIntCurrentSpinnerValue > 40)
                            {
                                myIntCurrentSpinnerValue = myIntCurrentSpinnerValue - 40;
                            }
                            double myDouble_FutureForeach = myDouble_ExactLength_Twenty * myIntCurrentSpinnerValue;
                            double myDouble_ThisFarAlong;

                            switch (myDouble_FutureForeach)
                            {
                            case double n when n < L1.Length:

                                myDouble_ThisFarAlong = myDouble_FutureForeach;
                                myXYZ_Result          = L1.GetEndPoint(0) + (L1.GetEndPoint(1) - L1.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong);

                                break;

                            case double n when n >= L1.Length& n < L1.Length + L2.Length:

                                myDouble_ThisFarAlong = myDouble_FutureForeach - L1.Length;
                                myXYZ_Result          = L2.GetEndPoint(0) + (L2.GetEndPoint(1) - L2.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong);

                                break;

                            case double n when n >= L1.Length + L2.Length& n < L1.Length + L2.Length + L3.Length:

                                myDouble_ThisFarAlong = myDouble_FutureForeach - L1.Length - L2.Length;
                                myXYZ_Result          = L3.GetEndPoint(0) + (L3.GetEndPoint(1) - L3.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong);

                                break;

                            case double n when n >= L1.Length + L2.Length + L3.Length:

                                myDouble_ThisFarAlong = myDouble_FutureForeach - L1.Length - L2.Length - L3.Length;
                                myXYZ_Result          = L4.GetEndPoint(0) + (L4.GetEndPoint(1) - L4.GetEndPoint(0)).Normalize().Multiply(myDouble_ThisFarAlong);

                                break;
                            }

                            XYZ myXYZ_MoveThisMuch = myXYZ_Result - ((LocationPoint)myFamilyInstance.Location).Point;
                            ElementTransformUtils.MoveElement(doc, myFamilyInstance.Id, myXYZ_MoveThisMuch);

                            //SketchPlane mySketchPlane = SketchPlane.Create(doc, pickedRef);
                            //myListElementID.Add(doc.Create.NewModelCurve(L1, mySketchPlane).Id);
                            //myListElementID.Add(doc.Create.NewModelCurve(L2, mySketchPlane).Id);
                            //myListElementID.Add(doc.Create.NewModelCurve(L3, mySketchPlane).Id);
                            //myListElementID.Add(doc.Create.NewModelCurve(L4, mySketchPlane).Id);
                        }
                        tx.Commit();
                    }
                    if (myWindow1.myIntegerUpDown_OneToTwentyCount.Value.Value == 40)
                    {
                        myWindow1.myIntegerUpDown_OneToTwentyCount.Value = 0;
                    }
                    myWindow1.myIntegerUpDown_OneToTwentyCount.Value++;
                }
            }
            #region catch and finally
            catch (Exception ex)
            {
                DatabaseMethods.writeDebug("EE08_MoveElementAroundHostingSurface" + Environment.NewLine + ex.Message + Environment.NewLine + ex.InnerException, true);
            }
            finally
            {
            }
            #endregion
        }
예제 #7
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("ElementsElevation"));

            Document doc = commandData.Application.ActiveUIDocument.Document;

            Config cfg = Config.Activate(false);

            if (cfg == null)
            {
                Debug.WriteLine("Unable to read config xml file");
                return(Result.Cancelled);
            }

            List <FamilyInstance> fams = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).Cast <FamilyInstance>().ToList();

            List <FamilyInstance> famsHoles = new List <FamilyInstance>();

            List <Element> ColumnsAndWalls = new FilteredElementCollector(doc)
                                             .WhereElementIsNotElementType()
                                             .OfClass(typeof(FamilyInstance))
                                             .OfCategory(BuiltInCategory.OST_StructuralColumns)
                                             .ToList();

            ColumnsAndWalls.AddRange(new FilteredElementCollector(doc).OfClass(typeof(Wall)).ToList());
            Debug.WriteLine("Columns and wall found: " + ColumnsAndWalls.Count);


            int ColumnAndWallsCount = 0;

            Parameter paramBaseLevelElev;
            Parameter paramElevOnLevel;

            foreach (FamilyInstance fi in fams)
            {
                string famname = fi.Symbol.FamilyName;
                if (string.IsNullOrEmpty(famname))
                {
                    continue;
                }
                int prefixLength = cfg.namePrefixes.First().Length;
                if (famname.Length <= prefixLength)
                {
                    continue;
                }
                string firstSymbols = famname.Substring(0, prefixLength);
                if (cfg.namePrefixes.Contains(firstSymbols))
                {
                    paramBaseLevelElev = fi.LookupParameter(cfg.paramBaseLevel);
                    paramElevOnLevel   = fi.LookupParameter(cfg.paramElevOnLevel);

                    if (paramBaseLevelElev != null && paramElevOnLevel != null)
                    {
                        famsHoles.Add(fi);
                    }
                }
            }
            Debug.WriteLine("Holes found: " + famsHoles.Count);

            Level  baseLevel = null;
            double elev      = 0;
            int    count     = 0;
            int    err       = 0;

            BasePoint projectBasePoint = new FilteredElementCollector(doc)
                                         .OfClass(typeof(BasePoint))
                                         .WhereElementIsNotElementType()
                                         .Cast <BasePoint>()
                                         .Where(i => i.IsShared == false)
                                         .First();
            double projectPointElevation = projectBasePoint.get_BoundingBox(null).Min.Z;

            Debug.WriteLine("Project base point elevation: " + (projectPointElevation * 304.8).ToString());

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Transaction");
                if (famsHoles.Count == 0 && ColumnsAndWalls.Count == 0)
                {
                    TaskDialog.Show("Holes elevation", "Семейства не найдены. Проверьте настройки");
                    return(Result.Failed);
                }
                else
                {
                    foreach (FamilyInstance fi in famsHoles)
                    {
                        Debug.WriteLine("Current family: " + fi.Id.IntegerValue);
                        baseLevel = LevelUtils.GetBaseLevelofElement(fi);

                        if (baseLevel != null) //обычные семейства на основе стены
                        {
                            elev = LevelUtils.GetOffsetFromLevel(fi);
                        }
                        else //семейства без основы - худший вариант; у семейства нет ни уровня, ни основы. ищу ближайший уровень через координаты
                        {
                            Debug.WriteLine("Family is without base level!");
                            LocationPoint lp = fi.Location as LocationPoint;
                            if (lp == null)
                            {
                                Debug.WriteLine("No location point");
                                continue;
                            }

                            XYZ point = lp.Point;
                            Debug.WriteLine("Location point: " + point.ToString());
                            baseLevel = LevelUtils.GetNearestLevel(point, doc, projectPointElevation);


                            if (baseLevel == null)
                            {
                                message += "Не удалось получить уровень для элемента " + fi.Name + " id " + fi.Id;
                                message += " на отметке " + (point.Z * 304.8).ToString("F0");
                                Debug.WriteLine("Unable to get level. " + message);
                                elements.Insert(fi);
                            }
                            elev = point.Z - baseLevel.Elevation - projectPointElevation;
                            Debug.WriteLine("Nearest level id: " + baseLevel.Id.IntegerValue + ", elev: " + elev.ToString("F1"));
                        }

                        GetParameter(fi, cfg.paramElevOnLevel, true).Set(elev);
                        GetParameter(fi, cfg.paramBaseLevel, true).Set(baseLevel.Elevation);
                        count++;
                    }
                }
                Debug.WriteLine("Families done: " + count);

                if (cfg.useWallAndColumns)
                {
                    Debug.WriteLine("Start wall and columns processing");
                    foreach (Element elem in ColumnsAndWalls)
                    {
                        Debug.WriteLine("Current elem id: " + elem.Id.IntegerValue);
                        Parameter baseLevelParam  = null;
                        Parameter baseOffsetParam = null;
                        Parameter topLevelParam   = null;
                        Parameter topOffsetParam  = null;

                        if (elem is FamilyInstance)
                        {
                            Debug.WriteLine("It is column");
                            FamilyInstance col = elem as FamilyInstance;
                            baseLevelParam  = col.get_Parameter(BuiltInParameter.SCHEDULE_BASE_LEVEL_PARAM);
                            baseOffsetParam = col.get_Parameter(BuiltInParameter.SCHEDULE_BASE_LEVEL_OFFSET_PARAM);
                            topLevelParam   = col.get_Parameter(BuiltInParameter.SCHEDULE_TOP_LEVEL_PARAM);
                            topOffsetParam  = col.get_Parameter(BuiltInParameter.SCHEDULE_TOP_LEVEL_OFFSET_PARAM);
                        }
                        else if (elem is Wall)
                        {
                            Debug.WriteLine("It is wall");
                            Wall w = elem as Wall;
                            baseLevelParam  = w.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
                            baseOffsetParam = w.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
                            topLevelParam   = w.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE);
                            topOffsetParam  = w.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET);
                        }

                        if (baseLevelParam == null || baseOffsetParam == null || topLevelParam == null || topOffsetParam == null)
                        {
                            Debug.WriteLine("Incorrect level or height parameters");
                            continue;
                        }

                        Level baseLev = doc.GetElement(baseLevelParam.AsElementId()) as Level;
                        if (baseLev == null)
                        {
                            Debug.WriteLine("No base level");
                            continue;
                        }
                        double baseLevElev = baseLev.Elevation;
                        double baseOffset  = baseOffsetParam.AsDouble();
                        double baseElev    = baseLevElev + baseOffset;

                        Level  topLev  = doc.GetElement(topLevelParam.AsElementId()) as Level;
                        double topElev = 0;
                        if (topLev == null)
                        {
                            if (elem is Wall)
                            {
                                double heigth = elem.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
                                topElev = baseElev + heigth;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            double topLevElev = topLev.Elevation;
                            double topOffset  = topOffsetParam.AsDouble();
                            topElev = topLevElev + topOffset;
                        }

                        SetElevParamValue(elem, baseElev, cfg.paramBottomElevName, cfg);
                        SetElevParamValue(elem, topElev, cfg.paramTopElevName, cfg);

                        ColumnAndWallsCount++;
                        Debug.WriteLine("Walls and columns done: " + ColumnAndWallsCount);

                        //заполняю сокращенную марку
                        //Parameter shortMarkParam = elem.LookupParameter("МаркаСокращенная");
                        //if (shortMarkParam == null) continue;
                        //Parameter markParam = elem.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
                        //if (markParam == null) continue;
                        //if (!markParam.HasValue) continue;
                        //string mark = markParam.AsString();
                        //if (string.IsNullOrEmpty(mark)) continue;
                        //string[] markArray = mark.Split('-');
                        //if (markArray.Length < 3) continue;
                        //string shortMark = markArray[0] + "-" + markArray[2];
                        //shortMarkParam.Set(shortMark);
                    }
                }

                t.Commit();
            }

            string msg = "Найдено проемов и отверстий: " + famsHoles.Count.ToString()
                         + "\nОбработано семейств: " + count
                         + "\nНе удалось обработать: " + err;

            if (cfg.useWallAndColumns)
            {
                msg += "\nЕще обработано колонн и стен: " + ColumnAndWallsCount;
            }
            Debug.WriteLine(msg);
            BalloonTip.Show("Holes elevation", msg);

            cfg.Save();
            return(Result.Succeeded);
        }