Esempio n. 1
0
        private void GroupSelectComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            definitionGroup = GroupSelectComboBox.SelectedItem;
            string definitionGroupName = definitionGroup.ToString();

            SortedList <string, ExternalDefinition> sharedParameterList = new SharedParametersLibrary(doc, app).GetSharedParameterList(definitionGroupName);

            ParameterList.Items.Clear();
            foreach (KeyValuePair <string, ExternalDefinition> parameterKeyValue in sharedParameterList)
            {
                ParameterList.Items.Add(parameterKeyValue.Key);
            }
        }
Esempio n. 2
0
        public LoadToFamilyForm(Document document, Autodesk.Revit.ApplicationServices.Application application)
        {
            InitializeComponent();

            app = application;
            doc = document;

            definitionfile = app.OpenSharedParameterFile();

            List <string> groupList = new SharedParametersLibrary(doc, app).GetDefinitionGroupList();
            Dictionary <string, BuiltInParameterGroup> builtInParameterGroupDictionary = new SharedParametersLibrary(doc, app).BuiltInParameterGroupDictionary(doc);

            GroupSelectComboBox.Items.AddRange(groupList.ToArray());
            ParameterList.Items.Add("Please select a group.");
            GroupParameterUnderComboBox.Items.AddRange(builtInParameterGroupDictionary.Keys.ToArray());
            InstanceCheck.Checked = true;
        }
Esempio n. 3
0
        public void AddParametersToFamily(Document doc, Autodesk.Revit.ApplicationServices.Application app)
        {
            Dictionary <string, BuiltInParameterGroup> builtInParameterGroupDictionary = new SharedParametersLibrary(doc, app).BuiltInParameterGroupDictionary(doc);
            SortedList <string, Category> parameterCategoryList = new SharedParametersLibrary(doc, app).ParameterCategoryList(doc);

            selectedGroup = GroupParameterUnderComboBox.SelectedItem;
            string selectedGroupName = selectedGroup.ToString();

            definitionGroup = GroupSelectComboBox.SelectedItem;
            string definitionGroupName = definitionGroup.ToString();

            BuiltInParameterGroup builtInParameterGroup = builtInParameterGroupDictionary[selectedGroupName];

            SortedList <string, ExternalDefinition> sharedParameterList = new SharedParametersLibrary(doc, app).GetSharedParameterList(definitionGroupName);

            FamilyManager familyManager = doc.FamilyManager;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Add Selected Shared Parameters");

                foreach (string selectedParameter in ParameterList.SelectedItems)
                {
                    if ((sharedParameterList.ContainsKey(selectedParameter)) && (TypeCheck.Checked))
                    {
                        ExternalDefinition externalDefinition =
                            new SharedParametersLibrary(doc, app).ExternalDefinitionExtractor(selectedParameter, sharedParameterList);
                        familyManager.AddParameter(externalDefinition, builtInParameterGroup, false);
                    }
                    else if ((sharedParameterList.ContainsKey(selectedParameter)) && (InstanceCheck.Checked))
                    {
                        ExternalDefinition externalDefinition =
                            new SharedParametersLibrary(doc, app).ExternalDefinitionExtractor(selectedParameter, sharedParameterList);
                        familyManager.AddParameter(externalDefinition, builtInParameterGroup, true);
                    }
                    else
                    {
                    }
                }
                tx.Commit();
            }
        }
Esempio n. 4
0
        public void AddParametersToProject(Document doc, Autodesk.Revit.ApplicationServices.Application app)
        {
            Dictionary <string, BuiltInParameterGroup> builtInParameterGroupDictionary = new SharedParametersLibrary(doc, app).BuiltInParameterGroupDictionary(doc);
            SortedList <string, Category> parameterCategoryList = new SharedParametersLibrary(doc, app).ParameterCategoryList(doc);

            selectedGroup = GroupParameterUnderComboBox.SelectedItem;
            string selectedGroupName = selectedGroup.ToString();

            definitionGroup = GroupSelectComboBox.SelectedItem;
            string definitionGroupName = definitionGroup.ToString();

            BuiltInParameterGroup builtInParameterGroup = builtInParameterGroupDictionary[selectedGroupName];

            SortedList <string, ExternalDefinition> sharedParameterList = new SharedParametersLibrary(doc, app).GetSharedParameterList(definitionGroupName);

            CategorySet categoryset = app.Create.NewCategorySet();

            foreach (string category in CategoryCheckList.CheckedItems)
            {
                categoryset.Insert(parameterCategoryList[category]);
            }

            // existing shared parameter list
            List <string>            collectorList            = new List <string>();
            List <string>            existingParameterList    = new List <string>();
            List <string>            nonExistingParameterList = new List <string>();
            FilteredElementCollector parameterCollector       = new FilteredElementCollector(doc);

            parameterCollector.OfClass(typeof(SharedParameterElement));

            foreach (var e in parameterCollector)
            {
                collectorList.Add(e.Name.ToString());
            }

            foreach (string parameter in ParameterList.SelectedItems)
            {
                if (collectorList.Contains(parameter))
                {
                    existingParameterList.Add(parameter);
                }
                else
                {
                    nonExistingParameterList.Add(parameter);
                }
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Add Selected Shared Parameters");

                foreach (string selectedParameter in nonExistingParameterList)
                {
                    if ((sharedParameterList.ContainsKey(selectedParameter)) && (TypeCheck.Checked))
                    {
                        ExternalDefinition externalDefinition =
                            new SharedParametersLibrary(doc, app).ExternalDefinitionExtractor(selectedParameter, sharedParameterList);
                        TypeBinding newBinding = app.Create.NewTypeBinding(categoryset);
                        doc.ParameterBindings.Insert(externalDefinition, newBinding, builtInParameterGroup);
                    }
                    else if ((sharedParameterList.ContainsKey(selectedParameter)) && (InstanceCheck.Checked))
                    {
                        ExternalDefinition externalDefinition =
                            new SharedParametersLibrary(doc, app).ExternalDefinitionExtractor(selectedParameter, sharedParameterList);
                        InstanceBinding newBinding = app.Create.NewInstanceBinding(categoryset);
                        doc.ParameterBindings.Insert(externalDefinition, newBinding, builtInParameterGroup);
                    }
                    else
                    {
                    }
                }
                foreach (string selectedParameter in existingParameterList)
                {
                    if ((sharedParameterList.ContainsKey(selectedParameter)) && (TypeCheck.Checked))
                    {
                        ExternalDefinition externalDefinition =
                            new SharedParametersLibrary(doc, app).ExternalDefinitionExtractor(selectedParameter, sharedParameterList);
                        TypeBinding newBinding = app.Create.NewTypeBinding(categoryset);
                        doc.ParameterBindings.ReInsert(externalDefinition, newBinding, builtInParameterGroup);
                    }
                    else if ((sharedParameterList.ContainsKey(selectedParameter)) && (InstanceCheck.Checked))
                    {
                        ExternalDefinition externalDefinition =
                            new SharedParametersLibrary(doc, app).ExternalDefinitionExtractor(selectedParameter, sharedParameterList);
                        InstanceBinding newBinding = app.Create.NewInstanceBinding(categoryset);
                        doc.ParameterBindings.ReInsert(externalDefinition, newBinding, builtInParameterGroup);
                    }
                    else
                    {
                    }
                }
                tx.Commit();
            }
        }