public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Tracer.Listeners.Add(new System.Diagnostics.EventLogTraceListener("Application")); UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; RebarsMarkerWnd wnd = null; try { // Get all the necessary particulars about partitions and // host marks from the repository Schema schema = ExtensibleStorageUtils .GetSchema(UpdateRepository.SCHEMA_GUID); if (schema == null) { TaskDialog.Show("Warning", "No repository exists. " + "Please generate one before proceeding with this command."); return(Result.Cancelled); } // Dig up the data storage element Autodesk.Revit.DB.ExtensibleStorage.DataStorage ds = ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME); if (ds == null) { TaskDialog.Show("Warning", "No data storage element. " + "Please update the repository."); return(Result.Cancelled); } // Retrieve host marks grouped by partition IDictionary <string, ISet <string> > partsHostMarks = ExtensibleStorageUtils.GetValues( schema, ds, UpdateRepository.FN_PARTS_HOST_MARKS); if (partsHostMarks.Keys.Count == 0) { TaskDialog.Show("Warning", "No rebars to mark have been bagged."); return(Result.Cancelled); } // Get hold of all assemblies grouped by host marks IDictionary <string, ISet <string> > hostMarksAssemblies = ExtensibleStorageUtils.GetValues( schema, ds, UpdateRepository.FN_HOST_MARKS_ASSEMBLIES); wnd = new RebarsMarkerWnd(partsHostMarks, hostMarksAssemblies); wnd.OkClicked += (sender, args) => { IList <FamilyInstance> filteredRebars = null; if (args.Assemblies.Count == 0) { filteredRebars = //GetRebarsNotInAssemblyByPartitionHostMark( // doc, // args.Partition, // args.HostMark); RebarsUtils.GetAllRebars( doc, args.Partition, args.HostMark) .Cast <FamilyInstance>() .ToList(); } else { filteredRebars = //GetRebarsByPartitionHostMarkAssembly( // doc, // args.Partition, // args.HostMark, // args.Assemblies.ElementAt(i)); RebarsUtils.GetAllRebars( doc, args.Partition, args.HostMark, args.Assemblies.ToList()) .Cast <FamilyInstance>() .ToList(); } Tracer.Write("The number of rebars looked up amounts to " + filteredRebars.Count); // Group the rebars into three categories and mark them GroupRebars(filteredRebars); }; wnd.ShowDialog(); return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions .OperationCanceledException) { return(Result.Cancelled); } catch (System.Exception ex) { string errorMsg = string.Format("{0}\n{1}", ex.Message, ex.StackTrace); Tracer.Write(errorMsg); TaskDialog.Show("Exception", errorMsg); return(Result.Failed); } finally { if (wnd != null) { wnd.Close(); } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Add an EventLogTraceListener object Tracer.Listeners.Add( new System.Diagnostics.EventLogTraceListener("Application")); // Lay the hands on the active document UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; // set up a timer Timing myTimer = new Timing(); myTimer.StartTime(); try { // Try retrieving partitions, host marks and assemblies from the repository (schema) Schema schema = ExtensibleStorageUtils.GetSchema(UpdateRepository.SCHEMA_GUID); if (schema == null) { TaskDialog.Show("Message", "Please update the repository."); return(Result.Failed); } DataStorage dataStorage = ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME); IDictionary <string, ISet <string> > partitionHostMarks = null; IDictionary <string, ISet <string> > hostMarkAssemblies = null; try { partitionHostMarks = ExtensibleStorageUtils.GetValues( schema, dataStorage, UpdateRepository.FN_PARTS_HOST_MARKS); hostMarkAssemblies = ExtensibleStorageUtils.GetValues( schema, dataStorage, UpdateRepository.FN_HOST_MARKS_ASSEMBLIES); if (partitionHostMarks.Count == 0 || hostMarkAssemblies.Count == 0) { throw new Exception("No rebars have been detected."); } } catch (UpdateRepositoryException ex) { TaskDialog.Show("Warning", ex.Message); return(Result.Failed); } catch (Exception ex) { TaskDialog.Show("Warning", ex.Message); return(Result.Failed); } return(Result.Failed); //WndMultitableSchedule wnd = //new WndMultitableSchedule(partitionHostMarks, hostMarkAssemblies); /*wnd.OkClicked += (sender, args) => * { * ComboScheduleGenerator scheduleGenerator = * new ComboScheduleGenerator( * doc, * args.MultiTableScheduleType, * args.ParametersValues, * args.ShowTitle); * * scheduleGenerator.CreateSubSchedules(doc); * * if (doc.ActiveView.ViewType == ViewType.DrawingSheet) * { * scheduleGenerator.PlaceOnSheet((ViewSheet)doc.ActiveView); * } * }; * try * { * wnd.ShowDialog(); * return Result.Succeeded; * } * catch (Exception ex) * { * wnd.Close(); * throw ex; * }*/ } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (RenameException) { return(Result.Cancelled); } catch (Exception ex) { TaskDialog.Show("Exception", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); Tracer.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } finally { myTimer.StopTime(); Tracer.Write(string.Format("Time elapsed: {0}s", myTimer.Duration.TotalSeconds)); } }
private void InternalSetSchema(Autodesk.Revit.DB.ExtensibleStorage.Schema schema) { InternalSchema = schema; }
public void Execute(UpdaterData data) { Document doc = data.GetDocument(); // Get the schema Autodesk.Revit.DB.ExtensibleStorage.Schema schema = Autodesk.Revit.DB.ExtensibleStorage.Schema.Lookup(schemaGUID); Autodesk.Revit.DB.ExtensibleStorage.Entity entity = null; try { entity = doc.ProjectInformation.GetEntity(schema); } catch { } if (entity != null) { IList <ElementId> elementIds = entity.Get <IList <ElementId> >("ScheduleId"); if (elementIds.Count > 0) { IList <string> paths = entity.Get <IList <string> >("ExcelFilePath"); IList <string> worksheets = entity.Get <IList <string> >("WorksheetName"); IList <string> dateTimes = entity.Get <IList <string> >("DateTime"); IList <int> pathTypes = entity.Get <IList <int> >("PathType"); foreach (ElementId deletedId in data.GetDeletedElementIds()) { try { // Check if it's in the linked schedules int index = -1; for (int i = 0; i < elementIds.Count; i++) { ElementId id = elementIds[i]; if (id.IntegerValue == deletedId.IntegerValue || id.IntegerValue == -1) { index = i; } } if (index >= 0) { elementIds.RemoveAt(index); worksheets.RemoveAt(index); dateTimes.RemoveAt(index); paths.RemoveAt(index); pathTypes.RemoveAt(index); // if there is still more than one element in the lists, reassign them to the entity, otherwise purge it. if (elementIds.Count > 0) { entity.Set("ScheduleId", elementIds); entity.Set("ExcelFilePath", paths); entity.Set("WorksheetName", worksheets); entity.Set("DateTime", dateTimes); entity.Set("PathType", pathTypes); doc.ProjectInformation.SetEntity(entity); } else { // Delete the entity data doc.ProjectInformation.DeleteEntity(schema); } } } catch { } } } } }
public Schema(Autodesk.Revit.DB.ExtensibleStorage.Schema schema) { InitSchema(schema); }