privatevoidChangeSelection(UIDocument uidoc) { // Get selected elements from current document. ICollection selectedIds = uidoc.Selection.GetElementIds();
// Display current number of selected elements TaskDialog.Show("Revit", "Number of selected elements: " + selectedIds.Count.ToString());
// Go through the selected items and filter out walls only. ICollection selectedWallIds = new List();
foreach (ElementId id in selectedIds) { Element elements = uidoc.Document.GetElement(id); if (elements is Wall) { selectedWallIds.Add(id); } }
// Set the created element set as current select element set. uidoc.Selection.SetElementIds(selectedWallIds);
// Give the user some information. if (0 != selectedWallIds.Count) { TaskDialog.Show("Revit", selectedWallIds.Count.ToString() + " Walls are selected!"); } else { TaskDialog.Show("Revit","No Walls have been selected!"); } }
UIDocument uidoc = new UIDocument(document); Selection choices = uidoc.Selection; // Pick one object from Revit. Reference hasPickOne = choices.PickObject(ObjectType.Element); if (hasPickOne != null) { TaskDialog.Show("Revit", "One element selected."); }
// Use the rectangle picking tool to identify model elements to select. IList pickedElements = uidoc.Selection.PickElementsByRectangle("Select by rectangle"); if (pickedElements.Count > 0) { // Collect Ids of all picked elements IList idsToSelect = new List(pickedElements.Count); foreach (Element element in pickedElements) { idsToSelect.Add(element.Id); }
// Update the current selection uidoc.Selection.SetElementIds(idsToSelect); TaskDialog.Show("Revit", string.Format("{0} elements added to Selection.", idsToSelect.Count)); }
ObjectSnapTypes snapTypes = ObjectSnapTypes.Endpoints | ObjectSnapTypes.Intersections; XYZ point = uidoc.Selection.PickPoint(snapTypes, "Select an end point or intersection");
string strCoords = "Selected point is " + point.ToString();
publicboolAllowReference(Reference refer, XYZ point) { if (doc.GetElement(refer).GetGeometryObjectFromReference(refer) is PlanarFace) { // Only return true for planar faces. Non-planar faces will not be selectable returntrue; } returnfalse; } }