private Dictionary <string, List <object> > GenerateWorksetNames(string path) { // Create COM Objects. Create a COM object for everything that is referenced Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(path); Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Excel.Range xlRange = xlWorksheet.UsedRange; // initialize a dictionary of object[] to hold workset names Dictionary <string, List <object> > worksetDictionary = new Dictionary <string, List <object> >() { { WorksetCreatorConstants.newWorksets, new List <object>() }, { WorksetCreatorConstants.existingWorksets, new List <object>() }, }; // collect all user created worksets from the revit document FilteredWorksetCollector revitWorksets = new FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset); // iterate through the excel sheet for (int i = 2; i <= 100; i++) { // check that we don't have a null if (xlRange.Cells[i, 1] != null && xlRange.Cells[i, 1].Value2 != null) { // save the workset name as a variable string worksetName = xlRange.Cells[i, 1].Value2.ToString(); // see if the excel workset already exists in revit if (revitWorksets.Where(w => w.Name == worksetName).FirstOrDefault() == null) { worksetDictionary[WorksetCreatorConstants.newWorksets].Add(worksetName); } else { worksetDictionary[WorksetCreatorConstants.existingWorksets].Add(worksetName); } } else { // break if there's a null break; } } // close workbook and release xlWorkbook.Close(); // quit excel and release xlApp.Quit(); return(worksetDictionary); }
public static Workset Workset(this Document document, string worksetName) { // Skip non-workshared documents and null/empty workset names if (!document.IsWorkshared || string.IsNullOrWhiteSpace(worksetName)) { BH.Engine.Reflection.Compute.RecordError("Document must be work shared to contain worksets, and workset name cannot be null or empty."); return(null); } // Find a workset with a specified name if it exists FilteredWorksetCollector worksets = new FilteredWorksetCollector(document).OfKind(WorksetKind.UserWorkset); // Find all user worksets return(worksets.Where(x => x.Name == worksetName).FirstOrDefault()); // Return the specified workset if it exists or null if it doesn't }