Adding a shared parameter

Adding a shared parameter

Anonymous
Not applicable
14,601 Views
2 Replies
Message 1 of 3

Adding a shared parameter

Anonymous
Not applicable

Hello everybody!,

 

I am new in revit API so, apologies if my question is a bit stupid, I am looking for the solution but i did not find it.

 

I am trying to create a macro to synchronize the space parameters between models. these parameters are into the same shared parameter file.

I can get the shared parameter file with:

... DefinitionFile spFile = this.Application.OpenSharedParameterFile();
DefinitionGroups defGrs = spFile.Groups;...

 

I would like to add to my model the existing shared parameters in the shared parameter file. I am tryin to do it with:

...Binding b = this.Application.Create.NewInstanceBinding(defGr);   ...

 

But I am not obtaining anything....

 

I would like to add shared parameters from a shared parameters file to the Spaces category, under Electrical params. group and as instance parameter.

 

Could anyone please give me any clue?

 

 

many thanks in advance

0 Likes
Accepted solutions (1)
14,602 Views
2 Replies
Replies (2)
Message 2 of 3

Dale.Bartlett
Collaborator
Collaborator

Not sure if this helps, original code probably came from Jeremy (Building Coder). Are you wrapping in transaction correctly?

 

// See if the parameter is an instance or type parameter.
            InstanceBinding instanceBinding = pParameterData.Binding as InstanceBinding;
            if (instanceBinding != null)
            {
                // Is an Instance parameter
                InstanceBinding newInstanceBinding = pDoc.Application.Create.NewInstanceBinding(cats);
                if (pDoc.ParameterBindings.ReInsert(pParameterData.Definition, newInstanceBinding))
                {
                    result = true;
                }
            }
            else
            {
                // Is a type parameter
                TypeBinding typeBinding = pDoc.Application.Create.NewTypeBinding(cats);
                if (pDoc.ParameterBindings.ReInsert(pParameterData.Definition, typeBinding))
                {
                    result = true;
                }
            }

Dale

 




______________
Yes, I'm Satoshi.
Message 3 of 3

Anonymous
Not applicable
Accepted solution

Dale, many thanks for your clue, it helped...

 

finally, here is my code to add params. from the shared parameters file to my project...

 

			UIDocument uiDoc = this.ActiveUIDocument;
			Document doc = this.ActiveUIDocument.Document;
			Selection sel = uiDoc.Selection;
			Category cat = doc.Settings.Categories.get_Item(BuiltInCategory.OST_MEPSpaces);
			CategorySet catSet = this.Application.Create.NewCategorySet();
		    catSet.Insert(cat);
			
						
			DefinitionFile spFile = this.Application.OpenSharedParameterFile();
			
			foreach (DefinitionGroup dG in spFile.Groups)
			{
				if (dG.Name == "Space")
				{
					var v = (from ExternalDefinition d in dG.Definitions select d);
					using (Transaction t = new Transaction(doc))
					{
						t.Start("Add Space Shared Parameters");					
						foreach (ExternalDefinition eD in v)
						{
							InstanceBinding newIB = this.Application.Create.NewInstanceBinding(catSet);
							doc.ParameterBindings.Insert(eD,newIB,BuiltInParameterGroup.PG_TEXT);
						}
						t.Commit();