private void BtnCreate_Click(object sender, EventArgs e) { // check if at least one item is selected if (LsvWorksets.CheckedItems.Count == 0) { UI.Info.Form_Info1.infoMsgMain = "Selection"; UI.Info.Form_Info1.infoMsgBody = "Select one or more worksets from the list."; using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1()) { thisForm.ShowDialog(); } } else { // collect selected worksets List <string> selectedWorksets = new List <string>(); foreach (ListViewItem item in LsvWorksets.CheckedItems) { selectedWorksets.Add(item.Text); } // check if workset name is in use usedNames = GetUsedNames(m_doc, selectedWorksets); if (usedNames.Any()) { using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } } // proceed if workset names are unique else { using (TransactionGroup tg = new TransactionGroup(m_doc, "Transfer Worksets")) { tg.Start(); createdWorksets.Clear(); // clear results list for when running the command more than once. foreach (string WorksetName in selectedWorksets) { using (Transaction t = new Transaction(m_doc, "Single Transaction")) { t.Start(); Workset newWorkset = null; newWorkset = Workset.Create(m_doc, WorksetName); createdWorksets.Add(WorksetName); t.Commit(); } } tg.Assimilate(); } // show Results Form using (UI.Info.Form_Results thisForm = new Info.Form_Results()) { thisForm.ShowDialog(); } DialogResult = DialogResult.OK; } } }
public static SortedDictionary <string, List <Definition> > GetParameterByType(Application app) { SortedDictionary <string, List <Definition> > DefinitionsByType = new SortedDictionary <string, List <Definition> >(); DefinitionFile definitionFile = null; // definition file exists? try { definitionFile = app.OpenSharedParameterFile(); } catch (Exception) { } if (definitionFile is null) { exceptionMessage = "DefinitionFile of Shared Parameters File does not exist." + " Something went wrong when trying to open the Shared Parameter File."; using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } } try { // iterate all groups foreach (DefinitionGroup gr in definitionFile.Groups) { // create sorted list of Definitions List <Definition> defList = new List <Definition>(); foreach (Definition def in gr.Definitions) { defList.Add(def); } List <Definition> sortedList = defList.OrderBy(x => x.Name).ToList(); // itereate sorted list and populate dictionary foreach (Definition def in sortedList) { // By Type if (!DefinitionsByType.ContainsKey(def.ParameterType.ToString())) { DefinitionsByType.Add(def.ParameterType.ToString(), sortedList); } } } } catch (Exception ex) { exceptionMessage = "Parameters could not be loaded: " + ex.Message; using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } } return(DefinitionsByType); }
public void InplaceReplacement(object sender, Autodesk.Revit.UI.Events.BeforeExecutedEventArgs arg) { UI.Info.Form_Warning.warningMsgHead = "Stop!"; UI.Info.Form_Warning.warningMsgMain = "Are you trying to create an In-Place Component?"; UI.Info.Form_Warning.warningMsgBody = "That is not usually the best practice.\n" + "I´m sure you that can use a loadable family instead!\n" + "Please reconsider your actions..."; using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } }
public void ImportReplacement(object sender, Autodesk.Revit.UI.Events.BeforeExecutedEventArgs arg) { UI.Info.Form_Warning.warningMsgHead = "Stop!"; UI.Info.Form_Warning.warningMsgMain = "Are you trying to import a CAD?"; UI.Info.Form_Warning.warningMsgBody = "That is not the best practice.\n" + "You should use 'Link CAD' instead!\n" + "Please reconsider your actions..."; using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } }
public static void MoveRoomToCentroid(Document doc, List <Room> modelRooms) { SpatialElementGeometryCalculator geomCalculator = new SpatialElementGeometryCalculator(doc); bool NotEnclosedRooms = false; //declare variable to detect Not Enclosed rooms foreach (Room r in modelRooms) { if (r.Area == 0) //are there not enclosed rooms? { NotEnclosedRooms = true; continue; } if (r.Area > 0) //hadle exception for Not Enclosed rooms when trying to calculate SpatialElementGeometry { Location rLoc = r.Location; LocationPoint currentLoc = (LocationPoint)r.Location; XYZ currentLocPoint = currentLoc.Point; SpatialElementGeometryResults geomResults = geomCalculator.CalculateSpatialElementGeometry(r); Solid roomSolid = geomResults.GetGeometry(); XYZ roomCentroid = roomSolid.ComputeCentroid(); XYZ moveVector = new XYZ(roomCentroid.X - currentLocPoint.X, roomCentroid.Y - currentLocPoint.Y, roomCentroid.Z - currentLocPoint.Z); // don´t move if centroid is outside of a room if (r.IsPointInRoom(roomCentroid)) { rLoc.Move(moveVector); } } } if (NotEnclosedRooms == true) //warn the user about not enclosed rooms { Form.Form_Main.warningMsgMain = "Warning"; Form.Form_Main.warningMsgBody = string.Format("There are 'Not Enclosed' rooms in this project.{0}{0}" + " This application have ignored them," + " but I strongly recommend you to revise them and amend as appropriate." , Environment.NewLine); using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } } }
public static void MoveModelTags(Document doc, List <RoomTag> rTagList) { bool NotEnclosedRooms = false; //declare variable to detect Not Enclosed rooms foreach (RoomTag rt in rTagList) { if (rt.Room.Area == 0) //are there not enclosed rooms? { NotEnclosedRooms = true; continue; } if (rt.Room.Area > 0) //proceed only with enclosed rooms { Location tLoc = rt.Location; // get room location LocationPoint rLoc = rt.Room.Location as LocationPoint; XYZ rPoint = rLoc.Point; // get tag location LocationPoint tagLoc = (LocationPoint)rt.Location; XYZ tagPoint = tagLoc.Point; XYZ moveVector = new XYZ(rPoint.X - tagPoint.X, rPoint.Y - tagPoint.Y, rPoint.Z - tagPoint.Z); tLoc.Move(moveVector); } } if (NotEnclosedRooms == true) //warn the user about not enclosed rooms { Form.Form_Main.warningMsgMain = "Warning"; Form.Form_Main.warningMsgBody = string.Format("There are 'Not Enclosed' rooms in this project.{0}{0}" + " This application have ignored them," + " but I strongly recommend you to revise them and amend as appropriate." , Environment.NewLine); using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } } }
} = 0; // number of schedules exported #endregion public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // add event handler for when the app does not find the ArpUtilies.dll assembly //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); #region variables UIApplication uiapp = commandData.Application; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; // element selection ICollection <ElementId> selIds = uidoc.Selection.GetElementIds(); // excel export settings ViewScheduleExportOptions export_options = new ViewScheduleExportOptions(); // paths to check Excel install string excelPaths_FileName = "OpenInExcel_UserPaths.txt"; string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string excelPaths_FilePath = Path.Combine(assemblyPath, excelPaths_FileName); // paths to export schedule string temp_folder = Path.GetTempPath(); #endregion // check if file exists if (!Data.Helpers.CheckFileExists(excelPaths_FilePath)) { warningMsgMain = "File missing"; warningMsgBody = string.Format("Could not find the File: {0}{0}{1} in {2}{0}{0}Contact [email protected] for help.", Environment.NewLine, excelPaths_FileName, assemblyPath); using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } return(Result.Cancelled); } // check if excel is installed in usual paths if (!Data.Helpers.CheckExcelInstall(excelPaths_FilePath)) { warningMsgMain = "Excel not found"; warningMsgBody = string.Format("Could not find Excel installed in the usual paths.{0}{0}" + "Please install Excel or add your Excel path to the OpenInExcel_UserPaths.txt " + "(located in {1}) and try again.{0}{0}" + "Contact [email protected] for help.", Environment.NewLine, assemblyPath); using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } return(Result.Cancelled); } // if there are not schedules selected or open throw a message if (!Data.Helpers.GetSelectedSchedules(doc, selIds).Any()) { using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } return(Result.Cancelled); } // go ahead and export the selected schedules if (Data.Helpers.GetSelectedSchedules(doc, selIds).Any()) { // start counters. For this application Use Time and Execution time will be the same. useTime.Start(); Random randomNumber = new Random(); // create excel name with schedule name + random number foreach (View v in Data.Helpers.GetSelectedSchedules(doc, selIds)) { Ana_NoOfExports += 1; // count number of schedules exported string scheduleName = Data.Helpers.ReplaceIllegalCharaters(v.Name); string txtFileName = scheduleName + "_" + randomNumber.Next(1000) + ".txt"; string scheduleExportPath = Path.Combine(temp_folder, txtFileName); // export schedule to .txt ViewSchedule viewSchedule = v as ViewSchedule; viewSchedule.Export(temp_folder, txtFileName, export_options); // open .txt schedule with excel Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application(); excelApp.Visible = true; // make the running excel instance visible Workbook wb = excelApp.Workbooks.Open(scheduleExportPath); } useTime.Stop(); UseTimeElapseS = useTime.Elapsed.Seconds.ToString(); ExecTimeElapseS = UseTimeElapseS; } //try //{ // Utilities.GetAnalyticsCSV(doc, app); // Data.Helpers.ScheduleToExcelAnalytics(doc, app, UseTimeElapseS, ExecTimeElapseS, Ana_NoOfExports); //} //catch (Exception) //{ //} return(Result.Succeeded); }
private void BtnOK_Click(object sender, EventArgs e) { // show message if both boxes are unchecked if (!CbxRoomCentroid.Checked && !CbxRoomTag.Checked) { infoMsgMain = "Hey!"; infoMsgBody = "Choose an action from the menu."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } // show message if there are neither tags not rooms if ((CbxRoomCentroid.Checked || CbxRoomTag.Checked) && !Data.Helpers.GetModelRooms(m_doc).Any() && !Data.Helpers.GetModelRoomTags(m_doc).Any() && !Data.Helpers.GetLinkRoomTags(m_doc).Any()) { // show dialog infoMsgMain = "Missing elements"; infoMsgBody = "There are not placed rooms or room tags in this project."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } Close(); } else // if there are tags or rooms { if (CbxRoomCentroid.Checked) { if (RbtProject.Checked) // if "Entire Project" is checked { if (!Data.Helpers.GetModelRooms(m_doc).Any()) // show message if there are no rooms { // show dialog infoMsgMain = "Missing elements"; infoMsgBody = "There are not placed rooms in this project."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } Close(); } else // move room insertion point to centroid { using (Transaction t = new Transaction(m_doc, "Room Insertion Point to Centroid")) { t.Start(); Data.Helpers.MoveRoomToCentroid(m_doc, Data.Helpers.GetModelRooms(m_doc)); t.Commit(); } // show dialog infoMsgMain = "Result"; infoMsgBody = "Room location points have been moved to centroid."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } DialogResult = DialogResult.OK; } } if (RbtActiveView.Checked) // if "Active View" is checked { if (!Data.Helpers.GetModelRoomsActView(m_doc).Any()) // show message if there are no rooms in active view { // show dialog infoMsgMain = "Missing elements"; infoMsgBody = "There are not placed rooms in this view."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } Close(); } else // move room insertion point to centroid { using (Transaction t = new Transaction(m_doc, "Room Insertion Point to Centroid")) { t.Start(); Data.Helpers.MoveRoomToCentroid(m_doc, Data.Helpers.GetModelRoomsActView(m_doc)); t.Commit(); } // show dialog infoMsgMain = "Result"; infoMsgBody = "Room location points have been moved to centroid."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } DialogResult = DialogResult.OK; } } } if (CbxRoomTag.Checked) { if (RbtActiveView.Checked) // if "Active View" is checked { if (!Data.Helpers.GetModelRoomTagsActView(m_doc).Any()) // show message if there are no tags { // show dialog infoMsgMain = "Missing elements"; infoMsgBody = "There are not room tags in this active view, or they are tagging rooms from a linked model."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } Close(); } else // move tag to room insertion point { using (Transaction t = new Transaction(m_doc, "Tags to Room Insertion Point")) { t.Start(); Data.Helpers.MoveModelTags(m_doc, Data.Helpers.GetModelRoomTagsActView(m_doc)); t.Commit(); } // show dialog infoMsgMain = "Result"; infoMsgBody = "Room tags have been moved to room location point."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } DialogResult = DialogResult.OK; } } if (RbtProject.Checked) // if "Entire Project" is checked { if (CbxLinkedRoomTag.Checked && CbxRoomTag.Checked) // if "Include tags of linked rooms" is checked { if (!Data.Helpers.GetLinkRoomTags(m_doc).Any()) { // show dialog infoMsgMain = "Missing elements"; infoMsgBody = "There are not room tags tagging linked rooms in the model."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } else // move all tags { using (Transaction t = new Transaction(m_doc, "Tags to Room Insertion Point")) { t.Start(); Data.Helpers.MoveModelTags(m_doc, Data.Helpers.GetModelRoomTags(m_doc)); // move model tags // show dialog infoMsgMain = "Result"; infoMsgBody = "Room tags have been moved to room location point."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } try { foreach (RoomTag rt in Data.Helpers.GetLinkRoomTags(m_doc)) // move linked tags { Data.Helpers.MoveLinkTags(m_doc, rt); } // show dialog infoMsgMain = "Result"; infoMsgBody = "Tags of linked rooms have been moved to room insertion point."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } } catch (Exception) { // show dialog warningMsgMain = "For your information"; warningMsgBody = string.Format("Some tags of linked rooms were not moved " + "because one or more links containing tagged rooms are unloaded.{0}{0}" + "Please, reload links and try again.", Environment.NewLine); using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning()) { thisForm.ShowDialog(); } DialogResult = DialogResult.Cancel; } t.Commit(); } DialogResult = DialogResult.OK; } } if (!CbxLinkedRoomTag.Checked) // if "Include tags of linked rooms" is unchecked { if (!Data.Helpers.GetModelRoomTags(m_doc).Any()) { // show dialog infoMsgMain = "Missing elements"; infoMsgBody = "There are not room tags in the model, or they are tagging rooms from a linked model."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } Close(); } else // move model tags { using (Transaction t = new Transaction(m_doc, "Tags to Room Insertion Point")) { t.Start(); Data.Helpers.MoveModelTags(m_doc, Data.Helpers.GetModelRoomTags(m_doc)); t.Commit(); } // show dialog infoMsgMain = "ResultAA"; infoMsgBody = "Room tags have been moved to room insertion point."; using (UI.Info.Form_Info1 thisForm = new UI.Info.Form_Info1()) { thisForm.ShowDialog(); } DialogResult = DialogResult.OK; } } } } } }