Not applicable
04-14-2016
09:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I’m working on a add-in which needs extra parameters. I don’t want to clutter the user’s type parameters, therefore, I decided that I would use a “Schema and Store Data”. I have everything working wonderfully, however, my add-in is only adding the Schema to one titleblock (current titleblock) instead of all the title blocks like a “type parameter”. My code is included I’m using a FamilyInstance of the current title block.
private string familyName = ""; private FamilyInstance familyInstance; private FamilySymbol familySymbol; //Retrives the titleblock in the active view. The method is used to compare the size of the titlblock. public void getTitleblockSize(Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id); collector.OfCategory(BuiltInCategory.OST_TitleBlocks).OfClass(typeof(FamilyInstance)); //get the built in parameter parameters of titleblock in view. foreach (FamilyInstance tbk in collector) { familyInstance = tbk; //titleblock information FamilySymbol familySymbol = tbk.Symbol; string familyTypeName = familySymbol.Name; Family family = familySymbol.Family; familyName = family.Name; } } class SchemaAndStoreData { //X values of cell private string titleblockName = ""; private string cellSizeDistance_X = ""; private string lowerGap_X = ""; private string additionalEdge_X = ""; private string fineTune_X = ""; //Y values of cell private string cellSizeDistance_Y = ""; private string lowerGap_Y = ""; private string additionalEdge_Y = ""; private string fineTune_Y = ""; //Size of grid in sheet private string cellGrid = ""; // Create a data structure, attach it to a wall, populate it with data, and retrieve the data back from the wall public void CreateSchemeAndStoreData(FamilyInstance titleblock) { SchemaBuilder schemaBuilder = new SchemaBuilder(new Guid("1a68d420-96dd-44aa-a1de-000774a6104b")); schemaBuilder.SetReadAccessLevel(AccessLevel.Public); // allow anyone to read the object schemaBuilder.SetSchemaName("TitleBlockSettings"); // create a field to store data FieldBuilder fieldBuilder_titleblockName = schemaBuilder.AddSimpleField("titleblockName", typeof(string)); FieldBuilder fieldBuilder_cellSizeDistance_X = schemaBuilder.AddSimpleField("cellSizeDistance_X", typeof(string)); FieldBuilder fieldBuilder_lowerGap_X = schemaBuilder.AddSimpleField("lowerGap_X", typeof(string)); FieldBuilder fieldBuilder_additionalEdge_X = schemaBuilder.AddSimpleField("additionalEdge_X", typeof(string)); FieldBuilder fieldBuilder_fineTune_X = schemaBuilder.AddSimpleField("fineTune_X", typeof(string)); FieldBuilder fieldBuilder_cellSizeDistance_Y = schemaBuilder.AddSimpleField("cellSizeDistance_Y", typeof(string)); FieldBuilder fieldBuilder_lowerGap_Y = schemaBuilder.AddSimpleField("lowerGap_Y", typeof(string)); FieldBuilder fieldBuilder_additionalEdge_Y = schemaBuilder.AddSimpleField("additionalEdge_Y", typeof(string)); FieldBuilder fieldBuilder_fineTune_Y = schemaBuilder.AddSimpleField("fineTune_Y", typeof(string)); FieldBuilder fieldBuilder_cellGrid = schemaBuilder.AddSimpleField("cellGrid", typeof(string)); //fieldBuilder.SetDocumentation("store length of cell size in X direction."); Schema schema = schemaBuilder.Finish(); // register the Schema object } public void RetrieveData(FamilyInstance titleblock) { string[] objects = new string[9]; Schema schema = Schema.Lookup(new Guid("1a68d420-96dd-44aa-a1de-000774a6104b")); // get the field from the schema Field field_titleblockName = schema.GetField("titleblockName"); Field field_cellSizeDistance_X = schema.GetField("cellSizeDistance_X"); Field field_lowerGap_X = schema.GetField("lowerGap_X"); Field field_additionalEdge_X = schema.GetField("additionalEdge_X"); Field field_fineTune_X = schema.GetField("fineTune_X"); Field field_cellSizeDistance_Y = schema.GetField("cellSizeDistance_Y"); Field field_lowerGap_Y = schema.GetField("lowerGap_Y"); Field field_additionalEdge_Y = schema.GetField("additionalEdge_Y"); Field field_fineTune_Y = schema.GetField("fineTune_Y"); Field field_cellGrid = schema.GetField("cellGrid"); // get the data back from the titleblock Entity retrievedEntity = titleblock.GetEntity(schema); string retrievedData_titleblockName = retrievedEntity.Get<string>(schema.GetField("titleblockName")); string retrievedData_cellSizeDistance_X = retrievedEntity.Get<string>(schema.GetField("cellSizeDistance_X")); string retrievedData_lowerGap_X = retrievedEntity.Get<string>(schema.GetField("lowerGap_X")); string retrievedData_additionalEdge_X = retrievedEntity.Get<string>(schema.GetField("additionalEdge_X")); string retrievedData_fineTune_X = retrievedEntity.Get<string>(schema.GetField("fineTune_X")); string retrievedData_cellSizeDistance_Y = retrievedEntity.Get<string>(schema.GetField("cellSizeDistance_Y")); string retrievedData_lowerGap_Y = retrievedEntity.Get<string>(schema.GetField("lowerGap_Y")); string retrievedData_additionalEdge_Y = retrievedEntity.Get<string>(schema.GetField("additionalEdge_Y")); string retrievedData_fineTune_Y = retrievedEntity.Get<string>(schema.GetField("fineTune_Y")); string retrievedData_cellGrid = retrievedEntity.Get<string>(schema.GetField("cellGrid")); titleblockName = retrievedData_titleblockName; cellSizeDistance_X = retrievedData_cellSizeDistance_X; lowerGap_X = retrievedData_lowerGap_X; additionalEdge_X = retrievedData_additionalEdge_X; fineTune_X = retrievedData_fineTune_X; cellSizeDistance_Y = retrievedData_cellSizeDistance_Y; lowerGap_Y = retrievedData_lowerGap_Y; additionalEdge_Y = retrievedData_additionalEdge_Y; fineTune_Y = retrievedData_fineTune_Y; cellGrid = retrievedData_cellGrid; } public void StoreData(FamilyInstance titleblock) { Schema schema = Schema.Lookup(new Guid("1a68d420-96dd-44aa-a1de-000774a6104b")); Entity entity = new Entity(schema); Field field_titleblockName = schema.GetField("titleblockName"); Field field_cellSizeDistance_X = schema.GetField("cellSizeDistance_X"); Field field_lowerGap_X = schema.GetField("lowerGap_X"); Field field_additionalEdge_X = schema.GetField("additionalEdge_X"); Field field_fineTune_X = schema.GetField("fineTune_X"); Field field_cellSizeDistance_Y = schema.GetField("cellSizeDistance_Y"); Field field_lowerGap_Y = schema.GetField("lowerGap_Y"); Field field_additionalEdge_Y = schema.GetField("additionalEdge_Y"); Field field_fineTune_Y = schema.GetField("fineTune_Y"); Field field_cellGrid = schema.GetField("cellGrid"); entity.Set<string>(field_titleblockName, titleblockName); entity.Set<string>(field_cellSizeDistance_X, cellSizeDistance_X); entity.Set<string>(field_lowerGap_X, lowerGap_X); entity.Set<string>(field_additionalEdge_X, additionalEdge_X); entity.Set<string>(field_fineTune_X, fineTune_X); entity.Set<string>(field_cellSizeDistance_Y, cellSizeDistance_Y); entity.Set<string>(field_lowerGap_Y, lowerGap_Y); entity.Set<string>(field_additionalEdge_Y, additionalEdge_Y); entity.Set<string>(field_fineTune_Y, fineTune_Y); entity.Set<string>(field_cellGrid, cellGrid); titleblock.SetEntity(entity); // store the entity in the element }
Solved! Go to Solution.
Link copied