public static void AddFilterToView( Document doc, Autodesk.Revit.DB.View view, SelectionFilterElement filterElement, Color cutFillColor, string[] cutFillPatterns, Color projFillColor, string[] projFillPatterns) { using (Transaction t = new Transaction(doc, "Add filter to view and set overrides")) { t.Start(); ElementId filterId = filterElement.Id; view.AddFilter(filterId); doc.Regenerate(); OverrideGraphicSettings overrideSettings = view.GetFilterOverrides(filterId); Element cutFill = (from element in new FilteredElementCollector(doc) .OfClass(typeof(FillPatternElement)).Cast <Element>() where cutFillPatterns.Any(pattern => pattern.Equals(element.Name)) select element) .FirstOrDefault(); Element projectFill = (from element in new FilteredElementCollector(doc) .OfClass(typeof(FillPatternElement)).Cast <Element>() where projFillPatterns.Any(pattern => pattern.Equals(element.Name)) select element) .FirstOrDefault(); overrideSettings.SetCutFillColor(cutFillColor); overrideSettings.SetCutFillPatternId(cutFill.Id); overrideSettings.SetProjectionFillColor(projFillColor); overrideSettings.SetProjectionFillPatternId(projectFill.Id); view.SetFilterOverrides(filterId, overrideSettings); t.Commit(); } }
public SelectionFilterElement LoadFilter(UIDocument uidoc) { FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document); ICollection <Element> typecollection = collector.OfClass(typeof(SelectionFilterElement)).ToElements(); SelectionFilterElement sef = typecollection.Cast <SelectionFilterElement>().FirstOrDefault(ele => ele.Name == FilterName); if (sef != null) { uidoc.Selection.GetElementIds().Clear(); uidoc.Selection.SetElementIds(sef.GetElementIds()); } return(sef); }
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) { } }
public static IEnumerable <ElementId> ElementIdsBySelectionSet(this Document document, string selectionSetName, bool caseSensitive, IEnumerable <ElementId> ids = null) { if (document == null) { return(null); } if (ids != null && ids.Count() == 0) { return(new List <ElementId>()); } List <SelectionFilterElement> selectionFilterElements = new FilteredElementCollector(document).OfClass(typeof(SelectionFilterElement)).Cast <SelectionFilterElement>().ToList(); SelectionFilterElement selectionFilterElement = null; if (caseSensitive) { selectionFilterElement = selectionFilterElements.Find(x => x.Name == selectionSetName); } else { selectionFilterElement = selectionFilterElements.Find(x => !string.IsNullOrEmpty(x.Name) && x.Name.ToUpper() == selectionSetName.ToUpper()); } if (selectionFilterElement == null) { BH.Engine.Reflection.Compute.RecordError("Couldn't find a Selection Set named " + selectionSetName + "."); return(new HashSet <ElementId>()); } HashSet <ElementId> result = new HashSet <ElementId>(selectionFilterElement.GetElementIds()); if (ids != null) { result.IntersectWith(ids); } return(result); }
public SelectionFilterElement LoadFilter(UIDocument uidoc) { Document doc = uidoc.Document; FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document); ICollection <Element> typecollection = collector.OfClass(typeof(SelectionFilterElement)).ToElements(); SelectionFilterElement sef = typecollection.Cast <SelectionFilterElement>().FirstOrDefault(ele => ele.Name == FilterName); if (sef != null) { var elements = uidoc.Selection.GetElementIds() .ToList() .Select(id => doc.GetElement(id)) .ToList(); elements.Clear(); foreach (ElementId id in sef.GetElementIds()) { elements.Add(uidoc.Document.GetElement(id)); } } return(sef); }
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); }
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); }
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 }); }
public WallSelectionFilter(ElementId levelId, SelectionFilterElement selectionFilterElement) { _levelId = levelId; _selectFilterElem = selectionFilterElement; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { #region//Utils //String Builder StringBuilder sb = new StringBuilder(); //Collector Collector collector = new Collector(); //UnitConvertor LengthUnitConverter converter = new LengthUnitConverter(); // Application context. var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; #endregion #region//Check if we are in the Revit project , not in family one. if (doc.IsFamilyDocument) { Message.Display("Can't use command in family document", WindowType.Warning); return(Result.Cancelled); } #endregion #region//Get access to current view. var sectionView = uidoc.ActiveView; #endregion #region//Check if Dimension can be created in currently active project view. bool canCreateDimensionInView = false; switch (sectionView.ViewType) { case ViewType.FloorPlan: canCreateDimensionInView = false; break; case ViewType.CeilingPlan: canCreateDimensionInView = false; break; case ViewType.Detail: canCreateDimensionInView = false; break; case ViewType.Elevation: canCreateDimensionInView = true; break; case ViewType.Section: canCreateDimensionInView = true; break; } #endregion #region//Check if Dimension can be created if (!canCreateDimensionInView) { Message.Display("Dimension can't be created in the current view.", WindowType.Warning); return(Result.Cancelled); } #endregion #region//Check if activeView is a proper view if (canCreateDimensionInView) { #region//Ask user to select one generic model. Reference selectionReference; try { selectionReference = uidoc.Selection.PickObject(ObjectType.Element, new SelectionFilterByCategory("Generic Models"), "Select one generic model."); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } #endregion #region//Get main window Element mainWindow = doc.GetElement(selectionReference); FamilyInstance mainWindowFamily = doc.GetElement(mainWindow.Id) as FamilyInstance; FamilySymbol mainWindowSymbol = mainWindowFamily.Symbol; #region//Get directions for dimensions XYZ widthDirection = sectionView.RightDirection.Normalize(); XYZ heigthDirection = new XYZ(0, 0, 1); #endregion #region// Checks if selection isn't empty if (mainWindowFamily == null) { Message.Display("You haven't selected a valid element.\nPlease selected another element.", WindowType.Error); return(Result.Cancelled); } #endregion #region//Check if generic model is in same direction as view XYZ genericModelDir = GetReferenceDirection(mainWindowFamily.GetReferences(FamilyInstanceReferenceType.CenterFrontBack).First(), doc); if (genericModelDir.ToString() != widthDirection.ToString()) { Message.Display("The generic model isn't parallel to the active view.", WindowType.Error); return(Result.Cancelled); } #endregion #region//Get Type parameters double MDK_offset_vooraanzicht = mainWindowSymbol.LookupParameter("MDK_offset_vooraanzicht").AsDouble(); double MDK_hoogte = mainWindowSymbol.LookupParameter("MDK_hoogte").AsDouble(); double MDK_breedte = mainWindowSymbol.LookupParameter("MDK_breedte").AsDouble(); string MDK_merk = mainWindowSymbol.LookupParameter("MDK_merk").AsString(); #endregion #region//Get locationpoint of selected element LocationPoint mainWindowLocation = mainWindowFamily.Location as LocationPoint; XYZ mainWindowLocationpoint = mainWindowLocation.Point; #endregion #region//main window references ReferenceArray mainWindowHeight1 = new ReferenceArray(); ReferenceArray mainWindowHeight2 = new ReferenceArray(); ReferenceArray mainWindowWidth1 = new ReferenceArray(); ReferenceArray mainWindowWidth2 = new ReferenceArray(); foreach (var e in mainWindowFamily.GetReferences(FamilyInstanceReferenceType.Top)) { mainWindowHeight1.Append(e); mainWindowHeight2.Append(e); } foreach (var e in mainWindowFamily.GetReferences(FamilyInstanceReferenceType.Bottom)) { mainWindowHeight1.Append(e); mainWindowHeight2.Append(e); } foreach (var e in mainWindowFamily.GetReferences(FamilyInstanceReferenceType.Left)) { mainWindowWidth1.Append(e); mainWindowWidth2.Append(e); } foreach (var e in mainWindowFamily.GetReferences(FamilyInstanceReferenceType.Right)) { mainWindowWidth1.Append(e); mainWindowWidth2.Append(e); } foreach (Reference reference in mainWindowFamily.GetReferences(FamilyInstanceReferenceType.WeakReference)) { string name = mainWindowFamily.GetReferenceName(reference); if (name.Contains("center_tussenregel")) { mainWindowHeight1.Append(reference); } if (name.Contains("center_tussenstijl")) { mainWindowWidth1.Append(reference); } } #endregion #endregion #region//Get DimensionType DimensionType windowDimension = collector.GetLinearDimensionTypeByName(doc, "FAC - Diagonal - 2mm - Black"); DimensionType windowFrameDimension = collector.GetLinearDimensionTypeByName(doc, "FAC - Diagonal - 2mm - Stelkozijn"); DimensionType doorHandleDimension = collector.GetLinearDimensionTypeByName(doc, "FAC - Ordinate - 2mm - Krukhoogte"); DimensionType windowFrameLevelDimension = collector.GetLinearDimensionTypeByName(doc, "FAC - Ordinate - 2mm - Stelkozijn"); #endregion #region//Get base line List <DetailLine> detailLines = collector.GetDetailLines(doc, sectionView.Id); string lineStyle = "FAC_vloerpeil"; Line detailLine = null; foreach (DetailLine dl in detailLines) { if (dl.LineStyle.Name == lineStyle) { detailLine = dl.GeometryCurve as Line; } else { Message.Display("Can't find a DetailLine with the LineStyle, FAC_vloerpeil.", WindowType.Error); return(Result.Cancelled); } } #endregion #region//Get windowframe and window family!!!MDK WORDT NOG VERVANGEN DOOR FAC KAN ERROR VEROORZAKEN ICollection <ElementId> subComponentIds = mainWindowFamily.GetSubComponentIds(); #region//Get windowframe family string windowFrameName = "31_MDK_GM_stelkozijn_lijn"; FamilyInstance windowFrame = null; foreach (ElementId id in subComponentIds) { if (doc.GetElement(id).Name == windowFrameName) { windowFrame = doc.GetElement(id) as FamilyInstance; } } #region//windowframe references ReferenceArray windowframeWidth = new ReferenceArray(); ReferenceArray windowframeHeight1 = new ReferenceArray(); ReferenceArray windowframeHeight2 = new ReferenceArray(); foreach (var e in windowFrame.GetReferences(FamilyInstanceReferenceType.Left)) { windowframeWidth.Append(e); } foreach (var e in windowFrame.GetReferences(FamilyInstanceReferenceType.Right)) { windowframeWidth.Append(e); } windowframeHeight2.Append(detailLine.Reference); foreach (var e in windowFrame.GetReferences(FamilyInstanceReferenceType.Top)) { windowframeHeight1.Append(e); windowframeHeight2.Append(e); } foreach (var e in windowFrame.GetReferences(FamilyInstanceReferenceType.Bottom)) { windowframeHeight1.Append(e); windowframeHeight2.Append(e); } #endregion #endregion #region//Get window family string windowName = "31_FAC_GM_vak_vleugel"; FamilyInstance window = null; List <FamilyInstance> nestedFamilyList = new List <FamilyInstance>(); foreach (ElementId id in subComponentIds) { FamilyInstance fInstance = doc.GetElement(id) as FamilyInstance; FamilySymbol fSymbol = fInstance.Symbol; if (fSymbol.FamilyName == windowName) { window = doc.GetElement(id) as FamilyInstance; } } ReferenceArray doorHandleHeightLevel = new ReferenceArray(); ReferenceArray doorHandleHeight = new ReferenceArray(); XYZ windowLocationPoint = null; XYZ windowDimensionPoint1 = null; Line windowDimension1 = null; if (window != null) { #region//Get locationpoint of window LocationPoint windowLocation = window.Location as LocationPoint; windowLocationPoint = windowLocation.Point; #endregion #region//Create endpoint for line creation windowDimensionPoint1 = GetDistance(windowLocationPoint, widthDirection, 0, -50); #endregion #region//Create line for dimension windowDimension1 = Line.CreateBound(windowDimensionPoint1, windowDimensionPoint1 + heigthDirection * 100); #endregion #region//window references doorHandleHeightLevel.Append(detailLine.Reference); foreach (Reference reference in window.GetReferences(FamilyInstanceReferenceType.Bottom)) { doorHandleHeight.Append(reference); } foreach (Reference reference in window.GetReferences(FamilyInstanceReferenceType.WeakReference)) { string name = window.GetReferenceName(reference); if (name.Contains("krukhoogte_binnen")) { doorHandleHeight.Append(reference); doorHandleHeightLevel.Append(reference); } } #endregion } #endregion #endregion #region//Create endpoints for line creation XYZ RightDimensionPoint1 = GetDistance(mainWindowLocationpoint, widthDirection, MDK_breedte, 150); XYZ RightDimensionPoint2 = GetDistance(mainWindowLocationpoint, widthDirection, MDK_breedte, 300); XYZ RightDimensionPoint3 = GetDistance(mainWindowLocationpoint, widthDirection, MDK_breedte, 450); XYZ BottomDimensionPoint1 = new XYZ(mainWindowLocationpoint.X, mainWindowLocationpoint.Y, mainWindowLocationpoint.Z + MDK_offset_vooraanzicht - converter.ConvertToFeet(150)); XYZ BottomDimensionPoint2 = new XYZ(mainWindowLocationpoint.X, mainWindowLocationpoint.Y, mainWindowLocationpoint.Z + MDK_offset_vooraanzicht - converter.ConvertToFeet(300)); XYZ LeftDimensionPoint1 = GetDistance(mainWindowLocationpoint, widthDirection, 0, -150); XYZ LeftDimensionPoint2 = GetDistance(mainWindowLocationpoint, widthDirection, 0, -300); XYZ TopDimensionPoint1 = new XYZ(mainWindowLocationpoint.X, mainWindowLocationpoint.Y, mainWindowLocationpoint.Z + MDK_offset_vooraanzicht + MDK_hoogte + converter.ConvertToFeet(150)); #endregion #region//Create line for dimension Line RightDimension1 = Line.CreateBound(RightDimensionPoint1, RightDimensionPoint1 + heigthDirection * 100); Line RightDimension2 = Line.CreateBound(RightDimensionPoint2, RightDimensionPoint2 + heigthDirection * 100); Line RightDimension3 = Line.CreateBound(RightDimensionPoint3, RightDimensionPoint3 + heigthDirection * 100); Line BottomDimension1 = Line.CreateBound(BottomDimensionPoint1, BottomDimensionPoint1 + widthDirection * 100); Line BottomDimension2 = Line.CreateBound(BottomDimensionPoint2, BottomDimensionPoint2 + widthDirection * 100); Line LeftDimension1 = Line.CreateBound(LeftDimensionPoint1, LeftDimensionPoint1 + heigthDirection * 100); Line LeftDimension2 = Line.CreateBound(LeftDimensionPoint2, LeftDimensionPoint2 + heigthDirection * 100); Line TopDimension1 = Line.CreateBound(TopDimensionPoint1, TopDimensionPoint1 + widthDirection * 100); #endregion #region//Get selection filter SelectionFilterElement filter = null; List <SelectionFilterElement> filters = collector.GetSelectionFilter(doc); string filtername = "Stelkozijn maatvoering"; foreach (SelectionFilterElement f in filters) { if (f.Name == filtername) { filter = f; } } #endregion #region//Create Annotations using (Transaction tx = new Transaction(doc)) { tx.Start("Create Annotations"); #region//Create and set workplane to place dimensions on Plane plane = Plane.CreateByNormalAndOrigin(sectionView.ViewDirection, sectionView.Origin); SketchPlane sketchPlane = SketchPlane.Create(doc, plane); sectionView.SketchPlane = sketchPlane; #endregion #region//Create Dimensions doc.Create.NewDimension(sectionView, RightDimension1, mainWindowHeight1, windowDimension); doc.Create.NewDimension(sectionView, BottomDimension1, mainWindowWidth1, windowDimension); Dimension windowFrameHeight1 = doc.Create.NewDimension(sectionView, LeftDimension1, windowframeHeight1, windowFrameDimension); Dimension windowFrameHeight2 = doc.Create.NewDimension(sectionView, LeftDimension2, windowframeHeight2, windowFrameLevelDimension); Dimension windowFrameWidth = doc.Create.NewDimension(sectionView, TopDimension1, windowframeWidth, windowFrameDimension); #region//Add dimension to selection filter filter.AddSingle(windowFrameWidth.Id); filter.AddSingle(windowFrameHeight1.Id); filter.AddSingle(windowFrameHeight2.Id); #endregion #region//Add prefix to window frame dimension foreach (DimensionSegment seg in windowFrameHeight2.Segments) { seg.Prefix = "vlp +"; } #endregion #region//Add height dimension 2 and/or 3 if (mainWindowHeight1.Size != 2) { doc.Create.NewDimension(sectionView, RightDimension2, mainWindowHeight2, windowDimension); if (window != null) { Dimension doorHandleHeight1 = doc.Create.NewDimension(sectionView, RightDimension3, doorHandleHeightLevel, doorHandleDimension); Dimension doorHandleHeight2 = doc.Create.NewDimension(sectionView, windowDimension1, doorHandleHeight, doorHandleDimension); foreach (DimensionSegment seg in doorHandleHeight1.Segments) { seg.Prefix = "GH ="; seg.Suffix = "+ vlp"; } foreach (DimensionSegment seg in doorHandleHeight2.Segments) { seg.Prefix = "GH ="; } } } else { if (window != null) { Dimension doorHandleHeight1 = doc.Create.NewDimension(sectionView, RightDimension2, doorHandleHeightLevel, doorHandleDimension); Dimension doorHandleHeight2 = doc.Create.NewDimension(sectionView, windowDimension1, doorHandleHeight, doorHandleDimension); foreach (DimensionSegment seg in doorHandleHeight1.Segments) { seg.Prefix = "GH ="; seg.Suffix = "+ vlp"; } foreach (DimensionSegment seg in doorHandleHeight2.Segments) { seg.Prefix = "GH ="; } } } #endregion #region//Add width dimension 2 if (mainWindowWidth1.Size != 2) { doc.Create.NewDimension(sectionView, BottomDimension2, mainWindowWidth2, windowDimension); } #endregion #endregion tx.Commit(); } #endregion } #endregion return(Result.Succeeded); }
public static IEnumerable <ElementId> ElementIdsOfMemberElements(this SelectionFilterElement selectionSet) { return(selectionSet.GetElementIds()); }
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) { } }
public static void RemoveFilterFromView(Document doc, Autodesk.Revit.DB.View view, SelectionFilterElement filterElement) { Transaction t = new Transaction(doc); bool filterExistsInActiveView = view.GetFilters().Any(id => doc.GetElement(id).Name.Equals("Voiles Porteurs")); if (filterExistsInActiveView) { t.Start("Remove filter from active view"); view.RemoveFilter(filterElement.Id); t.Commit(); } }
public static void RemoveFilterFromViewOrTemplate(Document doc, Autodesk.Revit.DB.View view, SelectionFilterElement filterElement) { if (view.ViewTemplateId == ElementId.InvalidElementId) // No view template applied on active view { // Remove filter from view RemoveFilterFromView(doc, view, filterElement); } else { Autodesk.Revit.DB.View template = doc.GetElement(view.ViewTemplateId) as Autodesk.Revit.DB.View; // Remove filter from template RemoveFilterFromView(doc, template, filterElement); } }
public static void AddFilterToViewOrTemplate(Document doc, Autodesk.Revit.DB.View view, SelectionFilterElement filterElement, Color cutFillColor, string[] cutFillPatterns, Color projFillColor, string[] projFillPatterns) { if (view.ViewTemplateId == ElementId.InvalidElementId) // No view template applied on active view { // Add filter to view AddFilterToView( doc, view, filterElement, cutFillColor, cutFillPatterns, projFillColor, projFillPatterns); } else { Autodesk.Revit.DB.View template = doc.GetElement(view.ViewTemplateId) as Autodesk.Revit.DB.View; // Add filter to template AddFilterToView( doc, template, filterElement, cutFillColor, cutFillPatterns, projFillColor, projFillPatterns); } }