Пример #1
0
        void IServerUI.LayoutInitialized(object sender, LayoutInitializedEventArgs e)
        {
            var entity = e.Entity as Entity;

            if (entity == null)
            {
                return;
            }
            else if (entity.Schema.SchemaName == "tabComboBoxSchema" && !isTabComboBoxSchemaExistsOnElement)
            {
                e.Editor.SetValue("ComboBoxUV", uvList[1], DisplayUnitType.DUT_METERS);
                e.Editor.SetValue("UnitComboBoxDoubleConstructor", 15, DisplayUnitType.DUT_METERS);
                e.Editor.SetValue("ComboBoxXYZ", xyzList[2], DisplayUnitType.DUT_METERS);
                e.Editor.SetValue("ComboBoxRebar", rebarList[2], DisplayUnitType.DUT_UNDEFINED);
            }
            else if (entity.Schema.SchemaName == "tabComboBoxSchema" && isTabComboBoxSchemaExistsOnElement)
            {
                var tab = new TabComboBoxSchema(entity, null);
                e.Editor.SetValue("ComboBoxUV", tab.ComboBoxUV, DisplayUnitType.DUT_METERS);
                e.Editor.SetValue("ComboBoxXYZ", tab.ComboBoxXYZ, DisplayUnitType.DUT_METERS);
                e.Editor.SetValue("UnitComboBoxDoubleConstructor", tab.UnitComboBoxDoubleConstructor, DisplayUnitType.DUT_METERS);
            }
        }
Пример #2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // One element should be selected and will be the active element
            Document document = commandData.Application.ActiveUIDocument.Document;

            if (commandData.Application.ActiveUIDocument.Selection.GetElementIds().Count != 1)
            {
                TaskDialog.Show("Error", "One element should be selected");
                return(Result.Cancelled);
            }

            // Check if five rebars are inside the project
            ElementId elementId = (new FilteredElementCollector(document).OfClass(typeof(RebarBarType)).ToElementIds() as List <ElementId>)[4] as ElementId;

            if (elementId == null)
            {
                TaskDialog.Show("Error", "At least five rebars should on this project");
                return(Result.Cancelled);
            }

            Element   activeElement   = null;
            ElementId activeElementId = null;


            foreach (ElementId eId in commandData.Application.ActiveUIDocument.Selection.GetElementIds())
            {
                activeElementId = eId;
            }

            //Create all schema instances associated to tabs instances with default constructor
            var instanceTabTextBox       = new TabTextBoxSchema();
            var instanceTabGrid          = new TabGridSchema();
            var instanceTabKey           = new TabKeySchema();
            var instanceTabNumericUpDown = new TabNumericUpDownSchema();
            var instanceTabComboBox      = new TabComboBoxSchema();
            var instanceTabListTextBox   = new TabListTextBoxSchema(document);
            var instanceTabEnum          = new TabEnumSchema();
            var instanceTabList          = new TabListSchema();
            var instanceTabCategory      = new TabCategorySchema();
            var instanceTabMiscellanious = new TabMiscellaniousSchema();


            // Data preparation
            // initialization of element from the Revit project
            instanceTabComboBox.ComboBoxElementId = elementId;
            instanceTabTextBox.TextBoxElementId   = activeElementId;
            activeElement = commandData.Application.ActiveUIDocument.Document.GetElement(activeElementId);

            rebarList = new FilteredElementCollector(document).OfClass(typeof(RebarBarType)).ToElements().Cast <RebarBarType>().ToList();

            // Check if we are in reading mode by quering active element
            isTabTextBoxSchemaExistsOnElement       = instanceTabTextBox.Exists(activeElement);
            isTabGridSchemaExistsOnElement          = instanceTabGrid.Exists(activeElement);
            isTabKeySchemaExistsOnElement           = instanceTabKey.Exists(activeElement);
            isTabNumericUpDownSchemaExistsOnElement = instanceTabNumericUpDown.Exists(activeElement);
            isTabComboBoxSchemaExistsOnElement      = instanceTabComboBox.Exists(activeElement);
            isTabListTextBoxSchemaExistsOnElement   = instanceTabListTextBox.Exists(activeElement);
            isTabEnumSchemaExistsOnElement          = instanceTabEnum.Exists(activeElement);
            isTabListSchemaExistsOnElement          = instanceTabList.Exists(activeElement);
            isTabCategorySchemaExistsOnElement      = instanceTabCategory.Exists(activeElement);
            isTabMiscellaniousSchemaExistsOnElement = instanceTabMiscellanious.Exists(activeElement);

            //Load data
            instanceTabTextBox.Load(activeElement);
            instanceTabGrid.Load(activeElement);
            instanceTabKey.Load(activeElement);
            instanceTabNumericUpDown.Load(activeElement);
            instanceTabComboBox.Load(activeElement);
            instanceTabListTextBox.Load(activeElement);
            instanceTabEnum.Load(activeElement);
            instanceTabList.Load(activeElement);
            instanceTabCategory.Load(activeElement);
            instanceTabMiscellanious.Load(activeElement);

            //Create all layouts on schema
            Layout layoutTabTextBox       = Layout.Build(typeof(TabTextBoxSchema), this);
            Layout layoutTabGrid          = Layout.Build(typeof(TabGridSchema), this);
            Layout layoutTabKey           = Layout.Build(typeof(TabKeySchema), this);
            Layout layoutTabNumericUpDown = Layout.Build(typeof(TabNumericUpDownSchema), this);
            Layout layoutTabComboBox      = Layout.Build(typeof(TabComboBoxSchema), this);
            Layout layoutTabListTextBox   = Layout.Build(typeof(TabListTextBoxSchema), this);
            Layout layoutTabEnum          = Layout.Build(typeof(TabEnumSchema), this);
            Layout layoutTabList          = Layout.Build(typeof(TabListSchema), this);
            Layout layoutTabCategory      = Layout.Build(typeof(TabCategorySchema), this);
            Layout layoutTabMiscellanious = Layout.Build(typeof(TabMiscellaniousSchema), this);

            // add an image in line on the last tab
            var image = new Image
            {
                Source = new Uri(@"pack://application:,,,/ExtensibleStorageUI;component/Images/bigImage1.png"),
                Index  = 1,
                Key    = "image1"
            };

            layoutTabMiscellanious.Controls.Insert(0, image);

            // add a free text inline
            var textBlock = new TextBlock
            {
                Text  = "This a test of the textblock usage",
                Index = 2,
                Key   = "text"
            };

            layoutTabMiscellanious.Controls.Insert(1, textBlock);


            // build all layout objects
            ILayoutControl layoutCtrTabTextBox       = Layout.BuildControl(this, document, layoutTabTextBox, instanceTabTextBox.GetEntity());
            ILayoutControl layoutCtrTabGrid          = Layout.BuildControl(this, document, layoutTabGrid, instanceTabGrid.GetEntity());
            ILayoutControl layoutCtrTabKey           = Layout.BuildControl(this, document, layoutTabKey, instanceTabKey.GetEntity());
            ILayoutControl layoutCtrTabNumericUpDown = Layout.BuildControl(this, document, layoutTabNumericUpDown, instanceTabNumericUpDown.GetEntity());
            ILayoutControl layoutCtrTabComboBox      = Layout.BuildControl(this, document, layoutTabComboBox, instanceTabComboBox.GetEntity());
            ILayoutControl layoutCtrTabListTextBox   = Layout.BuildControl(this, document, layoutTabListTextBox, instanceTabListTextBox.GetEntity());
            ILayoutControl layoutCtrTabEnum          = Layout.BuildControl(this, document, layoutTabEnum, instanceTabEnum.GetEntity());
            ILayoutControl layoutCtrTabList          = Layout.BuildControl(this, document, layoutTabList, instanceTabList.GetEntity());
            ILayoutControl layoutCtrTabCategory      = Layout.BuildControl(this, document, layoutTabCategory, instanceTabCategory.GetEntity());
            ILayoutControl layoutCtrTabMiscellanious = Layout.BuildControl(this, document, layoutTabMiscellanious, instanceTabMiscellanious);

            //create main window and add all object
            var window = new MainWindows
            {
                Name  = "ExtensibleStorageUIOverview",
                Title = "Extensible Storage UI Overview"
            };
            var layout = new MainLayout
            {
                tabTextBox       = { Content = layoutCtrTabTextBox },
                tabGrid          = { Content = layoutCtrTabGrid },
                tabKey           = { Content = layoutCtrTabKey },
                tabNumericUpDown = { Content = layoutCtrTabNumericUpDown },
                tabComboBox      = { Content = layoutCtrTabComboBox },
                tabListTextBox   = { Content = layoutCtrTabListTextBox },
                tabEnum          = { Content = layoutCtrTabEnum },
                tabList          = { Content = layoutCtrTabList },
                tabCategory      = { Content = layoutCtrTabCategory },
                tabMiscellanious = { Content = layoutCtrTabMiscellanious }
            };

            window.layout.Children.Add(layout);
            window.ShowAndAssignParent();

            //Getting data from UI
            instanceTabTextBox       = new TabTextBoxSchema(layoutCtrTabTextBox.GetEntity(), document);
            instanceTabGrid          = new TabGridSchema(layoutCtrTabGrid.GetEntity(), document);
            instanceTabKey           = new TabKeySchema(layoutCtrTabKey.GetEntity(), document);
            instanceTabNumericUpDown = new TabNumericUpDownSchema(layoutCtrTabNumericUpDown.GetEntity(), document);
            instanceTabComboBox      = new TabComboBoxSchema(layoutCtrTabComboBox.GetEntity(), document);
            instanceTabListTextBox   = new TabListTextBoxSchema(layoutCtrTabListTextBox.GetEntity(), document);
            instanceTabEnum          = new TabEnumSchema(layoutCtrTabEnum.GetEntity(), document);
            instanceTabList          = new TabListSchema(layoutCtrTabList.GetEntity(), document);
            instanceTabCategory      = new TabCategorySchema(layoutCtrTabCategory.GetEntity(), document);
            instanceTabMiscellanious = new TabMiscellaniousSchema(instanceTabMiscellanious.GetEntity(), document);

            //Saving Data into selected element
            if (window.storeSchema)
            {
                var t = new Transaction(document, "Save schemas");
                t.Start();
                instanceTabTextBox.Save(activeElement);
                instanceTabGrid.Save(activeElement);
                instanceTabKey.Save(activeElement);
                instanceTabNumericUpDown.Save(activeElement);
                instanceTabComboBox.Save(activeElement);
                instanceTabListTextBox.Save(activeElement);
                instanceTabEnum.Save(activeElement);
                instanceTabList.Save(activeElement);
                instanceTabCategory.Save(activeElement);
                instanceTabMiscellanious.Save(activeElement);
                t.Commit();
            }
            return(Result.Succeeded);
        }