예제 #1
0
        public static void BrickDimCheck(BrickDimSelector brDimSel, UIDocument uidoc, Document doc)
        {
            ISelectionFilter dimsFilt = new SelectionFilterDims();
            ElementId        dimId    = uidoc.Selection.PickObject(ObjectType.Element, dimsFilt).ElementId;
            Dimension        dim      = doc.GetElement(dimId) as Dimension;

            StringBuilder sb = new StringBuilder();

            //if empty add to cut brick list list
            //we could also check for multi dims and flag to user, poss with split method...
            if (dim.Value == null)
            {
                sb.Append("Something went wrong, perhaps this is a multi-dim?");
                brDimSel.BrickDimReadout.Content = sb.ToString();
                //we could probably override suffixes here if we wanted...dim.Suffix = "Joint";
                //this is probably a multi one, we could give a list?!
            }

            else
            {
                //get dimension value in mm
                double dimValue      = Convert.ToDouble(dim.Value);
                double dimValueMm    = UnitUtils.ConvertFromInternalUnits(dimValue, UnitTypeId.Millimeters);
                double dimValueMmRnd = BrickFuncts.round(dimValueMm); //round to 1 dp

                //divide by CO
                double dimCO = dimValueMmRnd / BrickFuncts.CO(1);
                //get math floor and set of CO values
                double dimCOflr = Math.Floor(dimCO);

                double dimCOflrCO      = BrickFuncts.round(BrickFuncts.CO(dimCOflr));
                double dimCOflrCOminus = BrickFuncts.round(BrickFuncts.COMinus(dimCOflr));
                double dimCOflrCOPlus  = BrickFuncts.round(BrickFuncts.COPlus(dimCOflr));

                //get math ceiling and set of CO values
                double dimCOclng = Math.Ceiling(dimCO);

                double dimCOclngCO      = BrickFuncts.round(BrickFuncts.CO(dimCOclng));
                double dimCOclngCOminus = BrickFuncts.round(BrickFuncts.COMinus(dimCOclng));
                double dimCOclngCOPlus  = BrickFuncts.round(BrickFuncts.COPlus(dimCOclng));

                sb.Append("CO-\t\tCO\t\tCO+\n");
                sb.Append(dimCOflrCOminus.ToString() + "\t\t" + dimCOflrCO.ToString() + "\t\t" + dimCOflrCOPlus.ToString() + "\n");
                sb.Append(dimCOclngCOminus.ToString() + "\t\t" + dimCOclngCO.ToString() + "\t\t" + dimCOclngCOPlus.ToString());

                brDimSel.BrickDimReadout.Content = sb.ToString();
                brDimSel.DimSelClick.Text        = dimValueMmRnd.ToString();
            }
        }
예제 #2
0
        /// <summary>
        /// This is the method which launches the WPF window, and injects any methods that are
        /// wrapped by ExternalEventHandlers. This can be done in a number of different ways, and
        /// implementation will differ based on how the WPF is set up.
        /// </summary>
        /// <param name="uiapp">The Revit UIApplication within the add-in will operate.</param>
        public void ShowForm(UIApplication uiapp)
        {
            // If we do not have a dialog yet, create and show it
            if (_mMyForm != null && _mMyForm == null)
            {
                return;
            }
            //EXTERNAL EVENTS WITH ARGUMENTS
            EventHandlerWithWpfArg evWpf = new EventHandlerWithWpfArg();

            _mMyForm = new BrickDimSelector(uiapp, evWpf);

            HwndSource hwndSource = HwndSource.FromHwnd(uiapp.MainWindowHandle);

            System.Windows.Window wnd = hwndSource.RootVisual as System.Windows.Window;
            if (wnd != null)
            {
                _mMyForm.Owner         = wnd;
                _mMyForm.ShowInTaskbar = false;
                _mMyForm.Show();
            }
        }
예제 #3
0
        public Result OnStartup(UIControlledApplication a)
        {
            _mMyForm = null; // no dialog needed yet; the command will bring it
            ThisApp  = this; // static access to this application instance

            BrickDimUpdater updater = new BrickDimUpdater(a.ActiveAddInId);

            Debug.Print("register");
            UpdaterRegistry.RegisterUpdater(updater);
            ElementCategoryFilter f = new ElementCategoryFilter(BuiltInCategory.OST_Dimensions);

            Debug.Print("filter");
            UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), f, Element.GetChangeTypeAny());


            // Method to add Tab and Panel
            RibbonPanel panel = RibbonPanel(a);

            string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;

            // BUTTON FOR COLOURING DIMENSIONS
            if (panel.AddItem(
                    new PushButtonData("Colour", "Colour\nIn View", thisAssemblyPath,
                                       "BrickDims.BrickDimsColourOverride")) is PushButton button2)
            {
                button2.ToolTip = "Visual interface for debugging applications.";
                Uri         uriImageB2   = new Uri("pack://application:,,,/BrickDims;component/Resources/brick-Rainbow.png");
                BitmapImage largeImageB2 = new BitmapImage(uriImageB2);
                button2.LargeImage = largeImageB2;
            }

            //panel.AddSeparator();

            /// <summary>
            /// Control buttons for the Dynamic Model Update
            /// </summary>
            ToggleButtonData toggleButtonData3
                = new ToggleButtonData("UpdaterStoptxtOff", "Stop\nAuto", thisAssemblyPath, "BrickDims.UIDynamicModelUpdateOff");
            Uri         uriImageTB3   = new Uri("pack://application:,,,/BrickDims;component/Resources/stop-big.png");
            BitmapImage largeImageTB3 = new BitmapImage(uriImageTB3);

            toggleButtonData3.LargeImage = largeImageTB3;


            ToggleButtonData toggleButtonData4
                = new ToggleButtonData("UpdaterPlaytxtOff", "Start\nAuto", thisAssemblyPath, "BrickDims.UIDynamicModelUpdateOn");
            Uri         uriImageTB4   = new Uri("pack://application:,,,/BrickDims;component/Resources/play-big.png");
            BitmapImage largeImageTB4 = new BitmapImage(uriImageTB4);

            toggleButtonData4.LargeImage = largeImageTB4;

            //TextBoxData brkDimTxt = new TextBoxData("Pause Play Updater");

            //panel.AddItem(toggleButtonData3);
            //panel.AddItem(toggleButtonData4);

            // make dyn update on/off radio button group

            RadioButtonGroupData radioBtnGroupData2 = new RadioButtonGroupData("Updater");

            //IList<RibbonItem> stackedGroup1 = panel.AddStackedItems(toggleButtonData4, toggleButtonData3);
            //as RadioButtonGroup;
            RadioButtonGroup radioBtnGroup2 = panel.AddItem(radioBtnGroupData2) as RadioButtonGroup;

            radioBtnGroup2.AddItem(toggleButtonData3);
            radioBtnGroup2.AddItem(toggleButtonData4);


            // listeners/watchers for external events (if you choose to use them)
            a.ApplicationClosing += a_ApplicationClosing; //Set Application to Idling
            a.Idling             += a_Idling;

            //turn off text in buttons where we want it
            setButtonNoText();

            panel.AddSeparator();

            // BUTTON FOR THE SINGLE-THREADED WPF OPTION
            if (panel.AddItem(
                    new PushButtonData("Brick Dim Selector", "Selector", thisAssemblyPath,
                                       "BrickDims.EntryCommand")) is PushButton button)
            {
                // defines the tooltip displayed when the button is hovered over in Revit's ribbon
                button.ToolTip = "Visual interface for debugging applications.";
                // defines the icon for the button in Revit's ribbon - note the string formatting
                Uri         uriImageB1   = new Uri("pack://application:,,,/BrickDims;component/Resources/brick-Small.png");
                BitmapImage largeImageB1 = new BitmapImage(uriImageB1);
                button.LargeImage = largeImageB1;
            }

            return(Result.Succeeded);
        }