public static int countFail = 0; // number of elements failed public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; Application app = uiapp.Application; Document doc = commandData.Application.ActiveUIDocument.Document; // add event handler for when the app does not find the ArpUtilies.dll assembly //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); #region check if it is family document if (doc.IsFamilyDocument) { using (UI.Form_Info3 thisForm = new UI.Form_Info3()) { thisForm.ShowDialog(); return(Result.Cancelled); } } #endregion #region warn the user if he wants to proceed using (UI.Warning.Form_Warning thisForm = new UI.Warning.Form_Warning()) { thisForm.ShowDialog(); if (thisForm.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return(Result.Cancelled); } } #endregion #region remove elevation tags using (TransactionGroup tg = new TransactionGroup(doc, "Remove Elevation Tags")) { tg.Start(); count = 0; // reset the counter for when the app is run more than once foreach (Element e in new FilteredElementCollector(doc) .OfClass(typeof(ElevationMarker)) .WhereElementIsNotElementType() .ToElements()) { ElevationMarker em = e as ElevationMarker; // only proceed with empty elevation marks if (em.HasElevations() == false) { string elevType = doc.GetElement(e.GetTypeId()).Name; //string itemInfo = "ID: " + "\t" + e.Id + " Elevation Type: " + elevType; //string itemFail = "ID: " + "\t" + e.Id + " Elevation Type: " + elevType; string itemInfo = string.Format("Elevation Type: {0} (ID: {1})", elevType, e.Id); string itemFail = string.Format("Elevation Type: {0} (ID: {1})", elevType, e.Id); try { // delete item using (Transaction t = new Transaction(doc, "Remove Single Elevation Tag")) { t.Start(); doc.Delete(e.Id); t.Commit(); } // collect info info.Add(itemInfo); count += 1; } catch (Exception) { infoFail.Add(itemFail); countFail += 1; } } } tg.Assimilate(); } #endregion // if count = 0 show Not Found form if (count == 0) { using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } // show Results Form if (count != 0) { using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); } } #region get analytics //try //{ // Utilities.GetAnalyticsCSV(doc, app); //} //catch (Exception) //{ //} #endregion return(Result.Succeeded); }
private void BtnOK_Click(object sender, EventArgs e) { if (RbtFlipHand.Checked == false && RbtFlipFacing.Checked == false && RbtFlipWalls.Checked == false) { infoMsgMain = "Choose option"; infoMsgBody = "You need to choose an option in order to flip."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } if (RbtFlipHand.Checked == true) { if (!GetSelectedDoors(m_uidoc).Any()) { infoMsgMain = "Select"; infoMsgBody = "You need to select a door."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } else { executionTime.Start(); // collect data for analytics IList <FamilyInstance> doorInstances = GetSelectedDoors(m_uidoc).Cast <FamilyInstance>().ToList(); elemTry = doorInstances.Count(); elemSuccess = 0; elemFail = 0; using (Transaction t = new Transaction(m_doc, "Flip Door Hand")) { t.Start(); try { foreach (FamilyInstance fi in doorInstances) { fi.flipHand(); elemSuccess += 1; } } catch (Exception) { elemFail += 1; } t.Commit(); } executionTime.Stop(); // collect data for analytics ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString(); // collect data for analytics // show Results Form using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()){ thisForm.ShowDialog(); } DialogResult = DialogResult.OK; useTime.Stop(); UseTimeElapseS = useTime.Elapsed.Seconds.ToString(); // collect data for analytics Ana_NoOfFlippedDoors = elemSuccess; // collect data for analytics Utilities.GetAnalyticsCSV(m_doc, m_app); // collect data for analytics FlipAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfFlippedWalls, Ana_NoOfFlippedDoors); // collect data for analytics } } if (RbtFlipFacing.Checked == true) { if (!GetSelectedDoors(m_uidoc).Any()) { infoMsgMain = "Select"; infoMsgBody = "You need to select one or more doors."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } else { executionTime.Start(); // collect data for analytics IList <FamilyInstance> doorInstances = GetSelectedDoors(m_uidoc).Cast <FamilyInstance>().ToList(); elemTry = doorInstances.Count(); elemSuccess = 0; elemFail = 0; using (Transaction t = new Transaction(m_doc, "Flip Door Facing")) { t.Start(); try { foreach (FamilyInstance fi in doorInstances) { fi.flipFacing(); elemSuccess += 1; } } catch (Exception) { elemFail += 1; } t.Commit(); } executionTime.Stop(); // collect data for analytics ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString(); // collect data for analytics // show Results Form using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); } DialogResult = DialogResult.OK; useTime.Stop(); UseTimeElapseS = useTime.Elapsed.Seconds.ToString(); // collect data for analytics Ana_NoOfFlippedDoors = elemSuccess; // collect data for analytics Utilities.GetAnalyticsCSV(m_doc, m_app); // collect data for analytics FlipAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfFlippedWalls, Ana_NoOfFlippedDoors); // collect data for analytics } } if (RbtFlipWalls.Checked == true) { if (!GetSelectedWalls(m_uidoc).Any()) { infoMsgMain = "Select"; infoMsgBody = "You need to select one or more walls."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } else { executionTime.Start(); // collect data for analytics IList <Wall> wallInstances = GetSelectedWalls(m_uidoc).Cast <Wall>().ToList(); elemTry = wallInstances.Count(); elemSuccess = 0; elemFail = 0; using (TransactionGroup tg = new TransactionGroup(m_doc, "Flip Walls")) { tg.Start(); foreach (Wall w in wallInstances) { try { Parameter loc_line = w.get_Parameter(BuiltInParameter.WALL_KEY_REF_PARAM); int currentValue = loc_line.AsInteger(); using (Transaction t = new Transaction(m_doc, "Change Location Line")) { t.Start(); loc_line.Set(0); t.Commit(); } using (Transaction t = new Transaction(m_doc, "Flip the wall")) { t.Start(); w.Flip(); elemSuccess += 1; loc_line.Set(currentValue); t.Commit(); } } catch (Exception) { elemFail += 1; } } tg.Assimilate(); } executionTime.Stop(); // collect data for analytics ExecTimeElapseS = executionTime.Elapsed.Seconds.ToString(); // collect data for analytics // show Results Form using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); } DialogResult = DialogResult.OK; useTime.Stop(); UseTimeElapseS = useTime.Elapsed.Seconds.ToString(); // collect data for analytics Ana_NoOfFlippedWalls = elemSuccess; Utilities.GetAnalyticsCSV(m_doc, m_app); // collect data for analytics FlipAnalytics(m_doc, m_app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfFlippedWalls, Ana_NoOfFlippedDoors); // collect data for analytics } } }
private void BtnOK_Click(object sender, EventArgs e) { // list of checked indices List <int> checkedIndices = new List <int>(); foreach (int index in LsvUnused.CheckedIndices) { checkedIndices.Add(index); } // message if there are no items selected if (LsvUnused.CheckedIndices.Count == 0) { using (UI.Info.Form_Info2 thisForm = new UI.Info.Form_Info2()) { thisForm.ShowDialog(); } } else // go ahead with deleting { // list of ElementIds of selected items List <ElementId> unusedItems = unusedTypesIds; List <ElementId> selectedItems = new List <ElementId>(); foreach (int index in checkedIndices) { selectedItems.Add(unusedItems[index]); } // delete items using (Transaction t = new Transaction(m_doc, "Purge Dimension Styles")) { t.Start(); foreach (ElementId eid in selectedItems) { try { infoList.Add(m_doc.GetElement(eid).Name); nOfItems += 1; m_doc.Delete(eid); } catch (Exception) { itemExceptList.Add(m_doc.GetElement(eid).Name); infoList.Remove(m_doc.GetElement(eid).Name); nOfItems -= 1; continue; } } t.Commit(); } // show results form using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); } this.DialogResult = DialogResult.OK; //try //{ // Utilities.GetAnalyticsCSV(m_doc, m_app); //} //catch (Exception) //{ //} } }
private void BtnOK_Click(object sender, EventArgs e) { // handle error if no data is selected if (CbxCategories.SelectedItem == null) { // show Wrong Selection form using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } else { Category cat = CbxCategories.SelectedItem as Category; elemTry = GetInstances(m_doc, cat).Count(); KeyValuePair <Parameter, string> targetKeyValuePair = (KeyValuePair <Parameter, string>)CbxTargetParameters.SelectedItem; Parameter targetParam = targetKeyValuePair.Key; using (TransactionGroup tg = new TransactionGroup(m_doc, "Parameter Mapper")) { tg.Start(); // for each element of the selected category foreach (Element elem in GetInstances(m_doc, cat)) { using (Transaction t = new Transaction(m_doc, "Parameter Mapper Single Transaction")) { t.Start(); try { Parameter elemTargetParam = elem.get_Parameter(targetParam.Definition); if (RbtElementId.Checked == true) // when Element Id is selected { string eId = elem.Id.ToString(); elemTargetParam.Set(eId); t.Commit(); } else if (RbtSourceParam.Checked == true && RbtAsText.Checked == true) // when "Number As Text" is selected { KeyValuePair <Parameter, string> sourceKeyValuePair = (KeyValuePair <Parameter, string>)CbxSourceParameters.SelectedItem; Parameter sourceParam = sourceKeyValuePair.Key; Parameter elemSourceParam = elem.get_Parameter(sourceParam.Definition); string sourceValueString = GetParamValueAsString(elemSourceParam); elemTargetParam.Set(sourceValueString); t.Commit(); } else // when "Number As Number" is selected { KeyValuePair <Parameter, string> sourceKeyValuePair = (KeyValuePair <Parameter, string>)CbxSourceParameters.SelectedItem; Parameter sourceParam = sourceKeyValuePair.Key; Parameter elemSourceParam = elem.get_Parameter(sourceParam.Definition); if (elemSourceParam.StorageType != StorageType.Double) { string sourceValueString = GetParamValueAsString(elemSourceParam); elemTargetParam.Set(sourceValueString); t.Commit(); } else { if (RbtAsNumber.Checked == true) { double sourceValueDouble = elemSourceParam.AsDouble(); elemTargetParam.Set(sourceValueDouble); t.Commit(); } else { string sourceValueString = GetParamValueAsString(elemSourceParam); elemTargetParam.Set(sourceValueString); t.Commit(); } } } } catch (Exception) { elemFail += 1; } } } tg.Assimilate(); } using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); } DialogResult = DialogResult.OK; } }
private void BtnOK_Click(object sender, EventArgs e) { CopyPasteOptions copyOpt = new CopyPasteOptions(); Document sourceDoc = CbxOpenDocs.SelectedItem as Document; List <ElementId> templatesToCopy = new List <ElementId>(); List <string> duplicatedNames = new List <string>(); List <string> transferredViews = new List <string>(); // is there at least one item selected? if (ClbTemplates.CheckedItems.Count == 0) { UI.Info.Form_Info1.infoMsgMain = "Select"; UI.Info.Form_Info1.infoMsgBody = "Select one or more View Templates to continue."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } // proceed to transfer try { foreach (Autodesk.Revit.DB.View v in ClbTemplates.CheckedItems) { templatesToCopy.Add(v.Id); transferredViews.Add(v.Name); // get duplicated names if (GetViewTemplateNames(m_doc).Contains(v.Name)) { duplicatedNames.Add(v.Name); } } // show message if there are duplicated names if (duplicatedNames.Any()) { resultHead = "Information"; resultMain = "The following templates already exist or have the same name:"; resultBody = duplicatedNames; // show message if there are duplicates using (UI.Info.Form_DupResults thisForm = new UI.Info.Form_DupResults()) { thisForm.ShowDialog(); // transfer view templates y pressed 'Yes' if (thisForm.DialogResult == DialogResult.Yes) { using (Transaction t = new Transaction(m_doc, "Transfer View Templates")) { t.Start(); ElementTransformUtils.CopyElements(sourceDoc, templatesToCopy, m_doc, Transform.Identity, copyOpt); t.Commit(); } // show Results Form resultHead = "Result"; resultMain = "The following View Templates have been transferred:"; resultBody = transferredViews; using (UI.Info.Form_Results ResultForm = new UI.Info.Form_Results()) { ResultForm.ShowDialog(); } DialogResult = DialogResult.OK; } } } // go ahead if no duplicates else { using (Transaction t = new Transaction(m_doc, "Transfer View Templates")) { t.Start(); ElementTransformUtils.CopyElements(sourceDoc, templatesToCopy, m_doc, Transform.Identity, copyOpt); t.Commit(); } // show Results Form resultHead = "Result"; resultMain = "The following View Templates have been transferred:"; resultBody = transferredViews; using (UI.Info.Form_Results ResultForm = new UI.Info.Form_Results()) { ResultForm.ShowDialog(); } DialogResult = DialogResult.OK; } } catch (Exception) { } }
private void btnOK_Click(object sender, EventArgs e) { //get list of checked indices List <int> checkedIndices = new List <int>(); foreach (int indexChecked in clbViewFilters.CheckedIndices) { checkedIndices.Add(indexChecked); } //check if there are any boxes checked if (!checkedIndices.Any()) { using (UI.Info.Form_Info2 thisForm = new UI.Info.Form_Info2()) { thisForm.ShowDialog(); } } else { //get list of selected filter elements so they can be deleted List <ParameterFilterElement> AllUnusedFilters = DeleteUnusedFilters.Helpers.GetUnusedFilterElem(m_doc); List <ParameterFilterElement> SelectedFilters = new List <ParameterFilterElement>(); foreach (int index in checkedIndices) { SelectedFilters.Add(AllUnusedFilters[index]); } //deletes selected filters using (Transaction t = new Transaction(m_doc, "Delete filters")) { t.Start(); foreach (ParameterFilterElement pfe in SelectedFilters) { listInfo.Add(pfe.Name); info += pfe.Name + "\n"; nOfFilters += 1; m_doc.Delete(pfe.Id); } t.Commit(); } // show Results Form using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); } //try //{ // Utilities.GetAnalyticsCSV(m_doc, m_app); //} //catch (Exception) //{ //} DialogResult = DialogResult.OK; Close(); } }
private void btnOK_Click(object sender, EventArgs e) { // get list of checked indices List <int> checkedIndices = new List <int>(); foreach (int index in clbUnused.CheckedIndices) { checkedIndices.Add(index); } // check if there are any boxes checked if (!checkedIndices.Any()) { using (UI.Info.Form_Info2 thisForm = new UI.Info.Form_Info2()) { thisForm.ShowDialog(); } } else { List <ElementId> unusedItems = Helpers.GetUnusedTextNoteTypes(m_doc).ToList(); List <ElementId> selectedItems = new List <ElementId>(); foreach (int index in checkedIndices) { selectedItems.Add(unusedItems[index]); } // delete selected filters using (Transaction t = new Transaction(m_doc, "Purge Text Note Types")) { t.Start(); foreach (ElementId eId in selectedItems) { try { infoList.Add(m_doc.GetElement(eId).Name); nOfItems += 1; m_doc.Delete(eId); } catch (Exception) { itemExceptList.Add(m_doc.GetElement(eId).Name); infoList.Remove(m_doc.GetElement(eId).Name); nOfItems -= 1; continue; } } t.Commit(); } // show Results Form using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); } //try //{ // Utilities.GetAnalyticsCSV(m_doc, m_app); // //GetAnalyticsCSV(m_doc, m_app); //} //catch (Exception) //{ //} this.DialogResult = DialogResult.OK; Close(); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; Application app = uiapp.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = commandData.Application.ActiveUIDocument.Document; // add event handler for when the app does not find the ArpUtilies.dll assembly //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); #region is family document? if (doc.IsFamilyDocument) { UI.Info.Form_Info1.infoMsgMain = "Wrong document"; UI.Info.Form_Info1.infoMsgBody = "This is a family document.\nRun this tool in a project document."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); return(Result.Cancelled); } } #endregion #region verify active view is sheet View activeView = doc.ActiveView; if (!(activeView is Autodesk.Revit.DB.ViewSheet)) { UI.Info.Form_Info1.infoMsgMain = "Wrong Active View"; UI.Info.Form_Info1.infoMsgBody = "Please, open a Sheet to run this tool."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); return(Result.Cancelled); } } #endregion #region sheet has viewports? List <Element> viewportList = GetAllViewport(doc, activeView as ViewSheet); if (!viewportList.Any()) { UI.Info.Form_Info1.infoMsgMain = "Viewports?"; UI.Info.Form_Info1.infoMsgBody = "This sheet does not contain any Viewport to renumber."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); return(Result.Cancelled); } } #endregion // get maximum value of detail number parameter int maxNum = MaxDetailNumber(viewportList); // renumber viewports using (Transaction t = new Transaction(doc, "Reassign Detail Number")) { t.Start(); // allows selection of as many viewports as there are in the sheet List <Element> selection = new List <Element>(); while (selection.Count() < viewportList.Count()) { try { Element e = doc.GetElement(uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new ViewportSelectionFilter(), "Select Viewports sequentially to re-number.")); selection.Add(doc.GetElement(e.Id)); } catch (Exception) { if (selection.Count != 0) { UI.Info.Form_Info1.infoMsgMain = "Incomplete Selection"; UI.Info.Form_Info1.infoMsgBody = "You have not selected all the viewports in this sheet.\n" + "Only selected ones will be renumbered sequentially.\n" + "Please, review the other detail numbers because they might have changed."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } else // cancel command if no views selected { return(Result.Cancelled); } break; } } // detect viewports with det num value equals to one of the tarjet values // and set it to a higher number so they donĀ“t get duplicated for (int i = 1; i < selection.Count() + 1; i++) { try { GetAllViewports_DICT(viewportList)[i.ToString()]. // get element with key value = i get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER). // get Detail Number parameter Set((maxNum + i).ToString()); // set parameter to greater value than the maximum of values } catch (Exception) { continue; } } // set new value for each item selected int newDetNumber = 0; infoResult.Clear(); // clear the results list for when the app is run multiple times foreach (Element e in selection) { newDetNumber += 1; e.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(newDetNumber.ToString()); Viewport vp = e as Viewport; infoResult.Add(newDetNumber + " -> " + doc.GetElement(vp.ViewId).Name); } t.Commit(); // show Results Form resultMsgMain = "The following viewports have been renumbered:"; using (UI.Info.Form_Results thisForm = new UI.Info.Form_Results()) { thisForm.ShowDialog(); } } //try //{ // Utilities.GetAnalyticsCSV(doc, app); //} //catch (Exception) //{ //} return(Result.Succeeded); }