public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; if (!(uidoc.ActiveView is ViewPlan)) { message = Properties.Messages.RenumberParking_NotPlanView; return(Result.Failed); } IList <Element> parkingElements = new FilteredElementCollector(uidoc.Document).OfCategory(BuiltInCategory.OST_Parking) .WhereElementIsNotElementType().Where(e => e.LevelId == uidoc.ActiveView.GenLevel.Id).ToList(); if (parkingElements.Count == 0) { message = Properties.Messages.RenumberParking_NoParking; return(Result.Failed); } renumberBlocksUI rBlockUI = new renumberBlocksUI(); rBlockUI.ShowDialog(); return(Result.Succeeded); }
static internal void RenumCleanSelected(string inPrefix, string inNumber) { Document doc = uidoc.Document; Selection sel = uidoc.Selection; View thisView = uidoc.ActiveView; try { IList <Element> allParkingElement = sel.PickElementsByRectangle(new ParkingSelectionFilter(), Properties.Messages.RenumberParking_SelectParkingSpace); if (allParkingElement.Count > 0) { try { using (Transaction cleanerTrans = new Transaction(doc, Properties.Messages.RenumberParking_ClearParkNumbering)) { cleanerTrans.Start(); foreach (Element currentElemen in allParkingElement) { currentElemen.get_Parameter(BuiltInParameter.DOOR_NUMBER).Set(""); } cleanerTrans.Commit(); } } catch { } } } catch { } finally { Level currentLevel = uidoc.ActiveView.GenLevel; IList <Element> AllParkingInLevel = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Parking).OfClass(typeof(FamilyInstance)) .Where(p => p.LevelId == currentLevel.Id).ToList(); double lastUsedNumber = 0; if (AllParkingInLevel.Count > 0) { foreach (Element currentParking in AllParkingInLevel) { Parameter numberParam = currentParking.get_Parameter(BuiltInParameter.DOOR_NUMBER); if (numberParam.HasValue) { double currentParkingNumber = -232.23; if (double.TryParse(numberParam.AsString(), out currentParkingNumber)) { if (lastUsedNumber < currentParkingNumber) { lastUsedNumber = currentParkingNumber; } } } } } renumberBlocksUI repeatUICreation = new renumberBlocksUI(inPrefix, lastUsedNumber.ToString()); repeatUICreation.ShowDialog(); } }
static internal void renameBlock(string inPrefix, string inNumber, bool isSingleParkingSelected) { int lastUsedNumber = int.Parse(inNumber); try { Selection sel = uidoc.Selection; Document doc = uidoc.Document; IList <Element> parkingElements = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Parking).WhereElementIsNotElementType().ToList(); IList <Element> remainingParking = new List <Element>(); IList <ElementId> usedparking = new List <ElementId>(); Element pickedOrFirstSelectedParking = null; IList <ParkingTypesInfo> parkingInfo = getAllParkingTypesInfo(); if (isSingleParkingSelected) { pickedOrFirstSelectedParking = doc.GetElement(sel.PickObject(ObjectType.Element, new ParkingSelectionFilter(), Properties.Messages.RenumberParking_SelectParkingSpace)); IList <Element> parkingElementsInLevel = parkingElements.ToList() .Where(p => p.LevelId == pickedOrFirstSelectedParking.LevelId) .Where(p => (p as FamilyInstance).Symbol.Id == (pickedOrFirstSelectedParking as FamilyInstance).Symbol.Id).ToList(); foreach (Element e in parkingElementsInLevel) { if (!usedparking.Contains(e.Id)) { remainingParking.Add(e); } } } else { remainingParking = sel.PickElementsByRectangle(new ParkingSelectionFilter(), Properties.Messages.RenumberParking_SelectParkingSpace); pickedOrFirstSelectedParking = doc.GetElement(sel.PickObject(ObjectType.Element, new ParkingSelectionFilter(), Properties.Messages.RenumberParking_SelectFirstParkingSpace)); //if the user didnt select anything on the box selection, return if (remainingParking.Count < 1) { return; } //if the user didnt select anything on the pick object, return if (pickedOrFirstSelectedParking == null) { return; } //User only parkings with the same type to the first park (picked one) and also order then by the first park remainingParking = remainingParking.Where(e => (e as FamilyInstance).Symbol.Id == (pickedOrFirstSelectedParking as FamilyInstance).Symbol.Id) .OrderBy(e => (e.Location as LocationPoint).Point.DistanceTo((pickedOrFirstSelectedParking.Location as LocationPoint).Point)).ToList(); } using (Transaction t = new Transaction(doc, Properties.Messages.RenumberParking_Transaction)) { t.Start(); if (remainingParking.Count == 1) { lastUsedNumber++; remainingParking.First().get_Parameter(BuiltInParameter.DOOR_NUMBER).Set(inPrefix + lastUsedNumber.ToString()); usedparking.Add(remainingParking.First().Id); } else { Element prevElement = null; remainingParking = remainingParking.Where(p => p is Element).OrderBy(p => { return((p.Location as LocationPoint).Point.DistanceTo((pickedOrFirstSelectedParking.Location as LocationPoint).Point)); }).ToList(); if (prevElement == null) { lastUsedNumber++; remainingParking.First().get_Parameter(BuiltInParameter.DOOR_NUMBER).Set(inPrefix + lastUsedNumber.ToString()); usedparking.Add(remainingParking.First().Id); prevElement = remainingParking.First(); } foreach (Element currentRemaining in remainingParking) { if (isSingleParkingSelected) { double dist = (currentRemaining.Location as LocationPoint).Point.DistanceTo((prevElement.Location as LocationPoint).Point); dist = Utils.ConvertM.feetToM(dist); ParkingTypesInfo currentTypeInfo = parkingInfo.Where(e => e.TypeId == currentRemaining.GetTypeId().IntegerValue).First(); double tolerance = currentTypeInfo.TypeWidth + 0.3; FamilyInstance currentParkInstance = currentRemaining as FamilyInstance; XYZ currenParkOrientation = currentParkInstance.FacingOrientation; FamilyInstance prevParkInstance = prevElement as FamilyInstance; XYZ prevParkOrientation = prevParkInstance.FacingOrientation; if ((dist < tolerance) && (!usedparking.Contains(currentRemaining.Id))) { if (currenParkOrientation.IsAlmostEqualTo(prevParkOrientation, 0.1)) { lastUsedNumber++; currentRemaining.get_Parameter(BuiltInParameter.DOOR_NUMBER).Set(inPrefix + lastUsedNumber.ToString()); usedparking.Add(currentRemaining.Id); prevElement = currentRemaining; } } } else { if (currentRemaining != prevElement) { lastUsedNumber++; currentRemaining.get_Parameter(BuiltInParameter.DOOR_NUMBER).Set(inPrefix + lastUsedNumber.ToString()); usedparking.Add(currentRemaining.Id); prevElement = currentRemaining; } } } } t.Commit(); } } catch (Exception) { } finally { renumberBlocksUI repeatUICreation = new renumberBlocksUI(inPrefix, lastUsedNumber.ToString()); repeatUICreation.ShowDialog(); } }