public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //call to the security check method to check for authentication security = SecurityLNT.Security_Check(); if (security == false) { return(Result.Succeeded); } UIDocument m_document = commandData.Application.ActiveUIDocument; IList <Reference> selectedObjects = m_document.Selection.PickObjects(ObjectType.Element, new SprinklerSelectionFilter(m_document.Document), "Select sprinklers to connect with pipe."); MessageBox.Show(selectedObjects.Count.ToString()); Reference pipeRefer = m_document.Selection.PickObject(ObjectType.Element, new PipeSelectionFilter(m_document.Document), "Select the pipe to which sprinklers are to be connected."); MessageBox.Show(m_document.Document.GetElement(pipeRefer).Id.ToString()); return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
//execute method for the IExternalCommand public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //call to the security check method to check for authentication security = SecurityLNT.Security_Check(); if (security == false) { return(Result.Succeeded); } //open the active document in revit m_document = commandData.Application.ActiveUIDocument; //call to method to get directory and file GetDirectoryAndFile(); //call method to make the file selection and get paths FIleSelection(); return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } throw new NotImplementedException(); }
//check security private bool CheckSecurity() { try { //call to the security check method to check for authentication bool security = SecurityLNT.Security_Check(); if (security == true) { return(true); } else { return(false); } } catch { return(false); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //call to the security check method to check for authentication security = SecurityLNT.Security_Check(); if (security == false) { return(Result.Succeeded); } //open the active document in revit m_document = commandData.Application.ActiveUIDocument; DialogResult dialogueResult = new DialogResult(); //create instance of the form using (UserChoice formInstance = new UserChoice()) { formInstance.GetData(RetrieveFamilies()); dialogueResult = formInstance.ShowDialog(); if (dialogueResult == DialogResult.OK || dialogueResult == DialogResult.Abort) { return(Result.Succeeded); } } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } throw new NotImplementedException(); }
//default execute method required by the IExternalCommand class public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //call to the security check method to check for authentication security = SecurityLNT.Security_Check(); if (security == false) { return(Result.Succeeded); } //get the application data Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; //read the config file SpecificationData configFileData = UtilityMethods.ReadConfig(); //check for discipline if (configFileData.discipline != "PHE") { TaskDialog.Show("Failed!", "Sorry! Plug-in Not intended for your discipline."); return(Result.Succeeded); } //exception handled if (configFileData.offset == -1.0) { MessageBox.Show("Configuration data not found!"); return(Result.Succeeded); } //get all data from the specification file specsData = UtilityMethods.GetAllSpecs(configFileData); //exception handled if (specsData == null) { MessageBox.Show("Specifications not found!"); return(Result.Succeeded); } //open the active document in revit m_document = commandData.Application.ActiveUIDocument; //get the selected element set eleSet = m_document.Selection.Elements; if (eleSet.IsEmpty) { MessageBox.Show("Please select pipes before executing the Add-in!"); return(Result.Succeeded); } //call to method to get the transform required Transform transform = UtilityMethods.GetInverseTransform(m_document.Document, commandData.Application.Application); if (transform == null) { MessageBox.Show("Sorry! Couldn't find a possible transform."); return(Result.Succeeded); } //get family name from config data FamilyName = configFileData.selectedFamily; //check if family exists family = UtilityMethods.FindElementByName(m_document.Document, typeof(Family), FamilyName) as Family; //if existing if (family == null) { MessageBox.Show("Please load the family into the project and re-run the Add-in."); return(Result.Succeeded); } //get the family symbol symbol = UtilityMethods.GetFamilySymbol(family); //exception handled if (family == null) { MessageBox.Show("No family symbol for the family you specified!"); return(Result.Succeeded); } //create a logical filter for all the structural elements LogicalOrFilter filter = UtilityMethods.GetStructuralFilter(); //if no filter is returned if (filter == null) { return(Result.Succeeded); } //get the structural elements from the documents List <Element> structuralElements = new List <Element>(); structuralElements = UtilityMethods.GetStructuralElements(app, filter); if (structuralElements == null) { MessageBox.Show("Sorry! No structural element found"); return(Result.Succeeded); } //list to store all the planar botom faces of the structural elements List <PlanarFace> pFace = new List <PlanarFace>(); //find and add bottom planar faces to the list foreach (Element e in structuralElements) { PlanarFace pf = UtilityMethods.GetBottomFace(e); if (pf != null) { pFace.Add(pf); } } //clear the structural elements list as it is no longer required structuralElements.Clear(); //control variable for removing unwanted elements from the planar faces list int flag = 0; //iterate through all the selected elements foreach (Element ele in eleSet) { //check whether the selected element is of type pipe if (ele is Pipe) { //get the location curve of the pipe pipeCurve = ((LocationCurve)ele.Location).Curve; //if the length of pipe curve obtained is zero skip that pipe if (pipeCurve.Length == 0) { FailedToPlace.Add(ele.Id); continue; } //remove unwanted planes from the list if (flag == 0) { //remove unwanted faces from the list (this works only once) pFace = UtilityMethods.GetPossiblePlanes(pFace, pipeCurve.get_EndPoint(0), transform); flag = -1; } //if no plane is found for intersect to work if (pFace.Count == 0) { MessageBox.Show("Sorry! No structural element found"); return(Result.Succeeded); } //from the specification file, get the spacing corresponding to the pipe diameter spacing = UtilityMethods.GetSpacing(ele, specsData); //check if the spacing returned is -1 if (spacing == -1) { FailedToPlace.Add(ele.Id); continue; } //get the points for placing the family instances points = UtilityMethods.GetPlacementPoints(spacing, pipeCurve, 1000 * configFileData.offset, 1000 * configFileData.minSpacing); //check if the points is null exception if (points == null) { FailedToPlace.Add(ele.Id); continue; } //get the pipe level pipeLevel = ele.Level; //iterate through all the points for placing the family instances foreach (XYZ point in points) { try { //create the instances at each points tempEle = m_document.Document.Create.NewFamilyInstance (point, symbol, ele, pipeLevel, StructuralType.NonStructural); createdElements.Add(tempEle.Id); } catch { FailedToPlace.Add(ele.Id); continue; } //find the rod length required rodLength = UtilityMethods.ReturnLeastZ_Value(m_document.Document, pFace, point, transform); if (rodLength == -1) { FailedToPlace.Add(ele.Id); createdElements.Remove(tempEle.Id); m_document.Document.Delete(tempEle.Id); continue; } //adjust the newly created element properties based on the rodlength, //orientation and dia of pipe if (!UtilityMethods.AdjustElement(m_document.Document, tempEle, point, (Pipe)ele, rodLength, pipeCurve)) { FailedToPlace.Add(ele.Id); createdElements.Remove(tempEle.Id); m_document.Document.Delete(tempEle.Id); continue; } } } } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } throw new NotImplementedException(); }
//default execute method required by the IExternalCommand class public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //call to the security check method to check for authentication security = SecurityLNT.Security_Check(); if (security == false) { return(Result.Succeeded); } //read the config file specificationData configFileData = UtilityMethods.ReadConfig(); //check for discipline if (configFileData.discipline != "FEMS") { TaskDialog.Show("Failed!", "Sorry! Plug-in Not intended for your discipline."); return(Result.Succeeded); } //exception handled if (configFileData.offset == -1.0) { MessageBox.Show("Configuration data not found!"); return(Result.Succeeded); } //get all data from specification file specList = UtilityMethods.GetFEMS_Specs(configFileData); //exception handled if (specList == null) { MessageBox.Show("Specifications not found!"); return(Result.Succeeded); } //open the active document in revit m_document = commandData.Application.ActiveUIDocument; //get the selected element set eleSet = m_document.Selection.Elements; if (eleSet.IsEmpty) { MessageBox.Show("Please select pipes before executing the Add-in!"); return(Result.Succeeded); } //get family name from config data FamilyName = configFileData.selectedFamily; //check if family exists family = UtilityMethods.FindElementByName(m_document.Document, typeof(Family), FamilyName) as Family; //if existing if (family == null) { MessageBox.Show("Please load the family into the project and re-run the Add-in."); return(Result.Succeeded); } //get the 3D view to workon view3D = UtilityMethods.Get3D_View(m_document.Document); //exception handled if (view3D == null) { MessageBox.Show("No 3D view available!"); return(Result.Succeeded); } //set the 3D view sectionBox to false and copy its bounding box bounds = UtilityMethods.GetBounds(view3D); //exception handled if (bounds == null) { MessageBox.Show("Failed to generate bounding box!"); return(Result.Succeeded); } //get the family symbol symbol = UtilityMethods.GetFamilySymbol(family); //exception handled if (family == null) { MessageBox.Show("No family symbol for the family you specified!"); return(Result.Succeeded); } //iterate through all the selected elements foreach (Element ele in eleSet) { //check whether the selected element is of type pipe if (ele is Pipe) { //get the location curve of the pipe pipeCurve = ((LocationCurve)ele.Location).Curve; //if the length of pipe curve obtained is zero skip that pipe if (pipeCurve.Length == 0) { FailedToPlace.Add(ele.Id); continue; } //from the specification file, get the spacing corresponding to the pipe diameter spacing = UtilityMethods.GetSpacing(ele, specList); //check if the spacing returned is -1 if (spacing == -1) { FailedToPlace.Add(ele.Id); continue; } //get the points for placing the family instances points = UtilityMethods.GetPlacementPoints(spacing, pipeCurve, 1000 * configFileData.offset, 1000 * configFileData.minSpacing); //check if the points is null exception if (points == null) { FailedToPlace.Add(ele.Id); continue; } //get the pipe level pipeLevel = (Level)m_document.Document.GetElement(ele.LevelId); //iterate through all the points for placing the family instances foreach (XYZ point in points) { try { //create the instances at each points tempEle = m_document.Document.Create.NewFamilyInstance (point, symbol, ele, pipeLevel, StructuralType.NonStructural); createdElements.Add(tempEle.Id); } catch { FailedToPlace.Add(ele.Id); continue; } //find the rod length required by using the reference intersector class rodLength = UtilityMethods.ExtendRod(point, m_document.Document, view3D); if (rodLength == -1) { FailedToPlace.Add(ele.Id); createdElements.Remove(tempEle.Id); m_document.Document.Delete(tempEle.Id); continue; } //adjust the newly created element properties based on the rodlength, //orientation and dia of pipe if (!UtilityMethods.AdjustElement(m_document.Document, tempEle, point, (Pipe)ele, rodLength, pipeCurve)) { FailedToPlace.Add(ele.Id); createdElements.Remove(tempEle.Id); m_document.Document.Delete(tempEle.Id); continue; } } } } if (!UtilityMethods.SetBounds(bounds, view3D)) { MessageBox.Show("Sorry! Couldn't restore the sectionbox for the 3D view."); return(Result.Succeeded); } return(Result.Succeeded); } catch (Exception e) { UtilityMethods.SetBounds(bounds, view3D); message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } throw new NotImplementedException(); }
//execute method for the IExternalCommand public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //call to the security check method to check for authentication security = SecurityLNT.Security_Check(); if (security == false) { return(Result.Succeeded); } //open the active document in revit m_document = commandData.Application.ActiveUIDocument; bool loopContinue = false; do { choice = ChooseAndFindFamily(); if (choice) { linkedFiles.Clear(); GetDirectoryAndFile(); //create instance of the form using (OpenFiles formInstance = new OpenFiles()) { formInstance.ShowLinkedData(linkedFiles, linkDirectoryPath); DialogResult dialogueResult = formInstance.ShowDialog(); if (DialogResult.Cancel == dialogueResult) { loopContinue = false; } else if (DialogResult.Retry == dialogueResult) { loopContinue = true; } formInstance.Close(); } } else { loopContinue = false; } } while (loopContinue == true); return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } throw new NotImplementedException(); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //call to the security check method to check for authentication security = SecurityLNT.Security_Check(); if (security == false) { return(Result.Succeeded); } //the application and document has been initialised m_application = commandData.Application; m_document = m_application.ActiveUIDocument; //Revit task dialog to communicate information to user. TaskDialog mainDialog = new TaskDialog("Numbering Tool"); mainDialog.MainInstruction = "Numbering Tool"; mainDialog.MainContent = "Please choose from the following options:\n"; //Add commmandLink to task dialog mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Auto Numbering (Rectangular Builing) "); mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Manual Numbering (Curved/Irregular Building)"); //Buttons to be shown on main dialogue window. mainDialog.CommonButtons = TaskDialogCommonButtons.Close; mainDialog.DefaultButton = TaskDialogResult.Close; TaskDialogResult tResult = mainDialog.Show(); //conditions for options chosen by the user if (TaskDialogResult.CommandLink1 == tResult) { IList <Element> selectedElementTags = new List <Element>(); IList <Element> selectedElements = new List <Element>(); //element selection. all elements have to be picked and then press finish to continue with auto numbering. //show dialogue using (NumberAndAlignment numberAndAlignmentInstance = new NumberAndAlignment()) { bool loopControl = true; while (loopControl) { DialogResult dialogueResult = numberAndAlignmentInstance.ShowDialog(); if (DialogResult.OK == dialogueResult) { isNumber = numberAndAlignmentInstance.CheckStartNumber(); if (isNumber) { startNum = numberAndAlignmentInstance.ReturnStartNumber(); tolerance = 3.28f * numberAndAlignmentInstance.ReturnTolerance(); option = numberAndAlignmentInstance.ReturnNumberingChoice(); loopControl = false; } else { MessageBox.Show("Enter Integer for Start Number and Decimal for Tolerance."); } } else if (DialogResult.Abort == dialogueResult) { loopControl = false; } } if (startNum != -1 && option != -1) { loopControl = true; selectedElementTags.Clear(); while (loopControl) { ((ICollection <Element>)selectedElementTags).Clear(); try { selectedElementTags = m_document.Selection.PickElementsByRectangle(new TagSelectionFilter(m_document.Document), "Select Elements by a Selection Rectangle."); if (((ICollection <Element>)selectedElementTags).Count > 0) { loopControl = false; } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { loopControl = false; } } if (option == 1) { selectedElements.Clear(); foreach (Element ele in selectedElementTags) { selectedElements.Add(((IndependentTag)ele).GetTaggedLocalElement()); } selectedElementTags.Clear(); HorizontalLtoR(selectedElements); selectedElements.Clear(); } else if (option == 2) { selectedElements.Clear(); foreach (Element ele in selectedElementTags) { selectedElements.Add(((IndependentTag)ele).GetTaggedLocalElement()); } selectedElementTags.Clear(); VerticalTtoB(selectedElements); selectedElements.Clear(); } } } } else if (TaskDialogResult.CommandLink2 == tResult) { //show dialogue using (StartNumber startNumberInstance = new StartNumber()) { bool control = true; while (control) { DialogResult dialogueResult = startNumberInstance.ShowDialog(); if (DialogResult.OK == dialogueResult) { isNumber = startNumberInstance.CheckStartNumber(); if (isNumber) { startNum = startNumberInstance.ReturnStartNumber(); control = false; } else { MessageBox.Show("Please Enter a Number."); } } else if (DialogResult.Abort == dialogueResult) { control = false; } else if (DialogResult.Cancel == dialogueResult) { control = false; } } } if (startNum != -1) { //element selection. the element has to be picked in the order in which it has to be numbered. //once the selection is completed press ESC to end the selection Reference elementReference = null; bool continueLoop = true; while (continueLoop) { try { elementReference = m_document.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element , new TagSelectionFilter(m_document.Document), "Pick elements to change Mark in the required order. Press ESC to END Slections."); if (ChangeMarkValue.GetTaggedElement(m_document, elementReference, startNum)) { ; } else { return(Autodesk.Revit.UI.Result.Failed); } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { continueLoop = false; } startNum++; } } } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } throw new NotImplementedException(); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //call to the security check method to check for authentication security = SecurityLNT.Security_Check(); if (security == false) { return(Result.Succeeded); } //open the active document in revit m_document = commandData.Application.ActiveUIDocument; selectedObjects.Clear(); try { //pick the objects of type dimensions using the pick objects method selectedObjects = m_document.Selection.PickObjects(ObjectType.Element, new DimensionSelectionFilter(m_document.Document), "Select Elements by a Selection Rectangle."); } catch (Exception e) { //return succeed even if it fails to avoid the'user aborted operation' message if (e is OperationCanceledException) { return(Result.Succeeded); } } foreach (Reference refer in selectedObjects) { //convert the refernces picked into elements and type cast it to dimensions dim = (Dimension)m_document.Document.GetElement(refer); //if the dimensions are independent dimensions aadd the text to below property if (dim.NumberOfSegments == 0) { dim.Below = "(TYP)"; } else { //if dimensions are of continuous type add text to below property //of each segment by iterating through the blelow property foreach (DimensionSegment segment in dim.Segments) { segment.Below = "(TYP)"; } } } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } throw new NotImplementedException(); }