Adding a shared Parameter for all the elements in a active view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
My goal is to add a shared parameter into the revit model that is shared by all the elements that are in te active view.
Here is my code and my mistake is in the INSTANCEBINDING. Anyone have any idea? Lot of thanks.
public void CreateSampleSharedParameters(Document doc, UIApplication uiapp, Application app)
{
//Cargamos el fichero
string originalFile = app.SharedParametersFilename;
string tempFile = @"C:\Users\Usuario\Desktop\Manu García Romero\Práctica Empresa TeamBimCivil\**********\para_comp.txt";
//EMPIEZA LA TRANSACCION AQUI
using (Transaction t = new Transaction(doc))
{
t.Start("Crear Parametro Compartido");
app.SharedParametersFilename = tempFile;
DefinitionFile sharedParameterFile = app.OpenSharedParameterFile();
DefinitionGroups myGroups = sharedParameterFile.Groups;
DefinitionGroup myGroup = myGroups.Create("ZONAS");
ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions("ubicacion", ParameterType.Text);
Definition myDefinition_ubicacion = myGroup.Definitions.Create(option);
CategorySet myCategories = uiapp.Application.Create.NewCategorySet();
FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
var categories = collector.ToElements().Select(x => x.Category).Distinct(new CategoryComparer()).ToList(); .
foreach (Category cat in categories)
{
myCategories.Insert(cat);
InstanceBinding instanceBinding = uiapp.Application.Create.NewInstanceBinding(myCategories);
doc.ParameterBindings.Insert(myDefinition_ubicacion, instanceBinding, BuiltInParameterGroup.PG_TEXT);
}
t.commit();