replaced Revit 2020 SDK by Revit 2021 SDK

This commit is contained in:
Jeremy Tammik
2020-05-11 14:07:56 +02:00
parent 06ba6e0541
commit 64f8b0ed3e
250 changed files with 1225 additions and 1496 deletions
@@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ExtensibleStorageManager</RootNamespace>
<AssemblyName>ExtensibleStorageManager</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
@@ -111,12 +111,12 @@ namespace ExtensibleStorageManager
private static void SimpleSchemaAndData(SchemaWrapperTools.SchemaWrapper mySchemaWrapper, out Entity storageElementEntityWrite)
{
//Create some sample fields.
mySchemaWrapper.AddField<int>(int0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<short>(short0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<double>(double0Name, UnitType.UT_Length, null);
mySchemaWrapper.AddField<float>(float0Name, UnitType.UT_Length, null);
mySchemaWrapper.AddField<bool>(bool0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<string>(string0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<int>(int0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<short>(short0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<double>(double0Name, SpecTypeId.Length, null);
mySchemaWrapper.AddField<float>(float0Name, SpecTypeId.Length, null);
mySchemaWrapper.AddField<bool>(bool0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<string>(string0Name, new ForgeTypeId(), null);
//Generate the Autodesk.Revit.DB.ExtensibleStorage.Schema.
mySchemaWrapper.FinishSchema();
@@ -137,8 +137,8 @@ namespace ExtensibleStorageManager
//Set data in the entity.
storageElementEntityWrite.Set<int>(fieldInt0, 5);
storageElementEntityWrite.Set<short>(fieldShort0, 2);
storageElementEntityWrite.Set<double>(fieldDouble0, 7.1, DisplayUnitType.DUT_METERS);
storageElementEntityWrite.Set<float>(fieldFloat0, 3.1f, DisplayUnitType.DUT_METERS);
storageElementEntityWrite.Set<double>(fieldDouble0, 7.1, UnitTypeId.Meters);
storageElementEntityWrite.Set<float>(fieldFloat0, 3.1f, UnitTypeId.Meters);
storageElementEntityWrite.Set(fieldBool0, false);
storageElementEntityWrite.Set(fieldString0, "hello");
@@ -152,35 +152,35 @@ namespace ExtensibleStorageManager
private static void ComplexSchemaAndData(SchemaWrapperTools.SchemaWrapper mySchemaWrapper, Element storageElement, string xmlPathOut, Guid schemaId, AccessLevel readAccess, AccessLevel writeAccess, string vendorId, string applicationId, string name, string documentation, out Entity storageElementEntityWrite)
{
#region Add Fields to the SchemaWrapper
mySchemaWrapper.AddField<int>(int0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<short>(short0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<double>(double0Name, UnitType.UT_Length, null);
mySchemaWrapper.AddField<float>(float0Name, UnitType.UT_Length, null);
mySchemaWrapper.AddField<bool>(bool0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<string>(string0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<ElementId>(id0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<XYZ>(point0Name, UnitType.UT_Length, null);
mySchemaWrapper.AddField<UV>(uv0Name, UnitType.UT_Length, null);
mySchemaWrapper.AddField<Guid>(guid0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<int>(int0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<short>(short0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<double>(double0Name, SpecTypeId.Length, null);
mySchemaWrapper.AddField<float>(float0Name, SpecTypeId.Length, null);
mySchemaWrapper.AddField<bool>(bool0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<string>(string0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<ElementId>(id0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<XYZ>(point0Name, SpecTypeId.Length, null);
mySchemaWrapper.AddField<UV>(uv0Name, SpecTypeId.Length, null);
mySchemaWrapper.AddField<Guid>(guid0Name, new ForgeTypeId(), null);
//Note that we use IDictionary<> for map types and IList<> for array types
mySchemaWrapper.AddField<IDictionary<string, string>>(map0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<IList<bool>>(array0Name, UnitType.UT_Undefined, null);
mySchemaWrapper.AddField<IDictionary<string, string>>(map0Name, new ForgeTypeId(), null);
mySchemaWrapper.AddField<IList<bool>>(array0Name, new ForgeTypeId(), null);
//Create a sample subEntity
SchemaWrapperTools.SchemaWrapper mySubSchemaWrapper0 = SchemaWrapperTools.SchemaWrapper.NewSchema(subEntityGuid0, readAccess, writeAccess, vendorId, applicationId, entity0Name, "A sub entity");
mySubSchemaWrapper0.AddField<int>("subInt0", UnitType.UT_Undefined, null);
mySubSchemaWrapper0.AddField<int>("subInt0", new ForgeTypeId(), null);
mySubSchemaWrapper0.FinishSchema();
Entity subEnt0 = new Entity(mySubSchemaWrapper0.GetSchema());
subEnt0.Set<int>(mySubSchemaWrapper0.GetSchema().GetField("subInt0"), 11);
mySchemaWrapper.AddField<Entity>(entity0Name, UnitType.UT_Undefined, mySubSchemaWrapper0);
mySchemaWrapper.AddField<Entity>(entity0Name, new ForgeTypeId(), mySubSchemaWrapper0);
//
//Create a sample map of subEntities (An IDictionary<> with key type "int" and value type "Entity")
//
//Create a new sample schema.
SchemaWrapperTools.SchemaWrapper mySubSchemaWrapper1_Map = SchemaWrapperTools.SchemaWrapper.NewSchema(subEntityGuid_Map1, readAccess, writeAccess, vendorId, applicationId, map1Name, "A map of int to Entity");
mySubSchemaWrapper1_Map.AddField<int>("subInt1", UnitType.UT_Undefined, null);
mySubSchemaWrapper1_Map.AddField<int>("subInt1", new ForgeTypeId(), null);
mySubSchemaWrapper1_Map.FinishSchema();
//Create a new sample Entity.
Entity subEnt1 = new Entity(mySubSchemaWrapper1_Map.GetSchema());
@@ -188,7 +188,7 @@ namespace ExtensibleStorageManager
subEnt1.Set<int>(mySubSchemaWrapper1_Map.GetSchema().GetField("subInt1"), 22);
//Add a new map field to the top-level Schema. We will add the entity we just created after all top-level
//fields are created.
mySchemaWrapper.AddField<IDictionary<int, Entity>>(map1Name, UnitType.UT_Undefined, mySubSchemaWrapper1_Map);
mySchemaWrapper.AddField<IDictionary<int, Entity>>(map1Name, new ForgeTypeId(), mySubSchemaWrapper1_Map);
@@ -198,7 +198,7 @@ namespace ExtensibleStorageManager
//
//Create a new sample schema
SchemaWrapperTools.SchemaWrapper mySubSchemaWrapper2_Array = SchemaWrapperTools.SchemaWrapper.NewSchema(subEntityGuid_Array2, readAccess, writeAccess, vendorId, applicationId, array1Name, "An array of Entities");
mySubSchemaWrapper2_Array.AddField<int>("subInt2", UnitType.UT_Undefined, null);
mySubSchemaWrapper2_Array.AddField<int>("subInt2", new ForgeTypeId(), null);
mySubSchemaWrapper2_Array.FinishSchema();
//Create a new sample Entity.
Entity subEnt2 = new Entity(mySubSchemaWrapper2_Array.GetSchema());
@@ -206,7 +206,7 @@ namespace ExtensibleStorageManager
subEnt2.Set<int>(mySubSchemaWrapper2_Array.GetSchema().GetField("subInt2"), 33);
//Add a new array field to the top-level Schema We will add the entity we just crated after all top-level fields
//are created.
mySchemaWrapper.AddField<IList<Entity>>(array1Name, UnitType.UT_Undefined, mySubSchemaWrapper2_Array);
mySchemaWrapper.AddField<IList<Entity>>(array1Name, new ForgeTypeId(), mySubSchemaWrapper2_Array);
#endregion
@@ -251,15 +251,15 @@ namespace ExtensibleStorageManager
storageElementEntityWrite.Set<int>(fieldInt0, 5);
storageElementEntityWrite.Set<short>(fieldShort0, 2);
storageElementEntityWrite.Set<double>(fieldDouble0, 7.1, DisplayUnitType.DUT_METERS);
storageElementEntityWrite.Set<float>(fieldFloat0, 3.1f, DisplayUnitType.DUT_METERS);
storageElementEntityWrite.Set<double>(fieldDouble0, 7.1, UnitTypeId.Meters);
storageElementEntityWrite.Set<float>(fieldFloat0, 3.1f, UnitTypeId.Meters);
storageElementEntityWrite.Set(fieldBool0, false);
storageElementEntityWrite.Set(fieldString0, "hello");
storageElementEntityWrite.Set(fieldId0, storageElement.Id);
storageElementEntityWrite.Set(fieldPoint0, new XYZ(1, 2, 3), DisplayUnitType.DUT_METERS);
storageElementEntityWrite.Set(fieldUv0, new UV(1, 2), DisplayUnitType.DUT_METERS);
storageElementEntityWrite.Set(fieldPoint0, new XYZ(1, 2, 3), UnitTypeId.Meters);
storageElementEntityWrite.Set(fieldUv0, new UV(1, 2), UnitTypeId.Meters);
storageElementEntityWrite.Set(fieldGuid0, new Guid("D8301329-F207-43B8-8AA1-634FD344F350"));
//Note that we must pass an IDictionary<>, not a Dictionary<> to Set().
@@ -361,8 +361,8 @@ namespace ExtensibleStorageManager
storageElementEntityWrite.Set<int>(fieldInt0, 10);
storageElementEntityWrite.Set<short>(fieldShort0, 20);
storageElementEntityWrite.Set<double>(fieldDouble0, 14.2, DisplayUnitType.DUT_METERS);
storageElementEntityWrite.Set<float>(fieldFloat0, 6.12f, DisplayUnitType.DUT_METERS);
storageElementEntityWrite.Set<double>(fieldDouble0, 14.2, UnitTypeId.Meters);
storageElementEntityWrite.Set<float>(fieldFloat0, 6.12f, UnitTypeId.Meters);
storageElementEntityWrite.Set(fieldBool0, true);
storageElementEntityWrite.Set(fieldString0, "goodbye");
//Set the entity back into the storage element.
@@ -52,8 +52,8 @@ namespace SchemaWrapperTools
/// </summary>
/// <param name="name">The name of the field</param>
/// <param name="typeIn">The AssemblyQualifiedName of the Field's data type</param>
/// <param name="unit">The unit type of the Field (set to UT_Undefined for non-floating point types</param>
public FieldData(string name, string typeIn, UnitType unit) : this(name, typeIn, unit, null)
/// <param name="spec">The unit type of the Field (set to UT_Undefined for non-floating point types</param>
public FieldData(string name, string typeIn, ForgeTypeId spec) : this(name, typeIn, spec, null)
{
}
@@ -63,13 +63,13 @@ namespace SchemaWrapperTools
/// </summary>
/// <param name="name">The name of the field</param>
/// <param name="typeIn">The AssemblyQualifiedName of the Field's data type</param>
/// <param name="unit">The unit type of the Field (set to UT_Undefined for non-floating point types</param>
/// <param name="spec">The unit type of the Field (set to UT_Undefined for non-floating point types</param>
/// <param name="subSchema">The SchemaWrapper of the field's subSchema, if the field is of type "Entity"</param>
public FieldData(string name, string typeIn, UnitType unit, SchemaWrapper subSchema)
public FieldData(string name, string typeIn, ForgeTypeId spec, SchemaWrapper subSchema)
{
m_Name = name;
m_Type = typeIn;
m_Unit = unit;
m_Spec = spec;
m_SubSchema = subSchema;
}
#endregion
@@ -83,7 +83,7 @@ namespace SchemaWrapperTools
strBuilder.Append(", ");
strBuilder.Append(Type);
strBuilder.Append(", ");
strBuilder.Append(Unit.ToString());
strBuilder.Append(Spec.TypeId);
if (SubSchema != null)
@@ -116,10 +116,10 @@ namespace SchemaWrapperTools
/// <summary>
/// The Unit type of the field
/// </summary>
public UnitType Unit
public ForgeTypeId Spec
{
get { return m_Unit; }
set { m_Unit = value; }
get { return m_Spec; }
set { m_Spec = value; }
}
/// <summary>
@@ -136,7 +136,7 @@ namespace SchemaWrapperTools
private SchemaWrapper m_SubSchema;
private string m_Name;
private string m_Type;
private UnitType m_Unit;
private ForgeTypeId m_Spec;
#endregion
}
@@ -76,11 +76,11 @@ namespace SchemaWrapperTools
/// </summary>
/// <param name="name">the name of the field</param>
/// <param name="typeIn">the data type of the field</param>
/// <param name="unit">The unit type of the Field (set to UT_Undefined for non-floating point types</param>
/// <param name="spec">The unit type of the Field (set to UT_Undefined for non-floating point types</param>
/// <param name="subSchema">The SchemaWrapper of the field's subSchema, if the field is of type "Entity"</param>
public void AddData(string name, System.Type typeIn, UnitType unit, SchemaWrapper subSchema)
public void AddData(string name, System.Type typeIn, ForgeTypeId spec, SchemaWrapper subSchema)
{
m_DataList.Add(new FieldData(name, typeIn.FullName, unit, subSchema));
m_DataList.Add(new FieldData(name, typeIn.FullName, spec, subSchema));
}
#endregion
@@ -65,7 +65,7 @@ namespace SchemaWrapperTools
//then query the field data types from the field and instantiate a new generic method with those types as parameters.
//Get the "AddField" method.
MethodInfo addFieldmethod = typeof(SchemaWrapper).GetMethod("AddField", new Type[] { typeof(string), typeof(UnitType), typeof(SchemaWrapper) });
MethodInfo addFieldmethod = typeof(SchemaWrapper).GetMethod("AddField", new Type[] { typeof(string), typeof(ForgeTypeId), typeof(SchemaWrapper) });
Type[] methodGenericParameters = null;
//Get the generic type parameters. The type will either be a single type, an IList<> of a single type, or an IDictionary<> of a key type and a value type.
@@ -87,7 +87,7 @@ namespace SchemaWrapperTools
swSub = SchemaWrapper.FromSchema(subSchema);
}
//Invoke the "AddField" method with the generic parameters from the current field.
genericAddFieldMethodInstantiated.Invoke(swReturn, new object[] { currentField.FieldName, currentField.UnitType, swSub });
genericAddFieldMethodInstantiated.Invoke(swReturn, new object[] { currentField.FieldName, currentField.GetSpecTypeId(), swSub });
}
//Note that we don't call SchemaWrapper.FinishSchema here.
//The Autodesk.Revit.DB.ExtensibleStorage.Schema object already exists and is registered -- we're just populating the outer wrapper.
@@ -161,11 +161,11 @@ namespace SchemaWrapperTools
/// </summary>
/// <typeparam name="TypeName">Currently supported types: int, short, float, double, bool, string, ElementId, XYZ, UV, Guid, Entity, IDictionary<>, IList<>. IDictionary<> does not support floating point types, XYZ, UV, or Entity as Key parameters.</typeparam>
/// <param name="name">The name of the field</param>
/// <param name="unit">The unit type of the field. Defintion required for floating point, XYZ, and UV types</param>
/// <param name="spec">The unit type of the field. Defintion required for floating point, XYZ, and UV types</param>
/// <param name="subSchema">A subSchemaWrapper, if the field is of type Entity</param>
public void AddField<TypeName>(string name, UnitType unit, SchemaWrapper subSchema)
public void AddField<TypeName>(string name, ForgeTypeId spec, SchemaWrapper subSchema)
{
m_SchemaDataWrapper.AddData(name, typeof(TypeName), unit, subSchema);
m_SchemaDataWrapper.AddData(name, typeof(TypeName), spec, subSchema);
}
/// <summary>
@@ -254,8 +254,8 @@ namespace SchemaWrapperTools
currentFieldData.SubSchema.FinishSchema(); //Recursively create the schema for the subSchema.
}
if (currentFieldData.Unit != UnitType.UT_Undefined)
currentFieldBuilder.SetUnitType(currentFieldData.Unit);
if (!currentFieldData.Spec.Empty())
currentFieldBuilder.SetSpec(currentFieldData.Spec);
}
//Set all the top level data in the schema we are generating.
@@ -373,7 +373,7 @@ namespace SchemaWrapperTools
{
string fieldName = field.FieldName;
System.Type fieldType = field.ValueType;
UnitType fieldUnit = field.UnitType;
ForgeTypeId fieldUnit = field.GetSpecTypeId();
ContainerType fieldContainerType = field.ContainerType;
Type[] methodGenericParameters = null;
object[] invokeParams = null;
@@ -385,15 +385,15 @@ namespace SchemaWrapperTools
else //map
methodGenericParameters = new Type[] { typeof(IDictionary<int, int>).GetGenericTypeDefinition().MakeGenericType(new Type[] { field.KeyType, field.ValueType }) };
if (fieldUnit == UnitType.UT_Undefined)
if (fieldUnit.Empty())
{
methodOverloadSelectionParams = new Type[] { typeof(Field) };
invokeParams = new object[] { field };
}
else
{
methodOverloadSelectionParams = new Type[] { typeof(Field), typeof(DisplayUnitType) };
invokeParams = new object[] { field, DisplayUnitType.DUT_METERS };
methodOverloadSelectionParams = new Type[] { typeof(Field), typeof(ForgeTypeId) };
invokeParams = new object[] { field, UnitTypeId.Meters };
}
MethodInfo instantiatedGenericGetMethod = entity.GetType().GetMethod("Get", methodOverloadSelectionParams).MakeGenericMethod(methodGenericParameters);
@@ -403,13 +403,13 @@ namespace SchemaWrapperTools
if (fieldType == typeof(Entity))
{
Schema subSchema = Schema.Lookup(field.SubSchemaGUID);
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.UnitType.ToString() + ", ContainerType: " + field.ContainerType.ToString());
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
DumpAllSchemaEntityData<FieldType>(retval, subSchema, strBuilder);
}
else
{
string sRetval = retval.ToString();
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + retval + ", Unit: " + field.UnitType.ToString() + ", ContainerType: " + field.ContainerType.ToString());
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + retval + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
}
}
else if (field.ContainerType == ContainerType.Array)
@@ -417,7 +417,7 @@ namespace SchemaWrapperTools
IList<FieldType> listRetval = (IList<FieldType>)instantiatedGenericGetMethod.Invoke(entity, invokeParams);
if (fieldType == (typeof(Entity)))
{
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.UnitType.ToString() + ", ContainerType: " + field.ContainerType.ToString());
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
foreach (FieldType fa in listRetval)
{
@@ -427,7 +427,7 @@ namespace SchemaWrapperTools
}
else
{
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Array} " + ", Unit: " + field.UnitType.ToString() + ", ContainerType: " + field.ContainerType.ToString());
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Array} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
foreach (FieldType fa in listRetval)
{
strBuilder.AppendLine(" Array value: " + fa.ToString());
@@ -436,11 +436,11 @@ namespace SchemaWrapperTools
}
else //Map
{
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Map} " + ", Unit: " + field.UnitType.ToString() + ", ContainerType: " + field.ContainerType.ToString());
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Map} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
IDictionary<KeyType, FieldType> mapRetval = (IDictionary<KeyType, FieldType>)instantiatedGenericGetMethod.Invoke(entity, invokeParams);
if (fieldType == (typeof(Entity)))
{
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.UnitType.ToString() + ", ContainerType: " + field.ContainerType.ToString());
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
foreach (FieldType fa in mapRetval.Values)
{
strBuilder.Append(" Map Value: ");
@@ -449,7 +449,7 @@ namespace SchemaWrapperTools
}
else
{
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Map} " + ", Unit: " + field.UnitType.ToString() + ", ContainerType: " + field.ContainerType.ToString());
strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Map} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
foreach (FieldType fa in mapRetval.Values)
{
strBuilder.AppendLine(" Map value: " + fa.ToString());
@@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SchemaWrapperTools</RootNamespace>
<AssemblyName>SchemaWrapperTools</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>