internal void SetBlockAndPartition(Subschedule template, IMultitableSchedule multiSchedule) { if (template.Id == ElementId.InvalidElementId) { return; } Element subSchd = m_doc.GetElement(template.Id); //Parameter blockNo = subSchd.LookupParameter(RebarsUtils.BLOCK_NUMBER); Parameter blockNo = subSchd.LookupParameter( MultischeduleParameters.BLOCK_NUMBER); //Parameter partition = subSchd.LookupParameter(RebarsUtils.PARTITION); Parameter partition = subSchd.LookupParameter( MultischeduleParameters.PARTITION); if (blockNo != null) { blockNo.Set(multiSchedule .FiltersValues[MultischeduleParameters.BLOCK_NUMBER]); } if (partition != null) { partition.Set(multiSchedule .FiltersValues[MultischeduleParameters.PARTITION]); } }
internal void SetSubschedules(IMultitableSchedule multiSchd) { for (int i = 0; i < multiSchd.ViewNameEndings.Count; ++i) { ElementId tmplId = FindTemplateByViewNameEnding(multiSchd.ViewNameEndings[i]); if (tmplId != null) { Subschedule subSchedule = new Subschedule { Id = tmplId, IsTemplate = true, ViewName = GenerateViewName(multiSchd, i), ShowTitle = false }; if (i == 0 && multiSchd.FiltersValues[ MultischeduleParameters.SHOW_TITLE].Equals("1")) { subSchedule.ShowTitle = true; } multiSchd.Subschedules.Add(subSchedule); } } }
internal void UpdateFilters(Subschedule template, IMultitableSchedule multiSchedule) { ViewSchedule vs = m_doc.GetElement(template.Id) as ViewSchedule; for (int j = 0; j < multiSchedule.FiltersValues.Count; ++j) { string fltrName = multiSchedule.FiltersValues.Keys.ElementAt(j); dynamic value = multiSchedule.FiltersValues[fltrName]; UpdateFilter(fltrName, value, vs.Definition); } }
internal void CarryOutSpecificOperations(IMultitableSchedule multiSchd) { if (multiSchd is RebarQuantityTakeoff) { ((RebarQuantityTakeoff)multiSchd) .HideZeroFieldsMaterialTakeOff(m_doc); } else if (multiSchd is BarBendingByStructure || multiSchd is BarBendingByAssembly) { System.Diagnostics.Trace.Write( string.Format("Id: {0}", multiSchd.Subschedules[0].Id)); HideEmptyColumns(multiSchd.Subschedules[0].Id); } }
internal void FindExistingSchedules(IMultitableSchedule multiSchedule) { for (int i = 0; i < multiSchedule.Subschedules.Count; ++i) { ElementId extSchdId = FindScheduleByName(multiSchedule.Subschedules[i].ViewName); if (extSchdId != null) { multiSchedule.Subschedules[i].Id = extSchdId; multiSchedule.Subschedules[i].IsTemplate = false; } else { multiSchedule.Templates.Add(multiSchedule.Subschedules[i]); } } }
internal void SetNewTitle(IMultitableSchedule multiSchd) { if (multiSchd is AssemblySchedule && multiSchd.Subschedules[0].ShowTitle) { ViewSchedule vs = m_doc.GetElement(multiSchd.Subschedules[0].Id) as ViewSchedule; string newTitle = "Спецификация элементов " + multiSchd.FiltersValues[MultischeduleParameters.ASSEMBLY_MARK]; vs.GetTableData() .GetSectionData(SectionType.Header) .SetCellText(vs.GetTableData().GetSectionData(SectionType.Header).FirstRowNumber, vs.GetTableData().GetSectionData(SectionType.Header).FirstColumnNumber, newTitle); } }
private string GenerateViewName(IMultitableSchedule multiSchd, int index) { string partition; string hostMark; string assembly; if (multiSchd.FiltersValues.TryGetValue( MultischeduleParameters.PARTITION, out partition) && multiSchd.FiltersValues.TryGetValue( MultischeduleParameters.HOST_MARK, out hostMark) && multiSchd.FiltersValues.TryGetValue( MultischeduleParameters.ASSEMBLY_MARK, out assembly)) { return(string.Format("{0} - {1} - {2} - {3}", partition, hostMark, assembly, multiSchd.ViewNameEndings[index] )); } else if (multiSchd.FiltersValues.TryGetValue( MultischeduleParameters.PARTITION, out partition) && multiSchd.FiltersValues.TryGetValue( MultischeduleParameters.HOST_MARK, out hostMark)) { return(string.Format("{0} - {1} - {2}", partition, hostMark, multiSchd.ViewNameEndings[index] )); } else if (multiSchd.FiltersValues .TryGetValue(MultischeduleParameters.PARTITION, out partition)) { return(string.Format("{0} - {1}", partition, multiSchd.ViewNameEndings[index] )); } else { throw new NotImplementedException("Partion and hostMark are both null."); } }
internal void PlaceOnSheet(ViewSheet sheet, IMultitableSchedule multiSchedule) { XYZ placementPoint = new XYZ(0, 0, 0); for (int i = 0; i < multiSchedule.Subschedules.Count; ++i) { if (multiSchedule.Subschedules[i].Id == ElementId.InvalidElementId) { continue; } ScheduleSheetInstance scheduleInstance = ScheduleSheetInstance .Create(m_doc, sheet.Id, multiSchedule.Subschedules[i].Id, placementPoint); placementPoint = new XYZ(0, scheduleInstance.get_BoundingBox(sheet).Min.Y + BORDER_WIDTH, 0); } }
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; // For reporting exceptions StringBuilder reporter = new StringBuilder(); // 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; IDictionary <string, ISet <string> > partsStrTypes = null; try { partitionHostMarks = ExtensibleStorageUtils.GetValues( schema, dataStorage, UpdateRepository.FN_PARTS_HOST_MARKS); hostMarkAssemblies = ExtensibleStorageUtils.GetValues( schema, dataStorage, UpdateRepository.FN_HOST_MARKS_ASSEMBLIES); partsStrTypes = ExtensibleStorageUtils.GetValues( schema, dataStorage, UpdateRepository.FN_PARTS_STR_TYPES); 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); } // Create a window and subscribe to its event WndMultitableSchedule wnd = new WndMultitableSchedule( partitionHostMarks, hostMarkAssemblies, partsStrTypes); wnd.OkClicked += (sender, args) => { // Turn out a multi-table schedule IMultitableSchedule multiSchd = MultitableScheduleFactory.CreateMultiTableSchedule( args.MultischeduleType, args.ParametersValues ); // Produce a manip MultischeduleManipulator manip = new MultischeduleManipulator(doc); // 1. Populate the subschedule manip.SetSubschedules(multiSchd); // 2. Find Existing Schedules manip.FindExistingSchedules(multiSchd); using (Transaction t = new Transaction(doc, "Produce a Multischedule")) { t.Start(); for (int i = 0; i < multiSchd.Templates.Count; ++i) { System.Diagnostics.Trace.Write(string.Format("ID:{0}; VN:{1}; ", multiSchd.Templates[i].Id, multiSchd.Templates[i].ViewName)); // Duplicate template manip.DuplicateSchedules(multiSchd.Templates[i]); // Rename template manip.RenameSchedules(multiSchd.Templates[i]); // Update the filters of the template manip.UpdateFilters(multiSchd.Templates[i], multiSchd); // Discard an empty template if (manip.DiscardEmptySchedule(multiSchd.Templates[i])) { continue; } // Show the title manip.ShowTitle(multiSchd.Templates[i]); // Set Block Number and Partition to certain values manip.SetBlockAndPartition(multiSchd.Templates[i], multiSchd); } // Schedule-specific settings manip.CarryOutSpecificOperations(multiSchd); // Change the title manip.SetNewTitle(multiSchd); t.Commit(); // Place on a sheet if the active view is of DrawingSheet type if (doc.ActiveView.ViewType == ViewType.DrawingSheet) { t.Start(); manip.PlaceOnSheet((ViewSheet)doc.ActiveView, multiSchd); t.Commit(); } } }; // Show the window try { wnd.ShowDialog(); } finally { wnd.Close(); } 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)); } }