Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating project parameter categories

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
828 Views, 1 Reply

Updating project parameter categories

hi all,

 

For an addin I'm trying to develop I neede to use some Shared Project Parameters so I've started with the code provided here and developed this method the following method that first checks if the parameter is available in the shared parameter file and then adds if it wasn't found. 

 

The second step is adding the parameter to the project parameters and apply it to the selected catagories. You wount have anyproblems if the parameter doesn't exist in the project but if the parameter already exist and for som reason you've added more categories to apply to these are not updated in the project.

 

Any suggestions on how to apply the parameter to new categories if the parameter already exist in the project and already aplyes to some categories?

 

 

        public const string SharedParamFile = @"R:\Documentos Comunes\0.Revit MEP\Parametros compartidos\Parametros compartidos.txt";

        public static bool AddProjectSharedParam(Application m_app, Document doc, string sharedParamGroup, string sharedParamName, ParameterType sharedParamType, CategorySet projectCategories, BuiltInParameterGroup projectGroup)
        {

            if (doc.IsFamilyDocument)
            {
                TaskDialog.Show("Este documento es familia", "Utiliza este addin en una familia.");
                return false;
            }

            DefinitionFile deffile;
            string fname = PGIUtil.SharedParamFile;
            ProjectInfo projInfo = doc.ProjectInformation;

            m_app.SharedParametersFilename = fname;

            deffile = m_app.OpenSharedParameterFile();
            if (deffile == null)
                throw new Exception("No shared file");

            using (Transaction t = new Transaction(doc, "Añadir parámetro compartido " + sharedParamName))
            {
                t.Start();

                DefinitionGroups myGroups = deffile.Groups;
                DefinitionGroup myGroup;
                ExternalDefinition myDef;

                if (myGroups.get_Item(sharedParamGroup) == null)
                    myGroup = myGroups.Create(sharedParamGroup);
                else
                    myGroup = myGroups.get_Item(sharedParamGroup);

                if (myGroup.Definitions.get_Item(sharedParamName) == null)
                    myDef = myGroup.Definitions.Create(sharedParamName, sharedParamType) as ExternalDefinition;
                else
                    myDef = myGroup.Definitions.get_Item(sharedParamName) as ExternalDefinition;

                //CategorySet myCats = m_app.Create.NewCategorySet();
                //Category myCat = new UIApplication(m_app).ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_ProjectInformation);

                //myCats.Insert(myCat);

                InstanceBinding instanceBinding = new UIApplication(m_app).Application.Create.NewInstanceBinding(projectCategories);
                BindingMap bindingMap  = new UIApplication(m_app).ActiveUIDocument.Document.ParameterBindings;
                bindingMap.Insert(myDef, instanceBinding, projectGroup);

                t.Commit();
            }
            return true;
        }

 To call the method the first time I use:

                CategorySet myCats = app.Create.NewCategorySet();
                Category pipeFittingCat = new UIApplication(app).ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_PipeFitting);
                Category pipeCat = new UIApplication(app).ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_PipeCurves);

                myCats.Insert(pipeFittingCat);
                myCats.Insert(pipeCat);

                PGIUtil.AddProjectSharedParam(app, doc,"Proyecto PRO", "PGI Elemento al exterior", ParameterType.YesNo, myCats, BuiltInParameterGroup.PG_IDENTITY_DATA);

 And on the second intend I'm adding the PipeAccesories category.

                CategorySet myCats = app.Create.NewCategorySet();
                Category pipeFittingCat = new UIApplication(app).ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_PipeFitting);
                Category pipeAccesoryCat = new UIApplication(app).ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_PipeAccessory);
                Category pipeCat = new UIApplication(app).ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_PipeCurves);

                myCats.Insert(pipeFittingCat);
                myCats.Insert(pipeAccesoryCat);
                myCats.Insert(pipeCat);

                PGIUtil.AddProjectSharedParam(app, doc,"Proyecto PRO", "PGI Elemento al exterior", ParameterType.YesNo, myCats, BuiltInParameterGroup.PG_IDENTITY_DATA);

 

1 REPLY 1
Message 2 of 2
Joe.Ye
in reply to: Anonymous

 


Hi

for existing shared parameter definition bindings in a file, you can get them by Document.ParameterBindings property. And then iterate the map to get your target parameter definition binding It is a ElementBinding instance. You can then add or remove category to the InstanceBinding.Categories or TypeBinding.Categories.



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report