Hi Jeremy, thanks for your reply
Below is what I came up with to create ExtensibleStorage from a listbox
t.Start();
List<string> myList = new List<string>() //<--This list will be fed by a form listbox
{
"item_1",
"item_2",
"item_3",
"item_4",
"item_5"
};
foreach (Conduit conduit in myFilter.myConduits(doc))
{
myXStorage.AddSchemaEntity(myXStorage.mySchema("someName", myList), myList, conduit);
}
t.Commit();
...
public class myXStorage
{
//-----------------------------------------------------------------------------------------
// Build Schema
//-----------------------------------------------------------------------------------------
public static Schema mySchema(string schemaName, List<string> fieldNames)
{
Guid schemaGuid = new Guid($"{myRandomHex(8)}-{myRandomHex(4)}-{myRandomHex(4)}-{myRandomHex(4)}-{myRandomHex(12)}");
SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);
schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
schemaBuilder.SetSchemaName(schemaName); //<--SchemaName
//schemaBuilder.SetDocumentation("Description of this schema"); //<--SchemaDescription
foreach (string item in fieldNames)
{
FieldBuilder fieldBuilder = schemaBuilder.AddSimpleField(item, typeof(string));
}
Schema schema = schemaBuilder.Finish();
return schema;
}
//-----------------------------------------------------------------------------------------
// Attach schema to element
//-----------------------------------------------------------------------------------------
public static void AddSchemaEntity(Schema schema, List<string> fieldNames, Element element)
{
Entity entity = new Entity(schema);
foreach (string item in fieldNames)
{
Field fieldName = schema.GetField(item);//<--FieldName
}
//entity.Set(FieldName1, "Field Value, this is type String");//<--FieldValue, not needed for this application
element.SetEntity(entity);
}
//-----------------------------------------------------------------------------------------
// Create a random hexdecimals
//-----------------------------------------------------------------------------------------
private static Random random = new Random();
private static string myRandomHex(int length)
{
const string hexnums = "ABCDEF123456789";
string randomhex = new string(Enumerable.Repeat(hexnums, length)
.Select(q => q[random.Next(q.Length)]).ToArray());
return randomhex;
}
}
- I noticed that if I filter conduit elements and only retrieve the first index element for the collection, my ExtensibleStorage is only assigned to the first conduit(element)… If this element(conduit) is deleted, so goes the XStorage and its information??? ß is this correct, is gone from the project???
- Also, if I don’t call the first index and assign the XStorage the entire conduit collection, only the conduits that are already created and in the model get this XStorage data but new conduits do not… So future conduit will need to be assigned this XStorage??? ß is this correct?
- If I only assign my XStorage to one conduit, I potensially can loose my XStorage info, if this one conduit is deleted
- If I assign my XStorage to all conduit, I potentially can bloat my model with unnecessary excess XStorage data, when really all I need is one place to house my data and call it as needed?
- Can I create an invisible ‘Element’ or better yet assign it to the application or document object, I only need one constant element that cannot be seen or deleted to house my XStorage? I am thinking to apply the storage to a view, such as the start view or BIMangerView, that should never be deleted… but still can be!!
- When you say, “do not erase and recreate the schema every time” my thoughts where more along the lines of, keeping up with the schemaID number, when I Need to update I find the schemaID, delete it and create the XStorage again, only with a different random GUID and again, keep up with the GUID for next time to update and repeat.
- If I do erase the schema by GUID, is it fully gone?
I have downloaded the PDF and I will read UpgradeSchema on pg11.
Thanks