Ejemplo n.º 1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication val  = commandData.get_Application();
            Document      val2 = val.get_ActiveUIDocument().get_Document();
            Selection     val3 = val.get_ActiveUIDocument().get_Selection();

            try
            {
                ICollection <ElementId> elementIds = val3.GetElementIds();
                if (elementIds.Count == 0)
                {
                    IList <Reference> refs = val3.PickObjects(1, "Select target elements for LOD change");
                    elementIds = LODapp.GetElementIds(val2, refs);
                }
                View            viewFromElements = GetViewFromElements(val2, elementIds);
                IList <Element> list;
                if (viewFromElements == null)
                {
                    IList <Element> elements2 = LODapp.GetElements(val2, elementIds);
                    list = elements2;
                }
                else
                {
                    list = GetFilteredElementsFromView(val2, viewFromElements);
                    if (list == null)
                    {
                        return(1);
                    }
                }
                if (setLODform == null)
                {
                    setLODform = new SetLODform();
                }
                setLODform.ShowDialog();
                if (setLODform.DialogResult != DialogResult.OK)
                {
                    return(1);
                }
                string      selectedLODtype     = setLODform.SelectedLODtype;
                int         selectedLODvalue    = setLODform.SelectedLODvalue;
                Definition  parameterDefinition = LODapp.GetParameterDefinition(val2, selectedLODtype);
                Transaction val4 = new Transaction(val2, "Set LOD");
                val4.Start();
                LODapp.SetParameterOfElements((IEnumerable <Element>)list, parameterDefinition, selectedLODvalue);
                val4.Commit();
            }
            catch (OperationCanceledException)
            {
                return(1);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(-1);
            }
            return(0);
        }
Ejemplo n.º 2
0
        public void Execute(UpdaterData data)
        {
            Document doc = data.GetDocument();

            if (!doc.get_IsFamilyDocument())
            {
                Definition parameterDefinition = LODapp.GetParameterDefinition(doc, "Current_LOD");
                if (parameterDefinition != null)
                {
                    ICollection <ElementId> addedElementIds = data.GetAddedElementIds();
                    IList <Element>         elems           = (from ElementId id in addedElementIds
                                                               select doc.GetElement(id)).ToList();
                    LODapp.SetParameterOfElementsIfNotSet((IEnumerable <Element>)elems, parameterDefinition, 200);
                }
            }
        }
Ejemplo n.º 3
0
 public bool IsCommandAvailable(UIApplication appData, CategorySet selectedCategories)
 {
     try
     {
         Document   doc = appData.get_ActiveUIDocument().get_Document();
         Definition parameterDefinition = LODapp.GetParameterDefinition(doc, "Current_LOD");
         if (parameterDefinition == null)
         {
             return(true);
         }
         return(false);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        public void Execute(UpdaterData data)
        {
            Document val = data.GetDocument();
            ICollection <ElementId> modifiedElementIds = data.GetModifiedElementIds();
            Definition curLODdef = LODapp.GetParameterDefinition(val, "Current_LOD");
            Definition tarLODdef = LODapp.GetParameterDefinition(val, "Target_LOD");

            CreateFiltersIfMissing(val);
            IEnumerable <Element> enumerable = new FilteredElementCollector(val, modifiedElementIds).WherePasses(curLODfilter).ToElements();
            bool flag = false;
            IEnumerable <Element> source = new FilteredElementCollector(val, modifiedElementIds).WherePasses(tarLODfilter).ToElements();
            bool flag2 = true;

            source = from e in source
                     where e.get_Parameter(tarLODdef).get_HasValue()
                     select e;

            if (enumerable.Count() > 0)
            {
                int    num  = enumerable.First().get_Parameter(curLODdef).AsInteger();
                string text = "Invalid Current_LOD Value: " + num;
                TaskDialog.Show("Invalid Value", text);
                foreach (Element item in enumerable)
                {
                    item.get_Parameter(curLODdef).Set(200);
                }
            }
            if (source.Count() > 0)
            {
                int    num2  = source.First().get_Parameter(tarLODdef).AsInteger();
                string text2 = "Invalid Target_LOD Value: " + num2;
                TaskDialog.Show("Invalid Value", text2);
                foreach (Element item2 in source)
                {
                    item2.get_Parameter(tarLODdef).Set(200);
                }
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Application val  = commandData.get_Application().get_Application();
            Document    val2 = commandData.get_Application().get_ActiveUIDocument().get_Document();
            Definition  val3 = LODapp.GetParameterDefinition(val2, "Current_LOD");
            Definition  val4 = LODapp.GetParameterDefinition(val2, "Target_LOD");
            Definition  val5 = LODapp.GetParameterDefinition(val2, "MEA");
            Definition  val6 = LODapp.GetParameterDefinition(val2, "Zone");
            Transaction val7 = new Transaction(val2, "Create LOD Parameter");

            try
            {
                val7.Start();
                string tempPath = Path.GetTempPath();
                tempPath += "LODmanager\\";
                Directory.CreateDirectory(tempPath);
                string     text       = tempPath + "RevitParameters.txt";
                FileStream fileStream = File.Create(text);
                fileStream.Close();
                val.set_SharedParametersFilename(text);
                DefinitionFile  val8 = val.OpenSharedParameterFile();
                DefinitionGroup val9 = val8.get_Groups().Create("BIM");
                if (val3 == null)
                {
                    ExternalDefinitionCreationOptions val10 = new ExternalDefinitionCreationOptions("Current_LOD", 2);
                    val10.set_Description("The Current Level of Development of the Object. \nOptions: 100, 200, 300, 350, 400. \nSee LOD Specification for details.");
                    val3 = val9.get_Definitions().Create(val10);
                }
                if (val4 == null)
                {
                    ExternalDefinitionCreationOptions val11 = new ExternalDefinitionCreationOptions("Target_LOD", 2);
                    val11.set_Description("The Target Level of Development of the Object. \nOptions: 100, 200, 300, 350, 400. \nSee LOD Specification for details.");
                    val4 = val9.get_Definitions().Create(val11);
                }
                if (val5 == null)
                {
                    ExternalDefinitionCreationOptions val12 = new ExternalDefinitionCreationOptions("MEA", 1);
                    val12.set_Description("The Model Element Author for the Object.");
                    val5 = val9.get_Definitions().Create(val12);
                }
                if (val6 == null)
                {
                    ExternalDefinitionCreationOptions val13 = new ExternalDefinitionCreationOptions("Zone", 1);
                    val13.set_Description("The Zone in which this Object resides.");
                    val6 = val9.get_Definitions().Create(val13);
                }
                CategorySet       val14       = val.get_Create().NewCategorySet();
                BuiltInCategory[] lodCatArray = LODapp.lodCatArray;
                foreach (BuiltInCategory val15 in lodCatArray)
                {
                    Category val16 = val2.get_Settings().get_Categories().get_Item(val15);
                    val14.Insert(val16);
                }
                InstanceBinding val17 = val.get_Create().NewInstanceBinding(val14);
                val2.get_ParameterBindings().Insert(val3, val17, -5000175);
                val2.get_ParameterBindings().Insert(val4, val17, -5000175);
                val2.get_ParameterBindings().Insert(val5, val17, -5000175);
                val2.get_ParameterBindings().Insert(val6, val17, -5000175);
                val7.Commit();
            }
            catch (Exception ex)
            {
                val7.RollBack();
                message = ex.ToString();
                return(-1);
            }
            val7 = new Transaction(val2, "Set Default LOD Values");
            try
            {
                val7.Start();
                BuiltInCategory[] lodCatArray2 = LODapp.lodCatArray;
                foreach (BuiltInCategory val18 in lodCatArray2)
                {
                    FilteredElementCollector val19 = new FilteredElementCollector(val2);
                    val19.OfCategory(val18);
                    IEnumerable <Element> elems = val19.ToElements();
                    LODapp.SetParameterOfElementsIfNotSet(elems, val3, 200);
                }
                val7.Commit();
            }
            catch (Exception ex2)
            {
                val7.RollBack();
                message = ex2.ToString();
                return(-1);
            }
            return(0);
        }
Ejemplo n.º 6
0
 public void Execute(UpdaterData data)
 {
     if (!Paused)
     {
         Document         doc  = data.GetDocument();
         List <ElementId> list = data.GetAddedElementIds().ToList();
         list.AddRange(data.GetModifiedElementIds());
         IList <Element> list2 = (from ElementId id in list
                                  select doc.GetElement(id)).ToList();
         Definition                parameterDefinition = LODapp.GetParameterDefinition(doc, "Zone");
         ElementId                 val  = LODapp.GetLODparameter(doc, parameterDefinition).get_Id();
         ParameterValueProvider    val2 = new ParameterValueProvider(val);
         FilterStringRuleEvaluator val3 = new FilterStringContains();
         FilterStringRuleEvaluator val4 = new FilterStringEquals();
         FilterStringRuleEvaluator val5 = new FilterStringBeginsWith();
         foreach (Element item in list2)
         {
             string text = item.LookupParameter("Name").AsString();
             if (!string.IsNullOrWhiteSpace(text))
             {
                 FilterRule[] array = (FilterRule[])new FilterRule[3]
                 {
                     new FilterStringRule(val2, val4, text, true),
                     new FilterStringRule(val2, val5, text + ", ", true),
                     new FilterStringRule(val2, val3, ", " + text, true)
                 };
                 ElementParameterFilter      val6        = new ElementParameterFilter((IList <FilterRule>)array);
                 IList <Element>             list3       = new FilteredElementCollector(doc).WhereElementIsNotElementType().WherePasses(val6).ToElements();
                 BoundingBoxIntersectsFilter val7        = new BoundingBoxIntersectsFilter(ToOutline(item.get_BoundingBox(null)));
                 IList <Element>             list4       = new FilteredElementCollector(doc).WhereElementIsNotElementType().WherePasses(val7).ToElements();
                 IEnumerable <Element>       enumerable  = list3.Except(list4, new EqualUniqueId());
                 IEnumerable <Element>       enumerable2 = list4.Except(list3, new EqualUniqueId());
                 foreach (Element item2 in enumerable)
                 {
                     Parameter val8 = item2.get_Parameter(parameterDefinition);
                     if (val8 != null)
                     {
                         string text2 = val8.AsString() ?? string.Empty;
                         string text3;
                         if (text2.Length > text.Length)
                         {
                             int num = text2.IndexOf(text);
                             text3 = ((num < 2 || text2[num - 2] != ',') ? text2.Remove(num, text.Length + 2) : text2.Remove(num - 2, text.Length + 2));
                         }
                         else
                         {
                             text3 = string.Empty;
                         }
                         val8.Set(text3);
                     }
                 }
                 foreach (Element item3 in enumerable2)
                 {
                     Parameter val9  = item3.get_Parameter(parameterDefinition);
                     string    text4 = (((int)val9 != 0) ? val9.AsString() : null) ?? string.Empty;
                     string    text5 = (text4.Length <= 0) ? text : (text4 + ", " + text);
                     Parameter val10 = item3.get_Parameter(parameterDefinition);
                     if ((int)val10 != 0)
                     {
                         val10.Set(text5);
                     }
                 }
             }
         }
     }
 }