public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Add an EventLogTraceListener object System.Diagnostics.Trace.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 { IDictionary <string, ISet <string> > values = RebarsUtils.GetPartitionHostMarkDic(doc); Schema schema = ExtensibleStorageUtils.GetSchema(SCHEMA_GUID, SCHEMA_NAME, values); DataStorage dataStorage = ExtensibleStorageUtils.GetDataStorage(doc, DATA_STORAGE_NAME); if (ExtensibleStorageUtils .AssignValues(schema, dataStorage, values)) { TaskDialog.Show("Success!", "Everything has gone smoothly."); } return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception ex) { TaskDialog.Show("Exception", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); System.Diagnostics.Trace.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } finally { myTimer.StopTime(); System.Diagnostics.Trace .Write(string.Format("Time elapsed: {0}s", myTimer.Duration.TotalSeconds)); } }
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) { Tracer.Listeners.Add(new System.Diagnostics.EventLogTraceListener("Application")); UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; RebarsCollectorWnd wnd = null; System.Text.StringBuilder strBld = new System.Text.StringBuilder(); try { List <ViewType> allowedViews = new List <ViewType> { ViewType.EngineeringPlan, ViewType.FloorPlan, ViewType.Section, ViewType.Elevation, ViewType.Detail, ViewType.DraftingView }; List <ElementId> rebarIds = new List <ElementId>(); // if the active view is a sheet, bag all the view belonging to it if (doc.ActiveView.ViewType == ViewType.DrawingSheet) { ViewSheet vs = doc.ActiveView as ViewSheet; foreach (ElementId viewId in vs.GetAllPlacedViews()) { View view = doc.GetElement(viewId) as View; if (allowedViews.Contains(view.ViewType)) { rebarIds.AddRange( RebarsUtils .GetAllRebarIdsInView(view)); } } } else if (allowedViews.Contains(doc.ActiveView.ViewType)) { rebarIds.AddRange( RebarsUtils .GetAllRebarIdsInView(doc.ActiveView)); } if (rebarIds.Count == 0) { TaskDialog.Show("Warning", "No rebars have been collected."); return(Result.Cancelled); } // Get partitions and host marks from the data storage IDictionary <string, ISet <string> > partsHostMarks = ExtensibleStorageUtils.GetValues( ExtensibleStorageUtils.GetSchema(UpdateRepository.SCHEMA_GUID), ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME), UpdateRepository.FN_PARTS_HOST_MARKS); // Dig out assemblies grouped by partition + host mark names IDictionary <string, ISet <string> > partsMarksAssemblies = ExtensibleStorageUtils.GetValues( ExtensibleStorageUtils.GetSchema(UpdateRepository.SCHEMA_GUID), ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME), UpdateRepository.FN_HOST_MARKS_ASSEMBLIES); wnd = new RebarsCollectorWnd(partsHostMarks, partsMarksAssemblies); wnd.ButtonClicked += (sender, e) => { using (Transaction t = new Transaction(doc, "Set rebars' properties")) { t.Start(); foreach (ElementId rebarId in rebarIds) { strBld.Clear(); strBld.AppendFormat("Id: {0}", rebarId.ToString()); // Get hold of the element represented by its id Element rebar = doc.GetElement(rebarId); // See about the partitions Parameter partition = rebar.LookupParameter(RebarsUtils.PARTITION); if (partition != null && !partition.IsReadOnly && e.Partition != null) { partition.Set(e.Partition); } // Set the value in the host mark parameter Parameter hostMark = rebar.LookupParameter(RebarsUtils.HOST_MARK); if (hostMark != null && !hostMark.IsReadOnly && e.HostMark != null) { hostMark.Set(e.HostMark); } // if checked, set the value in the assembly mark parameter Parameter assemblyMark = rebar.LookupParameter(RebarsUtils.ASSEMBLY_MARK); if (assemblyMark != null && !assemblyMark.IsReadOnly && e.AssemblyMark != null) { assemblyMark.Set(e.AssemblyMark); } // if checked and calculable, then set the value Parameter isCalculable = rebar.LookupParameter(RebarsUtils.IS_CALCULABLE); if (e.IsCalculable != null && isCalculable != null && !isCalculable.IsReadOnly) { isCalculable .Set((e.IsCalculable == true ? 1 : 0)); } // if checked and specifiable, then set the value Parameter isSpecifiable = rebar.LookupParameter(RebarsUtils.IS_SPECIFIABLE); if (e.IsSpecifiable != null && isSpecifiable != null && !isSpecifiable.IsReadOnly) { isSpecifiable .Set((e.IsSpecifiable == true ? 1 : 0)); } // if checked and in an assembly, then set the value Parameter isAssembly = rebar.LookupParameter(RebarsUtils.IS_IN_ASSEMBLY); if (e.IsAssembly != null && isAssembly != null && !isAssembly.IsReadOnly) { isAssembly .Set((bool)e.IsAssembly ? 1 : 0); } } t.Commit(); } }; wnd.ShowDialog(); return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions .OperationCanceledException) { return(Result.Cancelled); } catch (System.Exception ex) { if (wnd != null) { wnd.Close(); } TaskDialog.Show("Exception", string.Format("{0}\n{1}\n{2}", strBld.ToString(), ex.Message, ex.StackTrace)); Tracer.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } }
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)); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Add an EventLogTraceListener object System.Diagnostics.Trace.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 { // Track down all partitions as well as map them // to host marks IDictionary <string, ISet <string> > partHostValues = RebarsUtils.GetPartitionHostMarkDic(doc); RebarContainer rebarContainer = new RebarContainer(); foreach (FamilyInstance fi in RebarsUtils.GetAllRebarsInDoc(doc)) { GeneralRebar rebar = new GeneralRebar(fi); rebarContainer.Add(rebar); } // Dig up all host marks and map them // to assemblies IDictionary <string, ISet <string> > hostAssemblyValues = rebarContainer.GetHostAssemblies(); // Get hold of all partitions and // map them to structural types SortedList <string, SortedSet <string> > partsStrTypes = TektaRevitPlugins.Multischedule.MultischeduleUtils.DigUpPartsStrTypes(doc); Schema schema = ExtensibleStorageUtils.GetSchema( SCHEMA_GUID, SCHEMA_NAME, FN_PARTS_HOST_MARKS, FN_HOST_MARKS_ASSEMBLIES, FN_PARTS_STR_TYPES); DataStorage dataStorage = ExtensibleStorageUtils.GetDataStorage( doc, DATA_STORAGE_NAME); ExtensibleStorageUtils .AssignValues(schema, dataStorage, FN_PARTS_HOST_MARKS, FN_HOST_MARKS_ASSEMBLIES, FN_PARTS_STR_TYPES, partHostValues, hostAssemblyValues, partsStrTypes); TaskDialog.Show("Success!", "Repository has been updated."); return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception ex) { TaskDialog.Show("Exception", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); System.Diagnostics.Trace.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } finally { myTimer.StopTime(); System.Diagnostics.Trace .Write(string.Format("Time elapsed: {0}s", myTimer.Duration.TotalSeconds)); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Add an EventLogTraceListener object System.Diagnostics.Trace.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 { int i = 0; string partsHostMarks = UpdateRepository.FN_PARTS_HOST_MARKS; while (i < 2) { IDictionary <string, ISet <string> > values = ExtensibleStorageUtils.GetValues( ExtensibleStorageUtils.GetSchema(UpdateRepository.SCHEMA_GUID), ExtensibleStorageUtils.GetDataStorage(doc, UpdateRepository.DATA_STORAGE_NAME), partsHostMarks); StringBuilder strBld = new StringBuilder(); foreach (string key in values.Keys) { strBld.AppendLine(key); foreach (string value in values[key]) { strBld.Append(string.Format("{0} ", value)); } strBld.AppendLine(); } Tracer.Write(strBld.ToString()); strBld.Clear(); ++i; partsHostMarks = UpdateRepository.FN_HOST_MARKS_ASSEMBLIES; } return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception ex) { TaskDialog.Show("Exception", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); System.Diagnostics.Trace.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } finally { myTimer.StopTime(); System.Diagnostics.Trace .Write(string.Format("Time elapsed: {0}s", myTimer.Duration.TotalSeconds)); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; try { Schema schema = Schema.Lookup(UpdateRepository.PRECURSORY_GUID); using (Transaction t = new Transaction(doc, "Do away with the schema")) { if (t.Start() == TransactionStatus.Started) { Element ds = ExtensibleStorageUtils .GetDataStorage(doc, UpdateRepository.FOREGOING_DATA_STORAGE_NAME); if (ds != null) { doc.Delete(ds.Id); if (t.Commit() == TransactionStatus.Committed) { TaskDialog.Show("Info", "The data storage element has been discarded"); } else { t.RollBack(); return(Result.Failed); } } else { TaskDialog.Show("Info", "No such data storage element in the document."); t.RollBack(); } if (t.Start() == TransactionStatus.Started) { Schema.EraseSchemaAndAllEntities(schema, true); if (t.Commit() == TransactionStatus.Committed) { TaskDialog.Show("Schema Remove", "The schema has been disposed of."); } } else { t.RollBack(); return(Result.Failed); } } else { return(Result.Failed); } } return(Result.Succeeded); } catch (Exception ex) { TaskDialog.Show("Exception", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); System.Diagnostics.Trace.Write(string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); return(Result.Failed); } }