Esempio n. 1
0
            public static ReferencePoint RequestReferencePointSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                ReferencePoint rp = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                dynSettings.DynamoLogger.Log(message);

                //create some geometry options so that we computer references
                //var opts = new Options
                //{
                //    ComputeReferences = true,
                //    DetailLevel = ViewDetailLevel.Medium,
                //    IncludeNonVisibleObjects = false
                //};

                Reference pointRef = doc.Selection.PickObject(ObjectType.Element);

                if (pointRef != null)
                {
                    rp =
                        DocumentManager.Instance.CurrentUIDocument.Document.GetElement(pointRef) as
                        ReferencePoint;
                }
                return(rp);
            }
Esempio n. 2
0
            public static Form RequestFormSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                Form f = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                DynamoLogger.Instance.Log(message);

                //create some geometry options so that we computer references
                var opts = new Options
                {
                    ComputeReferences        = true,
                    DetailLevel              = ViewDetailLevel.Medium,
                    IncludeNonVisibleObjects = false
                };

                Reference formRef = doc.Selection.PickObject(ObjectType.Element);

                if (formRef != null)
                {
                    //the suggested new method didn't exist in API?
                    f = dynRevitSettings.Doc.Document.GetElement(formRef) as Form;
                }
                return(f);
            }
Esempio n. 3
0
        /// <summary>
        /// Pick Faces in the current Revit Document.  Don't forget to hit the Finished button in the options bar.
        /// </summary>
        /// <param name="message">A message to be displayed in the status bar.</param>
        /// <param name="reset">Resets the node so one can pick new objects.</param>
        /// <returns name="Faces">List of the selected faces.</returns>
        public static List <DynElem> Faces(
            [DefaultArgument("Select elements")] string message,
            [DefaultArgument("true")] bool reset)
        {
            Autodesk.Revit.UI.UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            RevitDoc doc = DocumentManager.Instance.CurrentDBDocument;

            List <DynElem> elems = new List <DynElem>();

            revitSelect.Selection selection = uiapp.ActiveUIDocument.Selection;

            try
            {
                IList <Reference> references = selection.PickObjects(revitSelect.ObjectType.Face, message);
                foreach (Reference r in references)
                {
                    DynElem elem = doc.GetElement(r.ElementId).ToDSType(true);
                    elems.Add(elem);
                }
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException e)
            {
                return(null);
            }

            return(elems);
        }
Esempio n. 4
0
            public static Face RequestFaceSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                Face f = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                DynamoLogger.Instance.Log(message);

                //create some geometry options so that we computer references
                var opts = new Options
                {
                    ComputeReferences        = true,
                    DetailLevel              = ViewDetailLevel.Medium,
                    IncludeNonVisibleObjects = false
                };

                Reference faceRef = doc.Selection.PickObject(ObjectType.Face);

                if (faceRef != null)
                {
                    GeometryObject geob = dynRevitSettings.Doc.Document.GetElement(faceRef).GetGeometryObjectFromReference(faceRef);
                    f = geob as Face;
                }
                return(f);
            }
Esempio n. 5
0
            public static FamilyInstance RequestFamilyInstanceSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                try
                {
                    Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                    choices.Elements.Clear();

                    //MessageBox.Show(message);
                    dynSettings.Controller.DynamoViewModel.Log(message);

                    Reference fsRef = doc.Selection.PickObject(ObjectType.Element);

                    if (fsRef != null)
                    {
                        return(doc.Document.GetElement(fsRef.ElementId) as FamilyInstance);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    dynSettings.Controller.DynamoViewModel.Log(ex);
                    return(null);
                }
            }
Esempio n. 6
0
            public static FamilyInstance RequestFamilyInstanceSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                try
                {
                    Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                    choices.Elements.Clear();

                    //MessageBox.Show(message);
                    dynSettings.DynamoLogger.Log(message);

                    Reference fsRef = doc.Selection.PickObject(ObjectType.Element);

                    if (fsRef != null)
                    {
                        return(doc.Document.GetElement(fsRef.ElementId) as FamilyInstance);
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    dynSettings.DynamoLogger.Log(ex);
                    return(null);
                }
            }
Esempio n. 7
0
            public static ReferencePoint RequestReferencePointSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                ReferencePoint rp = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                dynSettings.Controller.DynamoViewModel.Log(message);

                //create some geometry options so that we computer references
                var opts = new Options
                {
                    ComputeReferences        = true,
                    DetailLevel              = ViewDetailLevel.Medium,
                    IncludeNonVisibleObjects = false
                };

                Reference pointRef = doc.Selection.PickObject(ObjectType.Element);

                if (pointRef != null)
                {
                    rp = dynRevitSettings.Doc.Document.GetElement(pointRef) as ReferencePoint;
                }
                return(rp);
            }
Esempio n. 8
0
            public static Element RequestModelElementSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                Element selectedElement = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                dynSettings.DynamoLogger.Log(message);

                Reference fsRef = doc.Selection.PickObject(ObjectType.Element);

                if (fsRef != null)
                {
                    selectedElement = doc.Document.GetElement(fsRef.ElementId);
                    if (selectedElement is FamilyInstance || selectedElement is HostObject ||
                        selectedElement is ImportInstance || selectedElement is CombinableElement)
                    {
                        return(selectedElement);
                    }
                }

                return(selectedElement);
            }
Esempio n. 9
0
            public static Element RequestAnalysisResultInstanceSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                try
                {
                    View view = doc.ActiveView as View;

                    SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view);
                    Element             AnalysisResult;

                    if (sfm != null)
                    {
                        sfm.GetRegisteredResults();

                        Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                        choices.Elements.Clear();

                        //MessageBox.Show(message);
                        DynamoLogger.Instance.Log(message);

                        Reference fsRef = doc.Selection.PickObject(ObjectType.Element);

                        if (fsRef != null)
                        {
                            AnalysisResult = doc.Document.GetElement(fsRef.ElementId) as Element;

                            if (AnalysisResult != null)
                            {
                                return(AnalysisResult);
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    DynamoLogger.Instance.Log(ex);
                    return(null);
                }
            }
Esempio n. 10
0
            // MDJ TODO - this is really hacky. I want to just use the face but evaluating the ref fails later on in pointOnSurface, the ref just returns void, not sure why.
            public static Reference RequestFaceReferenceSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;
                choices.Elements.Clear();

                dynSettings.DynamoLogger.Log(message);
                Reference faceRef = doc.Selection.PickObject(ObjectType.Face);

                return(faceRef);
            }
Esempio n. 11
0
            public static Reference RequestEdgeReferenceSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;
                choices.Elements.Clear();

                dynSettings.Controller.DynamoViewModel.Log(message);

                Reference edgeRef = doc.Selection.PickObject(ObjectType.Edge);

                return(edgeRef);
            }
Esempio n. 12
0
            public static Reference RequestReferenceXYZSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;
                choices.Elements.Clear();

                dynSettings.Controller.DynamoLogger.Log(message);

                Reference xyzRef = doc.Selection.PickObject(ObjectType.PointOnElement);

                return(xyzRef);
            }
Esempio n. 13
0
            public static Reference RequestReferenceXYZSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;
                choices.Elements.Clear();

                DynamoLogger.Instance.Log(message);

                Reference xyzRef = doc.Selection.PickObject(ObjectType.PointOnElement);

                return(xyzRef);
            }
Esempio n. 14
0
            // MDJ TODO - this is really hacky. I want to just use the face but evaluating the ref fails later on in pointOnSurface, the ref just returns void, not sure why.
            public static Reference RequestFaceReferenceSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                Reference faceRef = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;
                choices.Elements.Clear();

                DynamoLogger.Instance.Log(message);
                faceRef = doc.Selection.PickObject(ObjectType.Face);

                return(faceRef);
            }
Esempio n. 15
0
            public static IList <Element> RequestMultipleCurveElementsSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;
                choices.Elements.Clear();

                dynSettings.DynamoLogger.Log(message);

                //var ca = new ElementArray();
                //ISelectionFilter selFilter = new CurveSelectionFilter();
                return(doc.Selection.PickElementsByRectangle(
                           //selFilter,
                           "Window select multiple curves."));
            }
Esempio n. 16
0
            public static IList <Element> RequestMultipleCurveElementsSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;
                choices.Elements.Clear();

                DynamoLogger.Instance.Log(message);

                var ca = new ElementArray();
                ISelectionFilter selFilter = new CurveSelectionFilter();

                return(doc.Selection.PickElementsByRectangle(//selFilter,
                           "Window select multiple curves.") as IList <Element>);
            }
Esempio n. 17
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            Autodesk.Revit.UI.Selection.Selection s1 = uidoc.Selection;
            XYZ point = null;

            try
            {
                point = s1.PickPoint("请选择一个点");
            }
            catch
            {
                return(Result.Succeeded);
            }
            Transaction t1 = new Transaction(doc, "t1");

            t1.Start();
            FamilySymbol familySymbol = doc.GetElement(new ElementId(52557)) as FamilySymbol;

            if (!familySymbol.IsActive)
            {
                familySymbol.Activate();
            }
            Level          level = null;
            FamilyInstance fi    = doc.Create.NewFamilyInstance(point, familySymbol, level, StructuralType.NonStructural);

            t1.Commit();

            Autodesk.Revit.UI.Selection.Selection s2 = uidoc.Selection;
            Reference       re    = s2.PickObject(ObjectType.Element, "请选择一个物体");
            Element         ele   = doc.GetElement(re);
            Options         opt   = new Options();
            GeometryElement gelem = ele.get_Geometry(opt);
            double          v     = 0.0;

            v = GetSolid(gelem).Sum(m => m.Volume) * 0.3048 * 0.3048 * 0.3048;
            TaskDialog.Show("Hint", "选中物体体积为:" + v.ToString("f3"));

            IList <Element> pickedElements = s2.PickElementsByRectangle(new WallSelectionfilter(), "请选择目标物体");
            double          num            = pickedElements.Count();

            TaskDialog.Show("Hint", "已选中的墙数为:" + num);

            return(Result.Succeeded);
        }
Esempio n. 18
0
            public static CurveElement RequestCurveElementSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                //MessageBox.Show(message);
                dynSettings.DynamoLogger.Log(message);

                Reference curveRef = doc.Selection.PickObject(ObjectType.Element);

                var c = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document.GetElement(
                    curveRef) as CurveElement;

                return(c);
            }
Esempio n. 19
0
            public static CurveElement RequestCurveElementSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                CurveElement c = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                //MessageBox.Show(message);
                DynamoLogger.Instance.Log(message);

                Reference curveRef = doc.Selection.PickObject(ObjectType.Element);

                c = dynRevitSettings.Revit.ActiveUIDocument.Document.GetElement(curveRef) as CurveElement;

                return(c);
            }
Esempio n. 20
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            Autodesk.Revit.UI.Selection.Selection selElement = uidoc.Selection;
            Autodesk.Revit.DB.Document            doc        = uidoc.Document;

            foreach (ElementId eleId in selElement.GetElementIds())
            {
                Element ele = doc.GetElement(eleId);
                // Get the group's center point
                XYZ origin = GetElementCenter(ele);
                // Get the room that the picked group is located in
                Room room = GetRoomOfGroup(doc, origin);
                MessageBox.Show("The item you have selected is in the room: " + room.Name);
            }


            return(Result.Succeeded);
        }
Esempio n. 21
0
            public static FamilySymbol RequestFamilySymbolByInstanceSelection(string message, ref FamilyInstance fi)
            {
                var doc = dynRevitSettings.Doc;

                try
                {
                    //FamilySymbol fs = null;

                    Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                    choices.Elements.Clear();

                    //MessageBox.Show(message);
                    DynamoLogger.Instance.Log(message);

                    Reference fsRef = doc.Selection.PickObject(ObjectType.Element);

                    if (fsRef != null)
                    {
                        fi = doc.Document.GetElement(fsRef) as FamilyInstance;

                        if (fi != null)
                        {
                            return(fi.Symbol);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    DynamoLogger.Instance.Log(ex);
                    return(null);
                }
            }
Esempio n. 22
0
            public static Form RequestFormSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                Form f = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                dynSettings.DynamoLogger.Log(message);

                Reference formRef = doc.Selection.PickObject(ObjectType.Element);

                if (formRef != null)
                {
                    //the suggested new method didn't exist in API?
                    f = DocumentManager.Instance.CurrentUIDocument.Document.GetElement(formRef) as Form;
                }
                return(f);
            }
Esempio n. 23
0
            public static Element RequestLevelSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                Level l = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                //MessageBox.Show(message);
                dynSettings.DynamoLogger.Log(message);

                Reference fsRef = doc.Selection.PickObject(ObjectType.Element);

                if (fsRef != null)
                {
                    l = (Level)doc.Document.GetElement(fsRef.ElementId);
                }

                return(l);
            }
Esempio n. 24
0
            public static Element RequestLevelSelection(string message)
            {
                var doc = dynRevitSettings.Doc;

                Level l = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                //MessageBox.Show(message);
                dynSettings.Controller.DynamoViewModel.Log(message);

                Reference fsRef = doc.Selection.PickObject(ObjectType.Element);

                if (fsRef != null)
                {
                    l = (Level)doc.Document.GetElement(fsRef.ElementId);
                }

                return(l);
            }
Esempio n. 25
0
            public static Element RequestAnalysisResultInstanceSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                try
                {
                    View view = doc.ActiveView;

                    SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view);

                    if (sfm != null)
                    {
                        sfm.GetRegisteredResults();

                        Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                        choices.Elements.Clear();

                        //MessageBox.Show(message);
                        dynSettings.Controller.DynamoLogger.Log(message);

                        Reference fsRef = doc.Selection.PickObject(ObjectType.Element);

                        if (fsRef != null)
                        {
                            Element analysisResult = doc.Document.GetElement(fsRef.ElementId);

                            return(analysisResult);
                        }
                        return(null);
                    }
                    return(null);
                }
                catch (Exception ex)
                {
                    dynSettings.Controller.DynamoLogger.Log(ex);
                    return(null);
                }
            }
Esempio n. 26
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;


            //access to the Revit selection methods
            Autodesk.Revit.UI.Selection.Selection sel = uidoc.Selection;

            //provides a filtered selection
            ElementMulticategoryFilter multicategoryFilter = new ElementMulticategoryFilter(TargetCategories());
            var filter =
                Utilities.SelFilter.GetElementFilter(multicategoryFilter);

            //prompt the user for a selection
            IList <Reference> selectionReference;

            try
            {
                selectionReference = sel.PickObjects(ObjectType.Element, filter);
            }
            catch (Exception)
            {
                //land here if someone cancels the pick operation
                return(Result.Cancelled);
            }

            //try to export to JSON on the desktop
            bool result = RevitElementsToHypar(doc, selectionReference.Select(e => e.ElementId).ToList());

            if (result)
            {
                return(Result.Succeeded);
            }
            return(Result.Failed);
        }
Esempio n. 27
0
            public static Face RequestFaceSelection(string message)
            {
                UIDocument doc = DocumentManager.Instance.CurrentUIDocument;

                Face f = null;

                Autodesk.Revit.UI.Selection.Selection choices = doc.Selection;

                choices.Elements.Clear();

                dynSettings.DynamoLogger.Log(message);

                Reference faceRef = doc.Selection.PickObject(ObjectType.Face);

                if (faceRef != null)
                {
                    GeometryObject geob =
                        DocumentManager.Instance.CurrentUIDocument.Document.GetElement(faceRef)
                        .GetGeometryObjectFromReference(faceRef);
                    f = geob as Face;
                }
                return(f);
            }
Esempio n. 28
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("RebarSketch"));
            Debug.WriteLine("Start rebar scetch, revit version" + commandData.Application.Application.VersionName);


            Document doc = commandData.Application.ActiveUIDocument.Document;

            Debug.WriteLine("Read settings");
            //считываем файл настроек
            string activateMessage = SupportSettings.Activate();

            if (!string.IsNullOrEmpty(activateMessage))
            {
                message = activateMessage;
                Debug.WriteLine("Read settings failed: " + message);
                return(Result.Failed);
            }
            Debug.WriteLine("Read settings success");

            //выбираем арматуру, которую будем обрабатывать
            Autodesk.Revit.UI.Selection.Selection sel = commandData.Application.ActiveUIDocument.Selection;
            List <ElementId> selIds = sel.GetElementIds().ToList();

            //bool checkSelectionRebar = true;
            if (selIds.Count == 0)
            {
                message = "Перед запуском перейдите в Ведомость деталей, выберите все строчки и после этого запускайте плагин.";
                Debug.WriteLine("No selected elements");
                return(Result.Failed);
            }


            if (selIds.Count > 0)
            {
                ElementId selId   = selIds.First();
                Element   selElem = doc.GetElement(selId);
                if (selElem.Category.Id.IntegerValue != new ElementId(BuiltInCategory.OST_Rebar).IntegerValue)
                {
                    message = "Перед запуском перейдите в Ведомость деталей, выберите все строчки и после этого запускайте плагин.";
                    Debug.WriteLine("No selected rebar elements");
                    return(Result.Failed);
                }
            }

            List <Element> col = new List <Element>();

            foreach (ElementId rebarId in selIds)
            {
                Element elem = doc.GetElement(rebarId);
                col.Add(elem);
            }



            View         activeView = commandData.Application.ActiveUIDocument.ActiveView;
            ViewSchedule vs         = activeView as ViewSchedule;

            if (vs == null)
            {
                message = "Перед запуском перейдите в Ведомость деталей, выберите все строчки и после этого запускайте плагин.";
                Debug.WriteLine("Active view is not ViewSchedule");
                return(Result.Failed);
            }



            //очищаю ранее созданные картинки для данной ведомости деталей
            string           imagesPrefix = vs.Id.IntegerValue.ToString();
            List <ElementId> oldImageIds  = new FilteredElementCollector(doc)
                                            .WhereElementIsElementType()
                                            .OfClass(typeof(ImageType))
                                            .Where(i => i.Name.StartsWith(imagesPrefix))
                                            .Select(i => i.Id)
                                            .ToList();

            Debug.WriteLine("Old scetch images found: " + oldImageIds.Count.ToString());

            if (oldImageIds.Count > 0)
            {
                using (Transaction t1 = new Transaction(doc))
                {
                    t1.Start("Очистка");
                    doc.Delete(oldImageIds);
                    t1.Commit();
                }
            }



            ScetchLibrary lib = new ScetchLibrary();

            lib.Activate(SupportSettings.libraryPath);

            System.IO.Directory.CreateDirectory(SupportSettings.tempPath);
            Debug.WriteLine("Create temp folder: " + SupportSettings.tempPath);


            //разделяю арматуру на обычную и переменной длины
            List <Element> standartRebars = new List <Element>();
            List <Element> variableRebars = new List <Element>();

            foreach (Element rebar in col)
            {
                int checkIsVariable = RebarSketch.ScetchTemplate.CheckrebarIsVariableLength(rebar);
                if (checkIsVariable == -1)
                {
                    continue;
                }

                if (checkIsVariable == 0)
                {
                    standartRebars.Add(rebar);
                }
                else
                {
                    variableRebars.Add(rebar);
                }
            }

            Debug.WriteLine("Standart rebars: " + standartRebars.Count.ToString() + ", variable rebars: " + variableRebars.Count.ToString());


            //группировка арматуры переменной длины по марке
            Dictionary <string, List <Element> > variableRebarBase = new Dictionary <string, List <Element> >();

            foreach (Element vRebar in variableRebars)
            {
                string mark = vRebar.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString();
                if (mark == null)
                {
                    string msg = "Обнаружены арматурные стержни переменной длины, для которых не назначена Марки. ";
                    msg += "Группировка для таких стержней выполняется по Марке, которую нужно назначить заранее.";
                    Debug.WriteLine("Non-marked variable rebars is found");
                    TaskDialog.Show("Ошибка", msg);
                    return(Result.Failed);
                }

                if (variableRebarBase.ContainsKey(mark))
                {
                    variableRebarBase[mark].Add(vRebar);
                }
                else
                {
                    variableRebarBase.Add(mark, new List <Element> {
                        vRebar
                    });
                }
            }

            Dictionary <string, ScetchImage> imagesBase = new Dictionary <string, ScetchImage>();

            HashSet <string> errorRebarNames = new HashSet <string>();

            using (Transaction t2 = new Transaction(doc))
            {
                t2.Start("Ведомость деталей");

                //заполняю картинки для обычной арматуры
                foreach (Element rebar in standartRebars)
                {
                    string formName = ScetchTemplate.GetFormNameByElement(rebar);
                    if (formName == "")
                    {
                        continue;
                    }

                    ScetchTemplate st = lib.GetTemlateByFamilyName(formName, rebar);
                    if (st == null)
                    {
                        errorRebarNames.Add(formName);
                        continue;
                        //return Result.Failed;
                    }

                    //для арматуры округляем размеры, для закладных деталей (класс арматуры меньше нуля) - нет
                    bool roundForSmallDimension = SupportMath.CheckNeedsRoundSmallDimension(rebar);


                    foreach (ScetchParameter sparam in st.parameters)
                    {
                        string paramName = sparam.Name;

                        Parameter lengthParam = rebar.LookupParameter(paramName);
                        if (lengthParam == null)
                        {
                            message = "Параметр " + paramName + " не найден в " + SupportNames.GetElementName(rebar)
                                      + ". Возможно, нужно обновить семейство.";
                            Debug.WriteLine(message);
                            return(Result.Failed);
                        }

                        string textVal = lengthParam.Definition.Name;
                        double val     = lengthParam.AsDouble();


#if R2022
                        ForgeTypeId forgeType     = lengthParam.GetUnitTypeId();
                        string      unittype      = forgeType.TypeId;
                        bool        isMillimeters = unittype.Contains("millimeters");
                        bool        isDegrees     = unittype.Contains("degrees");
#else
                        bool isMillimeters = lengthParam.DisplayUnitType == DisplayUnitType.DUT_MILLIMETERS;
                        bool isDegrees     = lengthParam.DisplayUnitType == DisplayUnitType.DUT_DECIMAL_DEGREES;
#endif
                        if (isDegrees)
                        {
                            val          = SupportMath.RoundDegrees(val);
                            textVal      = val.ToString("F0") + "°";
                            sparam.value = textVal;
                        }
                        else
                        {
                            val          = SupportMath.RoundMillimeters(val, roundForSmallDimension);
                            textVal      = val.ToString("F0");
                            sparam.value = textVal;
                        }

                        Debug.WriteLine("ScetchParameter name " + sparam.Name + " value = " + textVal);
                    }

                    ScetchLibrary.SearchAndApplyScetch(imagesBase, rebar, st, imagesPrefix);
                }


                //заполняю картинки для арматуры переменной длины
                foreach (var kvp in variableRebarBase)
                {
                    string         mark   = kvp.Key;
                    List <Element> rebars = kvp.Value;

                    bool roundForSmallDimension = SupportMath.CheckNeedsRoundSmallDimension(rebars.First());

                    string         formName = ScetchTemplate.GetFormNameByElement(rebars.First());
                    ScetchTemplate st       = lib.GetTemlateByFamilyName(formName, rebars.First());
                    if (st == null)
                    {
                        errorRebarNames.Add(formName);
                        continue;
                    }

                    //получаю для каждого имени параметра список его возможных значений
                    Dictionary <string, HashSet <double> > variableValues = new Dictionary <string, HashSet <double> >();
                    foreach (Element rebar in rebars)
                    {
                        foreach (ScetchParameter sparam in st.parameters)
                        {
                            string    paramName   = sparam.Name;
                            Parameter lengthParam = rebar.LookupParameter(paramName);
                            if (lengthParam == null)
                            {
                                message = "Параметр " + paramName + " не найден в " + SupportNames.GetElementName(rebar)
                                          + ". Возможно, попытка свести в одну позицию стержни разной формы. "
                                          + ". При использовании арматуры \"Переменной длины\" следует вручную назначить разные \"Марки\" для стержней разных позиций.";
                                Debug.WriteLine("No found parameter " + paramName + " in element " + rebar.Id.IntegerValue.ToString());
                                return(Result.Failed);
                            }
                            double val = rebar.LookupParameter(paramName).AsDouble();
                            if (variableValues.ContainsKey(paramName))
                            {
                                variableValues[paramName].Add(val);
                            }
                            else
                            {
                                variableValues.Add(paramName, new HashSet <double> {
                                    val
                                });
                            }
                            Debug.WriteLine("Add variableValues " + paramName + " = " + val.ToString());
                        }
                    }

                    foreach (ScetchParameter sparam in st.parameters)
                    {
                        string           paramName = sparam.Name;
                        HashSet <double> values    = variableValues[paramName];
                        int    count    = values.Count();
                        double minValue = values.Min();
                        minValue = SupportMath.RoundMillimeters(minValue, roundForSmallDimension);
                        double maxValue = values.Max();
                        maxValue = SupportMath.RoundMillimeters(maxValue, roundForSmallDimension);
                        double spacing = (maxValue - minValue) / (count - 1);
                        spacing = SupportSettings.lengthAccuracy * Math.Round(spacing / SupportSettings.lengthAccuracy); //Math.Round(spacing, 0);

                        string line = "";

                        if (minValue == maxValue || count == 1)
                        {
                            sparam.value       = minValue.ToString("F0");
                            sparam.IsVariable  = false;
                            sparam.HaveSpacing = false;
                        }
                        else
                        {
                            if (count == 2)
                            {
                                sparam.value       = minValue.ToString("F0") + "..." + maxValue.ToString("F0");
                                sparam.IsVariable  = true;
                                sparam.HaveSpacing = false;
                            }
                            else
                            {
                                //sparam.value = minValue.ToString("F0") + "..." + maxValue.ToString("F0") + " (ш." + spacing.ToString("F0") + ")";
                                sparam.value        = minValue.ToString("F0") + "..." + maxValue.ToString("F0");
                                sparam.HaveSpacing  = true;
                                sparam.IsVariable   = true;
                                sparam.SpacingValue = "ш." + spacing.ToString("F0");
                            }
                        }
                    }

                    foreach (Element rebar in rebars)
                    {
                        Debug.WriteLine("Processed rebar id " + rebar.Id.IntegerValue.ToString());
                        ScetchImage si = new ScetchImage(rebar, st);

                        ScetchLibrary.SearchAndApplyScetch(imagesBase, rebar, st, imagesPrefix);
                    }
                }
                t2.Commit();
            }

            FileSupport.CheckAndDeleteFolder(SupportSettings.tempPath);

            if (errorRebarNames.Count > 0)
            {
                string errorFamilyMessage = "Не удалось обработать семейства. Скорее всего, применены семейства не из библиотеки семейства. Имена семейств: ";
                foreach (string fam in errorRebarNames)
                {
                    errorFamilyMessage = errorFamilyMessage + fam + "; ";
                }
                Debug.WriteLine(errorFamilyMessage);
                TaskDialog.Show("Отчет", errorFamilyMessage);
            }

            Debug.WriteLine("Scetches finish success");
            return(Result.Succeeded);
        }