Exemplo n.º 1
0
        public static async void postConn(string url, TextBox txtbox)
        {
            using (var client = new HttpClient()) {
                try {
                    StringContent content = getPostPayload();

                    var responseTsk = await client.PostAsync(url, content);

                    var responseString = await responseTsk.Content.ReadAsStringAsync();

                    s = url + "\n" + responseString;
                    if (txtbox != null)
                    {
                        txtbox.ItemText = s;
                    }
                    else
                    {
                        Debug.WriteLine(s);
                    }
                }catch (Exception ex) {
                    Debug.WriteLine("ERROR ERROR ERROR ERROR ERROR ");
                    Debug.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Implement this method to implement the external application which should be called when
        /// Revit is about to exit, Any documents must have been closed before this method is called.
        /// </summary>
        /// <param name="application">An object that is passed to the external application
        /// which contains the controlled application.</param>
        /// <returns>Return the status of the external application.
        /// A result of Succeeded means that the external application successfully shutdown.
        /// Cancelled can be used to signify that the user cancelled the external operation at
        /// some point.
        /// If Failed is returned then the Revit user should be warned of the failure of the external
        /// application to shut down correctly.</returns>
        public Autodesk.Revit.UI.Result OnShutdown(UIControlledApplication application)
        {
            //remove events
            List <RibbonPanel> myPanels = application.GetRibbonPanels();

            Autodesk.Revit.UI.ComboBox comboboxLevel = (Autodesk.Revit.UI.ComboBox)(myPanels[0].GetItems()[2]);
            application.ControlledApplication.DocumentCreated -= new EventHandler <
                Autodesk.Revit.DB.Events.DocumentCreatedEventArgs>(DocumentCreated);
            Autodesk.Revit.UI.TextBox textBox = myPanels[0].GetItems()[5] as Autodesk.Revit.UI.TextBox;
            textBox.EnterPressed -= new EventHandler <
                Autodesk.Revit.UI.Events.TextBoxEnterPressedEventArgs>(SetTextBoxValue);

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemplo n.º 3
0
        // Both OnStartup and OnShutdown must be implemented as public method
        public Result OnStartup(UIControlledApplication application)
        {
            // Add a new ribbon panel
            RibbonPanel ribbonPanel = application.CreateRibbonPanel("JONES NICHOLSON");

            // Create a push button to trigger a command add it to the ribbon panel.
            // Adding lining to duct
            string         thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
            PushButtonData buttonData       = new PushButtonData("cmdAddLining",
                                                                 "ADD LINING", thisAssemblyPath, "JonesNicholson.AddLiningToDuct");

            PushButton  pushButton = ribbonPanel.AddItem(buttonData) as PushButton;
            TextBoxData itemData3  = new TextBoxData("itemName3");

            Autodesk.Revit.UI.TextBox item3 = ribbonPanel.AddItem(itemData3) as Autodesk.Revit.UI.TextBox;
            item3.Value   = "Option 3";
            item3.ToolTip = itemData3.Name; // Can be changed to a more descriptive text.

            // Optionally, other properties may be assigned to the button
            // a) tool-tip
            pushButton.ToolTip = "Will add lining to duct , keeping free area size intact";

            // b) large bitmap
            Uri         uriImage   = new Uri(@"C:\Users\Alext\OneDrive\Documents\Visual Studio 2013\Projects\Revit API\JonesNicholson\JonesNicholson\bin\Debug\39_globe_72x72.png");
            BitmapImage largeImage = new BitmapImage(uriImage);

            pushButton.LargeImage = largeImage;

            // Create a push button to trigger a command add it to the ribbon panel.
            // At this stage this button is for demonstration purposes , no functionality is implemented

            PushButtonData buttonDataTest = new PushButtonData("cmdRemoveLining",
                                                               "Remove LINING", thisAssemblyPath, "JonesNicholson.RemoveLiningToDuct");


            PushButton pushButtonTest = ribbonPanel.AddItem(buttonDataTest) as PushButton;

            // Optionally, other properties may be assigned to the button
            // a) tool-tip
            pushButton.ToolTip = "Will add lining to duct , keeping free area size intact";

            // b) large bitmap

            pushButtonTest.LargeImage = largeImage;

            return(Result.Succeeded);
        }
Exemplo n.º 4
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
                                                ref string message,
                                                ElementSet elements)
        {
            RibbonPanel myPanel = revit.Application.GetRibbonPanels()[0];
            //reset wall type
            RadioButtonGroup radioGroupTypeSelector =
                GetRibbonItemByName(myPanel, "WallTypeSelector") as RadioButtonGroup;

            if (null == radioGroupTypeSelector)
            {
                throw new InvalidCastException("Cannot get Wall Type selector!");
            }
            radioGroupTypeSelector.Current = radioGroupTypeSelector.GetItems()[0];

            //reset level
            Autodesk.Revit.UI.ComboBox comboboxLevel =
                GetRibbonItemByName(myPanel, "LevelsSelector") as Autodesk.Revit.UI.ComboBox;
            if (null == comboboxLevel)
            {
                throw new InvalidCastException("Cannot get Level selector!");
            }
            comboboxLevel.Current = comboboxLevel.GetItems()[0];

            //reset wall shape
            Autodesk.Revit.UI.ComboBox comboboxWallShape =
                GetRibbonItemByName(myPanel, "WallShapeComboBox") as Autodesk.Revit.UI.ComboBox;
            if (null == comboboxLevel)
            {
                throw new InvalidCastException("Cannot get wall shape combo box!");
            }
            comboboxWallShape.Current = comboboxWallShape.GetItems()[0];

            //get wall mark
            Autodesk.Revit.UI.TextBox textBox =
                GetRibbonItemByName(myPanel, "WallMark") as Autodesk.Revit.UI.TextBox;
            if (null == textBox)
            {
                throw new InvalidCastException("Cannot get Wall Mark TextBox!");
            }
            textBox.Value = "new wall";

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemplo n.º 5
0
        protected String GetNewWallMark(Autodesk.Revit.UI.UIApplication app)
        {
            RibbonPanel myPanel = app.GetRibbonPanels()[0];

            Autodesk.Revit.UI.TextBox textBox =
                GetRibbonItemByName(myPanel, "WallMark") as Autodesk.Revit.UI.TextBox;
            if (null == textBox)
            {
                throw new InvalidCastException("Cannot get Wall Mark TextBox!");
            }
            String newWallMark;
            int    newWallIndex = 0;
            FilteredElementCollector collector = new FilteredElementCollector(app.ActiveUIDocument.Document);
            ICollection <Element>    founds    = collector.OfClass(typeof(Wall)).ToElements();

            foreach (Element elem in founds)
            {
                Wall   wall     = elem as Wall;
                string wallMark = wall.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString();
                if (wallMark.StartsWith(textBox.Value.ToString()) && wallMark.Contains('_'))
                {
                    //get the index for new wall (wall_1, wall_2...)
                    char[]   chars   = { '_' };
                    string[] strings = wallMark.Split(chars);
                    if (strings.Length >= 2)
                    {
                        try
                        {
                            int index = Convert.ToInt32(strings[strings.Length - 1]);
                            if (index > newWallIndex)
                            {
                                newWallIndex = index;
                            }
                        }
                        catch (System.Exception)
                        {
                            continue;
                        }
                    }
                }
            }
            newWallMark = textBox.Value.ToString() + '_' + (newWallIndex + 1);
            return(newWallMark);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add a Text Box to the Ribbon Panel
        /// </summary>
        /// <param name="Panel"></param>
        /// <param name="textboxName"></param>
        /// <param name="tooltip"></param>
        /// <returns></returns>
        private Boolean AddTextBox(RibbonPanel Panel, string textboxName, string tooltip)
        {
            try
            {
                TextBoxData tbData = new TextBoxData(textboxName);
                Autodesk.Revit.UI.TextBox textBox = Panel.AddItem(tbData) as Autodesk.Revit.UI.TextBox;

                textBox.PromptText        = "Write something and hit Enter";
                textBox.ShowImageAsButton = true;

                textBox.ToolTip = tooltip;

                textBox.EnterPressed += new EventHandler <TextBoxEnterPressedEventArgs>(MyTextBoxEnter);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method is used to create RibbonSample panel, and add wall related command buttons to it:
        /// 1. contains a SplitButton for user to create Non-Structural or Structural Wall;
        /// 2. contains a StackedBotton which is consisted with one PushButton and two Comboboxes,
        /// PushButon is used to reset all the RibbonItem, Comboboxes are use to select Level and WallShape
        /// 3. contains a RadioButtonGroup for user to select WallType.
        /// 4. Adds a Slide-Out Panel to existing panel with following functionalities:
        /// 5. a text box is added to set mark for new wall, mark is a instance parameter for wall,
        /// Eg: if user set text as "wall", then Mark for each new wall will be "wall1", "wall2", "wall3"....
        /// 6. a StackedButton which consisted of a PushButton (delete all the walls) and a PulldownButton (move all the walls in X or Y direction)
        /// </summary>
        /// <param name="application">An object that is passed to the external application
        /// which contains the controlled application.</param>
        private void CreateRibbonSamplePanel(UIControlledApplication application)
        {
            // create a Ribbon panel which contains three stackable buttons and one single push button.
            string      firstPanelName    = "Ribbon Sample";
            RibbonPanel ribbonSamplePanel = application.CreateRibbonPanel(firstPanelName);

            #region Create a SplitButton for user to create Non-Structural or Structural Wall
            SplitButtonData splitButtonData = new SplitButtonData("NewWallSplit", "Create Wall");
            SplitButton     splitButton     = ribbonSamplePanel.AddItem(splitButtonData) as SplitButton;
            PushButton      pushButton      = splitButton.AddPushButton(new PushButtonData("WallPush", "Wall", AddInPath, "Revit.SDK.Samples.Ribbon.CS.CreateWall"));
            pushButton.LargeImage   = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "CreateWall.png"), UriKind.Absolute));
            pushButton.Image        = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "CreateWall-S.png"), UriKind.Absolute));
            pushButton.ToolTip      = "Creates a partition wall in the building model.";
            pushButton.ToolTipImage = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "CreateWallTooltip.bmp"), UriKind.Absolute));
            pushButton            = splitButton.AddPushButton(new PushButtonData("StrWallPush", "Structure Wall", AddInPath, "Revit.SDK.Samples.Ribbon.CS.CreateStructureWall"));
            pushButton.LargeImage = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "StrcturalWall.png"), UriKind.Absolute));
            pushButton.Image      = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "StrcturalWall-S.png"), UriKind.Absolute));
            #endregion

            ribbonSamplePanel.AddSeparator();

            #region Add a StackedButton which is consisted of one PushButton and two Comboboxes
            PushButtonData     pushButtonData     = new PushButtonData("Reset", "Reset", AddInPath, "Revit.SDK.Samples.Ribbon.CS.ResetSetting");
            ComboBoxData       comboBoxDataLevel  = new ComboBoxData("LevelsSelector");
            ComboBoxData       comboBoxDataShape  = new ComboBoxData("WallShapeComboBox");
            IList <RibbonItem> ribbonItemsStacked = ribbonSamplePanel.AddStackedItems(pushButtonData, comboBoxDataLevel, comboBoxDataShape);
            ((PushButton)(ribbonItemsStacked[0])).Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "Reset.png"), UriKind.Absolute));
            //Add options to WallShapeComboBox
            Autodesk.Revit.UI.ComboBox comboboxWallShape  = (Autodesk.Revit.UI.ComboBox)(ribbonItemsStacked[2]);
            ComboBoxMemberData         comboBoxMemberData = new ComboBoxMemberData("RectangleWall", "RectangleWall");
            ComboBoxMember             comboboxMember     = comboboxWallShape.AddItem(comboBoxMemberData);
            comboboxMember.Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "RectangleWall.png"), UriKind.Absolute));
            comboBoxMemberData   = new ComboBoxMemberData("CircleWall", "CircleWall");
            comboboxMember       = comboboxWallShape.AddItem(comboBoxMemberData);
            comboboxMember.Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "CircleWall.png"), UriKind.Absolute));
            comboBoxMemberData   = new ComboBoxMemberData("TriangleWall", "TriangleWall");
            comboboxMember       = comboboxWallShape.AddItem(comboBoxMemberData);
            comboboxMember.Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "TriangleWall.png"), UriKind.Absolute));
            comboBoxMemberData   = new ComboBoxMemberData("SquareWall", "SquareWall");
            comboboxMember       = comboboxWallShape.AddItem(comboBoxMemberData);
            comboboxMember.Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "SquareWall.png"), UriKind.Absolute));
            #endregion

            ribbonSamplePanel.AddSeparator();

            #region Add a RadioButtonGroup for user to select WallType
            RadioButtonGroupData radioButtonGroupData = new RadioButtonGroupData("WallTypeSelector");
            RadioButtonGroup     radioButtonGroup     = (RadioButtonGroup)(ribbonSamplePanel.AddItem(radioButtonGroupData));
            ToggleButton         toggleButton         = radioButtonGroup.AddItem(new ToggleButtonData("Generic8", "Generic - 8\"", AddInPath, "Revit.SDK.Samples.Ribbon.CS.Dummy"));
            toggleButton.LargeImage = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "Generic8.png"), UriKind.Absolute));
            toggleButton.Image      = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "Generic8-S.png"), UriKind.Absolute));
            toggleButton            = radioButtonGroup.AddItem(new ToggleButtonData("ExteriorBrick", "Exterior - Brick", AddInPath, "Revit.SDK.Samples.Ribbon.CS.Dummy"));
            toggleButton.LargeImage = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "ExteriorBrick.png"), UriKind.Absolute));
            toggleButton.Image      = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "ExteriorBrick-S.png"), UriKind.Absolute));
            #endregion

            //slide-out panel:
            ribbonSamplePanel.AddSlideOut();

            #region add a Text box to set the mark for new wall
            TextBoxData testBoxData           = new TextBoxData("WallMark");
            Autodesk.Revit.UI.TextBox textBox = (Autodesk.Revit.UI.TextBox)(ribbonSamplePanel.AddItem(testBoxData));
            textBox.Value             = "new wall"; //default wall mark
            textBox.Image             = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "WallMark.png"), UriKind.Absolute));
            textBox.ToolTip           = "Set the mark for new wall";
            textBox.ShowImageAsButton = true;
            textBox.EnterPressed     += new EventHandler <Autodesk.Revit.UI.Events.TextBoxEnterPressedEventArgs>(SetTextBoxValue);
            #endregion

            ribbonSamplePanel.AddSeparator();

            #region Create a StackedButton which consisted of a PushButton (delete all the walls) and a PulldownButton (move all the walls in X or Y direction)
            PushButtonData deleteWallsButtonData = new PushButtonData("deleteWalls", "Delete Walls", AddInPath, "Revit.SDK.Samples.Ribbon.CS.DeleteWalls");
            deleteWallsButtonData.ToolTip = "Delete all the walls created by the Create Wall tool.";
            deleteWallsButtonData.Image   = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "DeleteWalls.png"), UriKind.Absolute));

            PulldownButtonData moveWallsButtonData = new PulldownButtonData("moveWalls", "Move Walls");
            moveWallsButtonData.ToolTip = "Move all the walls in X or Y direction";
            moveWallsButtonData.Image   = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "MoveWalls.png"), UriKind.Absolute));

            // create stackable buttons
            IList <RibbonItem> ribbonItems = ribbonSamplePanel.AddStackedItems(deleteWallsButtonData, moveWallsButtonData);

            // add two push buttons as sub-items of the moveWalls PulldownButton.
            PulldownButton moveWallItem = ribbonItems[1] as PulldownButton;

            PushButton moveX = moveWallItem.AddPushButton(new PushButtonData("XDirection", "X Direction", AddInPath, "Revit.SDK.Samples.Ribbon.CS.XMoveWalls"));
            moveX.ToolTip    = "move all walls 10 feet in X direction.";
            moveX.LargeImage = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "MoveWallsXLarge.png"), UriKind.Absolute));

            PushButton moveY = moveWallItem.AddPushButton(new PushButtonData("YDirection", "Y Direction", AddInPath, "Revit.SDK.Samples.Ribbon.CS.YMoveWalls"));
            moveY.ToolTip    = "move all walls 10 feet in Y direction.";
            moveY.LargeImage = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "MoveWallsYLarge.png"), UriKind.Absolute));
            #endregion

            ribbonSamplePanel.AddSeparator();

            application.ControlledApplication.DocumentCreated += new EventHandler <Autodesk.Revit.DB.Events.DocumentCreatedEventArgs>(DocumentCreated);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Text Box Event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void MyTextBoxEnter(object sender, TextBoxEnterPressedEventArgs args)
        {
            UIDocument uiDoc = args.Application.ActiveUIDocument;
            Document   doc   = uiDoc.Document;

            Autodesk.Revit.UI.TextBox textBox = sender as Autodesk.Revit.UI.TextBox;

            string message = textBox.Value.ToString();

            string caseSwitch = "default";

            if (message.Contains("babbo"))
            {
                caseSwitch = "christmas";
            }

            if (message.Contains("leann says"))
            {
                caseSwitch = "leann";
            }

            if (message.Contains("+"))
            {
                caseSwitch = "sum";
            }

            if (message.StartsWith("*"))
            {
                caseSwitch = "select";
            }

            if (message.StartsWith("/"))
            {
                caseSwitch = "selectAll";
            }

            if (message.StartsWith("sheets"))
            {
                caseSwitch = "selectSheets";
            }

            if (message.StartsWith("tblocks"))
            {
                caseSwitch = "selectTBlocks";
            }

            if (message.StartsWith("-"))
            {
                caseSwitch = "delete";
            }

            if (message.StartsWith("+viewset"))
            {
                caseSwitch = "createViewSet";
            }

            switch (caseSwitch)
            {
            case "default":
                MessageBox.Show(textBox.Value.ToString(), "Command Line");
                break;

            case "christmas":
                Helpers.Christams();
                break;

            case "leann":
                Helpers.leannSays();
                break;

            case "sum":
                Helpers.AddTwoIntegers(message);
                break;

            case "select":
                Helpers.SelectAllElementsInView(uiDoc, message);
                break;

            case "selectAll":
                Helpers.SelectAllElements(uiDoc, message);
                break;

            case "createViewSet":
                Helpers.CreateViewset(doc, message);
                break;

            case "delete":
                break;

            case "selectSheets":
                Helpers.HighlightSelectSheets(uiDoc, message);
                break;

            case "selectTBlocks":
                Helpers.HighlightSelectTitleBlocks(uiDoc, message);
                break;
            }
        }