public QLFabricationServiceResolve(FabricationService _fabService, Field qlFabricationPartsField) { id = _fabService.ServiceId.ToString(); name = _fabService.Name; if (qlFabricationPartsField != null) { Autodesk.Revit.DB.Document _doc = ResolverEntry.Doc; List <FabricationPart> objectList = new FilteredElementCollector(_doc).OfClass(typeof(FabricationPart)). Select(x => (x as FabricationPart)).Where(x => x.ServiceId.ToString() == id).ToList(); var nameFiltersContained = GraphQlHelpers.GetArgumentStrings(qlFabricationPartsField, "nameFilter"); var queryFieldForParameters = GraphQlHelpers.GetFieldFromSelectionSet(qlFabricationPartsField, "qlParameters"); qlFabricationParts = new List <QLFabricationPart>(); foreach (FabricationPart aFabPart in objectList) { if (nameFiltersContained.Count == 0 || nameFiltersContained.Contains(aFabPart.Name)) { qlFabricationParts.Add(new QLFabricationPartResolve(aFabPart, queryFieldForParameters)); } } } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData , ref string message, ElementSet elements) { try { Document doc = commandData.Application.ActiveUIDocument.Document; using (Transaction tr = new Transaction(doc, "Set button and group exclusions")) { tr.Start(); FabricationConfiguration config = FabricationConfiguration.GetFabricationConfiguration(doc); if (config == null) { message = "No fabrication configuration loaded."; return(Result.Failed); } // get all loaded fabrication services IList <FabricationService> allLoadedServices = config.GetAllLoadedServices(); // get the "ADSK - HVAC:Supply Air" service string serviceName = "ADSK - HVAC: Supply Air"; FabricationService selectedService = allLoadedServices.FirstOrDefault(x => x.Name == serviceName); if (selectedService == null) { message = $"Could not find fabrication service {serviceName}"; return(Result.Failed); } string rectangularGroupName = "Rectangular"; string roundGroupName = "Round Bought Out"; string excludeButtonName = "Square Bend"; int rectangularGroupIndex = -1; int roundGroupIndex = -1; // find Rectangular and Round groups in service for (int i = 0; i < selectedService.GroupCount; i++) { if (selectedService.GetGroupName(i) == rectangularGroupName) { rectangularGroupIndex = i; } if (selectedService.GetGroupName(i) == roundGroupName) { roundGroupIndex = i; } if (rectangularGroupIndex > -1 && roundGroupIndex > -1) { break; } } if (rectangularGroupIndex > -1) { // exclude square bend in Rectangular group for (int i = 0; i < selectedService.GetButtonCount(rectangularGroupIndex); i++) { if (selectedService.GetButton(rectangularGroupIndex, i).Name == excludeButtonName) { selectedService.OverrideServiceButtonExclusion(rectangularGroupIndex, i, true); break; } } } else { message = $"Unable to locate {excludeButtonName} button to exclude."; return(Result.Failed); } // exclude entire Round Bought Out service group if (roundGroupIndex > -1) { selectedService.SetServiceGroupExclusions(new List <int>() { roundGroupIndex }); } else { message = $"Unable to locate {roundGroupName} service group to exclude."; return(Result.Failed); } tr.Commit(); TaskDialog td = new TaskDialog("Button and Group Exclsuions") { MainIcon = TaskDialogIcon.TaskDialogIconInformation, TitleAutoPrefix = false, MainInstruction = "Operation Successful", MainContent = $"Excluded {excludeButtonName} button from {serviceName} {rectangularGroupName} Group {Environment.NewLine}" + $"Excluded {roundGroupName} Group from {serviceName}" }; td.Show(); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Convenience method to locate a fabrication service button specified by group and name. /// </summary> /// <param name="service"> /// The fabrication service. /// </param> /// <param name="group"> /// The fabrication service group index. /// </param> /// <param name="name"> /// The fabrication service button name. /// </param> /// <returns> /// Returns the fabrication service button as specified by the fabrication service, group and name. /// </returns> FabricationServiceButton locateButton(FabricationService service, int group, string name) { FabricationServiceButton button = null; if (service != null && group >= 0 && group < service.GroupCount) { int buttonCount = service.GetButtonCount(group); for (int i = 0; button == null && i < buttonCount; i++) { FabricationServiceButton bt = service.GetButton(group, i); if (bt != null && bt.Name.Equals(name)) button = bt; } } return button; }