Esempio n. 1
0
        private static void makeAnnoOverrides(
            Document doc, View view, List <List <string> > category_colors)
        {
            try
            {
                StringBuilder sb  = new StringBuilder();
                var           col = new FilteredElementCollector(doc, view.Id)
                                    .WhereElementIsNotElementType();

                var colorcats = category_colors.Select(x => x.First()).ToList();

                using (Transaction tx = new Transaction(doc))
                {
                    var tohide = new List <ElementId>();
                    tx.Start("SetViewtxz");

                    foreach (Element elem in col)
                    {
                        try
                        {
                            if (elem.Category != null)
                            {
                                var elemBcCat =
                                    (BuiltInCategory)elem.Category.Id.IntegerValue;
                                string bcCat = elemBcCat.ToString();

                                if (!colorcats.Contains(bcCat))
                                {
                                    tohide.Add(elem.Id);
                                }
                            }
                        }
                        catch (Exception) { }
                    }
                    SelectionFilterElement filterElement =
                        SelectionFilterElement.Create(doc, Helper.RandomString(100));
                    filterElement.SetElementIds(tohide);
                    doc.Regenerate();
                    view.AddFilter(filterElement.Id);
                    view.SetFilterVisibility(filterElement.Id, false);

                    tx.Commit();
                }
            }
            catch (Exception) { }
        }
Esempio n. 2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication _uiapp = commandData.Application;
            UIDocument    _uidoc = _uiapp.ActiveUIDocument;
            Document      _doc   = _uidoc.Document;

            View activeV = _doc.ActiveView;

            SelectionFilterElement filterElement = new FilteredElementCollector(_doc)
                                                   .OfClass(typeof(SelectionFilterElement)).Cast <SelectionFilterElement>()
                                                   .Where(sf => sf.Name.Equals("Voiles Porteurs"))
                                                   .FirstOrDefault();

            Transaction t = new Transaction(_doc);

            t.Start("Creat filter");

            // Dont find the filter in the doc, create a new filter
            if (filterElement == null)
            {
                try
                {
                    filterElement = SelectionFilterElement.Create(_doc, "Voiles Porteurs");
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    return(Result.Failed);
                }
            }
            t.Commit();

            // The filter is not added to the active view, add it to the view
            //bool filterExistsInActiveView =
            //    activeV.GetFilters().Any(id => _doc.GetElement(id).Name.Equals("Voiles Porteurs"));
            //if (!filterExistsInActiveView)
            //{
            //    ViewTemplate.AddFilterToView(
            //        _doc, activeV, filterElement,
            //        new Color(000, 128, 255), new string[] { "Uni", "Solid fill" },
            //        new Color(000, 128, 255), new string[] { "Uni", "Solid fill" });
            //}

            // Add selected walls to the filter
            IList <Reference> refIds;

            try
            {
                refIds = _uidoc.Selection.PickObjects(ObjectType.Element,
                                                      new WallSelectionFilter(activeV.GenLevel.Id));
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }

            t.Start("Add walls to filter");
            foreach (Reference refe in refIds)
            {
                filterElement.AddSingle(refe.ElementId);
            }
            t.Commit();

            ViewTemplate.RemoveFilterFromViewOrTemplate(_doc, activeV, filterElement);

            ViewTemplate.AddFilterToViewOrTemplate(
                _doc, activeV, filterElement,
                new Color(000, 128, 255), new string[] { "Uni", "Solid fill" },
                new Color(000, 128, 255), new string[] { "Uni", "Solid fill" });

            _uidoc.RefreshActiveView();


            return(Result.Succeeded);
        }
Esempio n. 3
0
        public static void cropExtentAnno(Document doc, View view)
        {
            try
            {
                var els
                    = new FilteredElementCollector(doc, view.Id)
                      .WhereElementIsNotElementType();

                var bbv  = view.get_BoundingBox(view);
                var maxx = bbv.Max.X;
                var maxy = bbv.Max.Y;
                var maxz = bbv.Max.Z;

                var minx = bbv.Min.X;
                var miny = bbv.Min.Y;
                var minz = bbv.Min.Z;

                var tohide = new List <ElementId>();

                foreach (Element e in els)
                {
                    try
                    {
                        var    elemBcCat = (BuiltInCategory)e.Category.Id.IntegerValue;
                        string bcCat     = elemBcCat.ToString();
                        if (bcCat.Contains("Tag") ||
                            bcCat.Contains("Arrow") ||
                            bcCat.Contains("Callo") ||
                            bcCat.Contains("OST_Grid") ||
                            bcCat.Contains("Elevation") ||
                            bcCat.Contains("Annotation") ||
                            bcCat.Contains("View")
                            //|| bcCat.Contains("Line")
                            || bcCat.Contains("Level") ||
                            bcCat.Contains("Section") ||
                            bcCat.Contains("Dimension")
                            //|| bcCat.Contains("Text")
                            )
                        {
                            var bbx = e.get_BoundingBox(view);
                            if (maxx < bbx.Max.X || maxy < bbx.Max.Y || maxz < bbx.Max.Z ||
                                minx > bbx.Min.X || miny > bbx.Min.Y || minz > bbx.Min.Z)
                            {
                                tohide.Add(e.Id);
                            }
                        }
                        //if (bcCat.Contains("OST_Grid"))
                        //{
                        //    var bbx = e.get_BoundingBox(view);
                        //    //Intersect
                        //    if(bbx.)
                        //}
                    }
                    catch (Exception) { }
                }
                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("shade");
                    SelectionFilterElement filterElement = SelectionFilterElement.Create(doc, RandomString(100));
                    filterElement.SetElementIds(tohide);
                    doc.Regenerate();

                    view.AddFilter(filterElement.Id);
                    view.SetFilterVisibility(filterElement.Id, false);

                    tx.Commit();
                }
            }
            catch (Exception) { }
        }
        //
        public void selectByParaSpecial(UIDocument uiDoc)
        {
            // pick first element to get all parameters
            Document doc = uiDoc.Document;

            Reference myRef = uiDoc.Selection.PickObject(ObjectType.Element, "Select an Element...");

            Element myFirstElem = doc.GetElement(myRef);

            // Get parameters of element
            ParameterSet myParaSet = myFirstElem.Parameters;



            List <string> myListParaName        = new List <string>();
            List <string> myListParaValueString = new List <string>();

            bool saveSelection = false;

            foreach (Parameter myPara in myParaSet)
            {
                //TaskDialog.Show("abc", myPara.Definition.Name + "Value: " + myPara.AsValueString());
                myListParaName.Add(myPara.Definition.Name);

                if (myPara.StorageType == StorageType.String)
                {
                    myListParaValueString.Add(myPara.AsString());
                }

                else
                {
                    myListParaValueString.Add(myPara.AsValueString());
                }
            }

            //TaskDialog.Show("abc","num value: " + myListParaName.Count.ToString());
            //Reference myRef2 = uiDoc.Selection.PickObject(ObjectType.Element, new FilterByNameElementType(myListType));

            List <ElementId> myListIdElem = new List <ElementId>();

            string paraNameSelected  = "a";
            string paraValueSelected = "b";

            using (FilterForm myFormSelect = new FilterForm(myListParaName, myListParaValueString))

            {
                // Add list parameter to cb
                myFormSelect.ShowDialog();

                //if the user hits cancel just drop out of macro
                if (myFormSelect.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    //else do all this :)
                    myFormSelect.Close();
                    return;
                }

                if (myFormSelect.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    paraNameSelected  = myFormSelect.paraName_Cb.Text;
                    paraValueSelected = myFormSelect.value_Tb.Text;
                    saveSelection     = myFormSelect.saveSelection;
                    myFormSelect.Close();
                }
            }

            // Select by Filter

            List <Reference> myListRef = uiDoc.Selection.PickObjects(ObjectType.Element,
                                                                     new FilterByParameterValueSelectClass(paraNameSelected, paraValueSelected),
                                                                     "Select Element") as List <Reference>;

            foreach (Reference myRefe in myListRef) // Iterate through list of selected elements
            {
                // Add the ElementId of each selected element to the selection filter
                myListIdElem.Add(myRefe.ElementId);
            }

            if (saveSelection)
            {
                using (Transaction t = new Transaction(doc, "Create & Add To Selection Filter"))
                {
                    t.Start(); // Start the transaction

                    // Create a SelectionFilterElement
                    SelectionFilterElement selFilter = SelectionFilterElement.Create(doc, paraNameSelected + " - " + paraValueSelected);



                    foreach (Reference r in myListRef) // Iterate through list of selected elements
                    {
                        // Add the ElementId of each selected element to the selection filter
                        selFilter.AddSingle(r.ElementId);
                    }

                    // Commit the transaction
                    t.Commit();
                }
            }
            uiDoc.Selection.SetElementIds(myListIdElem);

            //TaskDialog.Show("abc", "number element: " + myListRef.Count);
        }
Esempio n. 5
0
        private void InitializeCommand()
        {
            CommandBinding cbSelectParam = new CommandBinding(cmdSelectParam, (sender, e) =>
            {
                if ((e.OriginalSource as CheckBox).IsChecked == true)
                {
                    ParamListFiltered.Add(e.Parameter.ToString());
                }
                else
                {
                    ParamListFiltered.Remove(e.Parameter.ToString());
                }
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });

            CommandBinding cbParamsRefresh = new CommandBinding(cmdParamsRefresh, (sender, e) =>
            {
                ProcessSelection();

                CurrentElementList.ForEach(ele =>
                {
                    ParameterSet parameters = ele.Parameters;
                    foreach (Parameter parameter in parameters)
                    {
                        ParamListSource.Add(parameter.Definition.Name);
                    }
                });

                HashSet <string> hs = new HashSet <string>(ParamListSource);
                ParamListSource.Clear();
                hs.ToList().ForEach(d => ParamListSource.Add(d));
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });

            CommandBinding cbApplySelection = new CommandBinding(cmdApplySelection, (sender, e) =>
            {
                ProcessSelection();

                using (Transaction trans = new Transaction(doc, "CreateSelectionFilter"))
                {
                    trans.Start();
                    FilteredElementCollector collector   = new FilteredElementCollector(doc);
                    ICollection <Element> typecollection = collector.OfClass(typeof(SelectionFilterElement)).ToElements();
                    SelectionFilterElement selectset     = typecollection.Cast <SelectionFilterElement>().FirstOrDefault(ele => ele.Name == txtSelectFilterName.Text);
                    if (selectset != null)
                    {
                        selectset.Clear();
                    }
                    else
                    {
                        selectset = SelectionFilterElement.Create(doc, txtSelectFilterName.Text);
                    }

                    CurrentElementList.ForEach(ele => selectset.AddSingle(ele.Id));
                    //doc.ActiveView.IsolateElementsTemporary(selectset.GetElementIds());
                    trans.Commit();
                }
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });

            bnApplySelection.Command = cmdApplySelection;
            bnParamsRefresh.Command  = cmdParamsRefresh;

            ProcSF.CommandBindings.AddRange(new CommandBinding[]
            {
                cbSelectParam,
                cbParamsRefresh,
                cbApplySelection
            });
        }
Esempio n. 6
0
        private static void AddOverride2(Document doc, View view, ElementId pattern, List <List <string> > category_colors)
        {
            try
            {
                FilteredElementCollector col
                    = new FilteredElementCollector(doc, view.Id)
                      .WhereElementIsNotElementType();

                StringBuilder sb = new StringBuilder();

                using (Transaction tx = new Transaction(doc))
                {
                    var tohide = new List <ElementId>();
                    tx.Start("SetViewtx");
                    try
                    {
                        foreach (Element elem in col)
                        {
                            try
                            {
                                // var catid = elem.Category.Id.IntegerValue;

                                var    elemBcCat = (BuiltInCategory)elem.Category.Id.IntegerValue;
                                string bcCat     = elemBcCat.ToString();

                                var category_ovrs = category_colors.Where(x => x.First() == elemBcCat.ToString()).ToList();

                                if (category_ovrs.Count > 0)
                                {
                                    var category_ovr = category_ovrs.First();
                                    var r            = Convert.ToByte(category_ovr[1]);
                                    var g            = Convert.ToByte(category_ovr[2]);
                                    var b            = Convert.ToByte(category_ovr[3]);
                                    var color_c      = new Color(r, g, b);

                                    var gSettings = new OverrideGraphicSettings();
                                    //gSettings.
                                    gSettings.SetCutFillColor(color_c);
                                    gSettings.SetCutLineColor(color_c);
                                    gSettings.SetCutFillPatternVisible(true);
                                    gSettings.SetCutFillPatternId(pattern);
                                    gSettings.SetProjectionFillColor(color_c);
                                    gSettings.SetProjectionLineColor(color_c);
                                    gSettings.SetProjectionFillPatternId(pattern);
                                    view.SetElementOverrides(elem.Id, gSettings);
                                }
                                else
                                {
                                    //!elem.Category.HasMaterialQuantities ||
                                    if (elemBcCat.ToString().Contains("Tag") || elemBcCat.ToString().Contains("Arrow") ||
                                        elemBcCat.ToString().Contains("Text") || elemBcCat.ToString().Contains("Annotation") ||
                                        elemBcCat.ToString().Contains("Line"))
                                    {
                                        tohide.Add(elem.Id);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                sb.AppendLine();
                                sb.Append("Fail--OVERRIDES:" + view.ViewName + e.ToString());
                                //File.AppendAllText(FileManager.logfile, sb.ToString() + "\n");
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // TaskDialog.Show("x", e.ToString());
                    }

                    SelectionFilterElement filterElement = SelectionFilterElement.Create(doc, "tags filter");
                    filterElement.SetElementIds(tohide);
                    // doc.Regenerate();
                    view.AddFilter(filterElement.Id);
                    view.SetFilterVisibility(filterElement.Id, false);
                    // view.

                    tx.Commit();
                }
            }
            catch (Exception) { }
        }