/// <summary> /// This method creates and shows a modeless dialog, unless it already exists. /// </summary> /// <remarks> /// The external command invokes this on the end-user's request /// </remarks> /// public void ShowForm_SymbolSelection(UIApplication uiapp) { // If we don't have dialog yet, create and show it if (m_SymbolSelection == null || m_SymbolSelection.IsDisposed) { // A new handler handle request posting by the dialog CreateBeamExternalEventHandler handler = new CreateBeamExternalEventHandler(); // External event for the dialog to use (to post request) ExternalEvent exEvent = ExternalEvent.Create(handler); // We give the objects to the new dialog; // The dialog becomes the owner responsible fore disposing them, eventually. m_SymbolSelection = new SymbolSelectionForm(exEvent, handler, uiapp.ActiveUIDocument.Document); m_SymbolSelection.Show(); } }
/// <summary> /// The top method of the event handler. /// </summary> /// <remarks> /// This is called by Revit after the corresponding /// external event was raised (by the modeless form) /// and Revit reached the time at which it could call /// the event's handler (i.e. this object) /// </remarks> /// <param name="app">Revit User Interface Application</param> public void Execute(UIApplication app) { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; View view = doc.ActiveView; // External Event Handler Instance CreateBeamExternalEventHandler createBeamExternalEventHandler = new CreateBeamExternalEventHandler(); // Create a external event inherited from handler. ExternalEvent externalEvent = ExternalEvent.Create(createBeamExternalEventHandler); // Modeless Form Instance SymbolSelectionForm symbolSelectionForm = new SymbolSelectionForm(externalEvent, createBeamExternalEventHandler, doc); try { using (Transaction t = new Transaction(doc)) { //Provide access to make change in document t.Start("Create Beam W Columns"); // Collect selected objects element id ICollection <ElementId> selElements = uidoc.Selection.GetElementIds(); ICollection <ElementId> structuralColumns = new FilteredElementCollector(uidoc.Document, selElements).OfCategory(BuiltInCategory.OST_StructuralColumns).ToElementIds(); CreateBeamMethod(doc, view, structuralColumns, symbolSelectionForm); t.Commit(); App.thisApp.WakeFormUp_SymbolSelectionForm(); } } catch (Exception e) { TaskDialog.Show("INFO", e.Message); } finally { App.thisApp.WakeFormUp_SymbolSelectionForm(); } return; }
/// <summary> /// Create Beam(s) Between The Selected Structural Columns /// </summary> /// <param name="doc">Active Revit Document</param> /// <param name="refList">Selected Elements Id list</param> /// <param name="symbolSelectionForm">Symbol Selection Form</param> /// <param name="view">Active Revit View</param> private void CreateBeamMethod(Document doc, View view, ICollection <ElementId> refList, SymbolSelectionForm symbolSelectionForm) { // Collect column location point with offset as point list List <XYZ> points = new List <XYZ>(); // Need at least two columns if (refList.Count < 2) { TaskDialog.Show("ERROR", "Please select at least two columns"); } // Iterate through the list foreach (ElementId r in refList) { Element column = doc.GetElement(r); // Get element as family instance FamilyInstance familyInstance = column as FamilyInstance; FamilySymbol columnSymbol = familyInstance.Symbol; // If selected elements aren't structural column cancel the operation if (familyInstance.StructuralType == StructuralType.Column) { // Get the bounding box of element BoundingBoxXYZ boxXYZ = familyInstance.get_BoundingBox(view); // Column bounding box reference height double column_height = boxXYZ.Max.Z - boxXYZ.Min.Z; // Offset point XYZ offset = new XYZ(0, 0, column_height); //// Get the column location point Location loc = familyInstance.Location; LocationPoint locationPoint = loc as LocationPoint; // Add offset to the column location point to get the height of column points.Add(locationPoint.Point.Add(offset)); } else { TaskDialog.Show("ERROR", "Please select at least two columns"); } } // Create beam location line from column location points List <Line> lines = CreateLine(refList.Count, points); // get the active level from document Level level = doc.GetElement(doc.ActiveView.LevelId) as Level; if (App.beamTypeSelection != null) { FamilySymbol beamSymbol = App.beamTypeSelection as FamilySymbol; // For using in the document, symbol has to be activate. if (!beamSymbol.IsActive) { beamSymbol.Activate(); } if (lines != null) { foreach (Line line in lines) { FamilyInstance beam = doc.Create.NewFamilyInstance(line, beamSymbol, level, StructuralType.Beam); } } } else { TaskDialog.Show("INFO", "Combo box selection is null"); } }
/// <summary> /// Execute the command when REVIT starts /// </summary> /// <param name="a">Access the control of user interface application</param> /// <returns></returns> public Result OnStartup(UIControlledApplication a) { m_DoorControlForm = null; // no dialog needed yet; the command will bring it m_rotatingForm = null; m_SymbolSelection = null; m_structuralConnectionSelector = null; thisApp = this; // static access to this application instance #region Revit ribbon and tab creation // An instance of push button data model class PushButtonDataModel p = new PushButtonDataModel(); // Get executing assembly for creating button data PushButtonDataModel.GetAssemblyLocation = Assembly.GetExecutingAssembly().Location; // Create Ribbon Tab string tabName = "Selectra Main"; a.CreateRibbonTab(tabName); // Create the ribbon panels RibbonPanel arhcitecturalCommandsPanel = a.CreateRibbonPanel(tabName, "Architectural Commands"); RibbonPanel structuralCommandsPanel = a.CreateRibbonPanel(tabName, "Structural Commads"); TextBoxData textBoxData = new TextBoxData("Cope Distance"); TextBox copeDistanceTextBox = structuralCommandsPanel.AddItem(textBoxData) as TextBox; copeDistanceTextBox.Width /= 3; copeDistanceTextBox.PromptText = "Cope Distance"; copeDistanceTextBox.Value = "0.0"; copeDistanceTextBox.ToolTip = "Sets the cope distance of cutted framing elements"; SplitButtonData splitButtonData = new SplitButtonData("Multi Cope Split", "Multi Cope"); SplitButton splitMultiCope = structuralCommandsPanel.AddItem(splitButtonData) as SplitButton; splitMultiCope.ItemText = "Multiple Cope Options"; SplitButtonData splitDatumButtonData = new SplitButtonData("Datum Util Split", "Datum Utils"); SplitButton splitButtonDatum = arhcitecturalCommandsPanel.AddItem(splitDatumButtonData) as SplitButton; splitButtonDatum.ItemText = "Datum Utils"; #region Create Beam between Columns Button // Populate button data model PushButtonDataModel BeamBtwColButtonData = new PushButtonDataModel() { Label = "CreateBeam\nBetweenColumn", Panel = structuralCommandsPanel, CommandNamespacePath = CreateBeamCommand.GetPath(), Tooltip = "Create Beam between columns from selected beam symbol", IconImageName = p.Icon_Beam, TooltipImageName = p.tooltip_Beam }; // Create Button from provided data PushButton beamButton = Button.Create(BeamBtwColButtonData); #endregion #region Create Structural Connection Button // Populate push button data model PushButtonDataModel createStructuralConnectionData = new PushButtonDataModel() { Label = "Create Structural\nConnection", Panel = structuralCommandsPanel, CommandNamespacePath = CreateStructuralConnectionCommand.GetPath(), Tooltip = "Create Multiple Structural Connection between selected elements", IconImageName = p.Icon_PlateConnection, TooltipImageName = p.tooltip_PlateConnection }; // Create push button from populated button data PushButton createStructuralConnectionButton = Button.Create(createStructuralConnectionData); #endregion #region Rotate Multiple Elements Button // Populate button data model PushButtonDataModel rotateButtonData = new PushButtonDataModel() { Label = "Rotate Multiple\nElements", Panel = arhcitecturalCommandsPanel, CommandNamespacePath = RotateMultiCommand.GetPath(), Tooltip = "Create Beam between columns from selected beam symbol", IconImageName = p.Icon_Rotate, TooltipImageName = p.tooltip_3DRotate }; // Create Button from provided data PushButton rotateButton = Button.Create(rotateButtonData); #endregion #region Door Control Button // Populate button data model PushButtonDataModel doorControlData = new PushButtonDataModel() { Label = "Door Control", Panel = arhcitecturalCommandsPanel, CommandNamespacePath = DoorControlCommand.GetPath(), Tooltip = "Control the door behaviour due to user input", IconImageName = p.Icon_DoorOpening, TooltipImageName = p.tooltip_DoorOpening }; // Create button from provided data PushButton doorControlButton = Button.Create(doorControlData); #endregion #region Multiple Coping Button Data // Populate button data model PushButtonDataModel multiCopeData = new PushButtonDataModel() { Label = "Multiple\nCope", Panel = structuralCommandsPanel, CommandNamespacePath = CopeIntersected.GetPath(), Tooltip = "Cope multiple beams and columns", IconImageName = p.Icon_B, TooltipImageName = p.tooltip_Beam, }; #endregion #region Cope Intersected Beams Button Data // Populate button data model PushButtonDataModel copeIntersectsData = new PushButtonDataModel() { Label = "Cope Intersected Beams", Panel = structuralCommandsPanel, CommandNamespacePath = CopeIntersectedBeams.GetPath(), Tooltip = "Cope the beams that intersects with selected beam", IconImageName = p.Icon_Beam, TooltipImageName = p.tooltip_Beam }; #endregion #region Cope Beam With Intersects Button Data PushButtonDataModel copeSelectedData = new PushButtonDataModel() { Label = "Cope Selected Beam\n with Intersects", Panel = structuralCommandsPanel, CommandNamespacePath = CopeSelectedWIntersects.GetPath(), Tooltip = "Cope selected beam through intersects", IconImageName = p.Icon_B, TooltipImageName = p.tooltip_Beam }; #endregion #region Cope Connected Beams // Populate button data model PushButtonDataModel copeConnectedsData = new PushButtonDataModel() { Label = "Cope connected beams", Panel = structuralCommandsPanel, CommandNamespacePath = CopeConnectedBeams.GetPath(), Tooltip = "Cope the beams that connected to selected element", IconImageName = p.Icon_Beam, TooltipImageName = p.tooltip_Beam, }; #endregion #region Cope Beams Connected To Structural Column Button Data PushButtonDataModel copeConnectedToColumnData = new PushButtonDataModel() { Label = "Cope Beams Connected To Structural Column", Panel = structuralCommandsPanel, CommandNamespacePath = CopeBeamConnectedToStrColumn.GetPath(), Tooltip = "Cope beams connected to structural column", IconImageName = p.Icon_Beam, TooltipImageName = p.tooltip_Beam }; #endregion #region Remove copings Button Data // Populate button data model PushButtonDataModel removeCopeButtonData = new PushButtonDataModel() { Label = "Remove Copings", Panel = structuralCommandsPanel, CommandNamespacePath = RemoveAllCopings.GetPath(), Tooltip = "Remove all copings from selected elements", IconImageName = p.Icon_Beam, TooltipImageName = p.tooltip_DoorOpening }; #endregion #region Override Graphic Settings Button // Populate button data model PushButtonDataModel overrideButtonData = new PushButtonDataModel() { Label = "Override\nGraphics", Panel = arhcitecturalCommandsPanel, CommandNamespacePath = OverrideCommand.GetPath(), Tooltip = "Override graphic settings of selected element", IconImageName = p.Icon_Override, TooltipImageName = p.tooltip_Override }; // Create push button from provided data PushButton overrideButton = Button.Create(overrideButtonData); #endregion #region Create Wall Grid Button Data // Populate the button data model PushButtonDataModel createGridButtonData = new PushButtonDataModel() { Label = "Create Wall\nGrid", Panel = arhcitecturalCommandsPanel, CommandNamespacePath = CreateWallGrid.GetPath(), Tooltip = "Create Grid from wall center line", IconImageName = p.Icon_Grid, TooltipImageName = p.tooltip_Grid }; #endregion #region Plate Param Changer Button // Populate button data mode PushButtonDataModel plateParamData = new PushButtonDataModel() { Label = "Plate Parametre\nController", Panel = structuralCommandsPanel, CommandNamespacePath = SteelElementProperty.GetPath(), Tooltip = "Set the parameter of plates (Volume and Mass)", IconImageName = p.Icon_PlateConnection, TooltipImageName = p.tooltip_PlateConnection }; PushButton plateParamButton = Button.Create(plateParamData); #endregion #region Schema Build Button // Populate button data model PushButtonDataModel schemaBuildButtonData = new PushButtonDataModel() { Label = "Add Data", Panel = structuralCommandsPanel, CommandNamespacePath = AddField.GetPath(), Tooltip = "Add Data to extensible storage", IconImageName = p.Icon_B, TooltipImageName = p.Icon_DoorOpening }; PushButton schemaBuildButton = Button.Create(schemaBuildButtonData); #endregion #region Tag Wall Layers Button PushButtonDataModel tagWallLayerData = new PushButtonDataModel() { Label = "Tag Wall\nLayers", Panel = arhcitecturalCommandsPanel, CommandNamespacePath = TagWallLayers.GetPath(), Tooltip = "Create a textnote element at given point that includes the wall layers information", IconImageName = p.Icon_B, TooltipImageName = p.tooltip_DoorOpening }; PushButton tagWallButton = Button.Create(tagWallLayerData); #endregion #region Create Level Button Data // Populate button data model with given input PushButtonDataModel createLevelData = new PushButtonDataModel() { Label = "Create Multiple\nLevel", Panel = arhcitecturalCommandsPanel, CommandNamespacePath = CreateLevel.GetPath(), Tooltip = "Create Multiple Level with given user input", IconImageName = p.Icon_B, TooltipImageName = p.tooltip_Grid }; #endregion #region Set Elevation Button Data // Populate Button Data model PushButtonDataModel setElevationData = new PushButtonDataModel() { Label = "Set Elevation", Panel = arhcitecturalCommandsPanel, CommandNamespacePath = SetELevation.GetPath(), Tooltip = "Set elevation of level(s) with given input", IconImageName = p.Icon_S, TooltipImageName = p.Icon_S }; #endregion #region Sample Button // Populate button data model PushButtonDataModel sampleData = new PushButtonDataModel() { Label = "SAMPLE", Panel = arhcitecturalCommandsPanel, CommandNamespacePath = Sample.GetPath(), Tooltip = "This is just a sample for test purpose, content change continiously", IconImageName = p.Icon_S, TooltipImageName = p.tooltip_Override }; // Create push button from provided data PushButton sampleButton = Button.Create(sampleData); #endregion // Add push button to multiple cope split button splitMultiCope.AddPushButton(Button.CreateButtonData(multiCopeData)); splitMultiCope.AddPushButton(Button.CreateButtonData(copeIntersectsData)); splitMultiCope.AddPushButton(Button.CreateButtonData(copeSelectedData)); splitMultiCope.AddPushButton(Button.CreateButtonData(copeConnectedToColumnData)); splitMultiCope.AddPushButton(Button.CreateButtonData(removeCopeButtonData)); splitMultiCope.AddPushButton(Button.CreateButtonData(copeConnectedsData)); // Add push button to datum utils split button splitButtonDatum.AddPushButton(Button.CreateButtonData(createLevelData)); splitButtonDatum.AddPushButton(Button.CreateButtonData(setElevationData)); splitButtonDatum.AddPushButton(Button.CreateButtonData(createGridButtonData)); #endregion return(Result.Succeeded); }