How can i add a projet parameter

How can i add a projet parameter

Anonymous
Not applicable
485 Views
4 Replies
Message 1 of 5

How can i add a projet parameter

Anonymous
Not applicable

Hello , 

 

I'm trying to add a new projet parameter using C# code and set a value to this created parameter during adding a Material  anyone can help me please  ?

0 Likes
486 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Hello,

if I'm not mistaken, you can't create project parameter via Revit API.

0 Likes
Message 3 of 5

MarryTookMyCoffe
Collaborator
Collaborator

for moment I thought it was possible, but no it's not(it is still shareadParameter) and this stupid forum don't allow to delete posts

 

Ha it is possible, I just made it. 🙂
this is how :

          Transaction trans = new Transaction(doc);
            trans.Start("Project Parameter");
//first you need to create Definition group 
            DefinitionGroup defGr = //your metod to create it, my is to long to past here but there is a exemple in SDK
            ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions("nowe", ParameterType.Text);
// here we create Definition
            Definition ed = defGr.Definitions.Create(option);
//chose in witch category schould it be
            CategorySet cs = new CategorySet();
            cs.Insert(Category.GetCategory(uidoc.Document, BuiltInCategory.OST_PipeCurves));
//you can bind it as instance or type, I did with Instance
            InstanceBinding bind = new InstanceBinding(cs);
// with it you made a new project parameter
            uidoc.Document.ParameterBindings.Insert(ed, bind);
            trans.Commit();

---------------------------------------------

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
Message 4 of 5

Anonymous
Not applicable

Is it project parameter?

I think this shared parameter!

Can you show your externalDefinition creating?

0 Likes
Message 5 of 5

Anonymous
Not applicable

Me to i was able to do it 2 days ago by using this code 

 

 

string originalFile = uiapp.Application.SharedParametersFilename;
                                            string tempFile = Path.GetTempFileName() + ".txt";
                                            using (File.Create(tempFile)) { }
                                            uiapp.Application.SharedParametersFilename = tempFile;
                                            string param = range.Cells[4, j].Value2;
                                            if (myMaterial.LookupParameter(param) == null)
                                            {
                                                ExternalDefinitionCreationOptions edco = new ExternalDefinitionCreationOptions(param, ParameterType.Text);
                                                edco.Visible = true;
                                                var definition = uiapp.Application.OpenSharedParameterFile().Groups.Create("MaterialsParameters").Definitions.Create(edco);
                                                uiapp.Application.SharedParametersFilename = originalFile;
                                                File.Delete(tempFile);
                                                var newCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Materials);
                                                var newCategorySet = uiapp.Application.Create.NewCategorySet();
                                                newCategorySet.Insert(newCategory);
                                                Autodesk.Revit.DB.Binding binding = uiapp.Application.Create.NewInstanceBinding(newCategorySet);
                                                doc.ParameterBindings.Insert(definition, binding, BuiltInParameterGroup.PG_DATA);
                                                myMaterial.LookupParameter(param).Set((string)range.Cells[iRow, j].Value2);
                                            }
                                            else
                                            {
                                                if (!string.IsNullOrEmpty((string)range.Cells[iRow, j].Value2))
                                                    myMaterial.LookupParameter(param).Set((string)range.Cells[iRow, j].Value2);
                                            }

 

0 Likes