Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Revit.ES.Extension/Attributes/FieldAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ public class FieldAttribute : Attribute
{
public FieldAttribute()
{
#if FORGETYPEID
SpecTypeId = "";
#else
UnitType = UnitType.UT_Undefined;
#endif
}

public string Documentation { get; set; }
#if FORGETYPEID
public string SpecTypeId { get; set; }
#else
public UnitType UnitType { get; set; }
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public static void SetWrapper<T>(this Entity entity, Field field, IList<T> value
public static void SetWrapper<T>(this Entity entity,
Field field,
IList<T> value,
#if FORGETYPEID
ForgeTypeId displayUnitType)
#else
DisplayUnitType displayUnitType)
#endif
{
entity.Set(field, value, displayUnitType);
}
Expand All @@ -102,7 +106,11 @@ public static void SetWrapper<TKey,TValue>(this Entity entity,
public static void SetWrapper<TKey, TValue>(this Entity entity,
Field field,
IDictionary<TKey, TValue> value,
#if FORGETYPEID
ForgeTypeId displayUnitType)
#else
DisplayUnitType displayUnitType)
#endif
{
entity.Set(field, value, displayUnitType);
}
Expand Down
33 changes: 33 additions & 0 deletions Revit.ES.Extension/EntityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ public Entity Convert(IRevitEntity revitEntity)

propertyValue = ConvertSimpleProperty(propertyValue, field);

#if FORGETYPEID
if (field.GetSpecTypeId().TypeId == "")
#else
if (field.UnitType == UnitType.UT_Undefined)
#endif
{
entity.Set(field, propertyValue);
}
Expand Down Expand Up @@ -110,7 +114,11 @@ public Entity Convert(IRevitEntity revitEntity)
* IList parameter instead FieldType, it works propoerly
*/

#if FORGETYPEID
if (field.GetSpecTypeId().TypeId == "")
#else
if (field.UnitType == UnitType.UT_Undefined)
#endif
{
EntityExtension.SetWrapper(entity, field, convertedIListFieldValue);
}
Expand All @@ -130,7 +138,11 @@ public Entity Convert(IRevitEntity revitEntity)
var convertedMapFieldValue =
ConvertIDictionaryProperty(propertyValue, field);

#if FORGETYPEID
if (field.GetSpecTypeId().TypeId == "")
#else
if (field.UnitType == UnitType.UT_Undefined)
#endif
{
EntityExtension.SetWrapper(entity, field, convertedMapFieldValue);
}
Expand Down Expand Up @@ -575,7 +587,11 @@ private object GetEntityFieldValue(Entity entity,
}

object entityValue;
#if FORGETYPEID
if (field.GetSpecTypeId().TypeId == "")
#else
if (field.UnitType == UnitType.UT_Undefined)
#endif
{
MethodInfo entityGetMethod =
entity
Expand All @@ -594,7 +610,11 @@ private object GetEntityFieldValue(Entity entity,
MethodInfo entityGetMethod =
entity
.GetType()
#if FORGETYPEID
.GetMethod("Get", new[] { typeof(Field), typeof(ForgeTypeId) });
#else
.GetMethod("Get", new[] { typeof(Field), typeof(DisplayUnitType) });
#endif
MethodInfo entityGetMethodGeneric =
entityGetMethod
.MakeGenericMethod(fieldValueType);
Expand All @@ -618,14 +638,27 @@ private object Convert(Type irevitEntityType, Entity entity)
return iRevitEntity;
}

#if FORGETYPEID
private ForgeTypeId GetFirstCompatibleDUT(Field field)
#else
private DisplayUnitType GetFirstCompatibleDUT(Field field)
#endif
{
#if FORGETYPEID
ForgeTypeId forgeTypeId = typeof(UnitTypeId)
.GetProperties()
.Select(q => q.GetValue(null))
.Cast<ForgeTypeId>()
.FirstOrDefault(q => field.CompatibleUnit(q));
return forgeTypeId;
#else
var firstCompatibleDUT = Enum
.GetValues(typeof(DisplayUnitType))
.OfType<DisplayUnitType>()
.FirstOrDefault(field.CompatibleDisplayUnitType);

return firstCompatibleDUT;
#endif
}

}
Expand Down
4 changes: 2 additions & 2 deletions Revit.ES.Extension/Revit.ES.Extension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 2021|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug 2021\</OutputPath>
<DefineConstants>TRACE;DEBUG;REVIT2021</DefineConstants>
<DefineConstants>TRACE;DEBUG;REVIT2021;FORGETYPEID</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand Down Expand Up @@ -179,7 +179,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release 2021|AnyCPU'">
<OutputPath>bin\Release 2021\</OutputPath>
<DefineConstants>TRACE;REVIT2021</DefineConstants>
<DefineConstants>TRACE;REVIT2021;FORGETYPEID</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
6 changes: 5 additions & 1 deletion Revit.ES.Extension/SchemaCreator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 © Victor Chekalin
* Copyright 2012 Victor Chekalin
*
* THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
Expand Down Expand Up @@ -93,7 +93,11 @@ public Schema CreateSchema(Type type)
if (!string.IsNullOrEmpty(fieldAttribute.Documentation))
fieldBuilder.SetDocumentation(fieldAttribute.Documentation);
if (fieldBuilder.NeedsUnits())
#if FORGETYPEID
fieldBuilder.SetSpec(new Autodesk.Revit.DB.ForgeTypeId(fieldAttribute.SpecTypeId));
#else
fieldBuilder.SetUnitType(fieldAttribute.UnitType);
#endif


}
Expand Down
6 changes: 6 additions & 0 deletions Revit.ES.ExtensionTestCommand/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ public Result OnShutdown(UIControlledApplication a)
return Result.Succeeded;
}
}

public static class Utils
{
public const string specTypeIdPrefix = "autodesk.spec.aec";
public const string specTypeIdSuffix = "-2.0.0";
}
}
6 changes: 5 additions & 1 deletion Revit.ES.ExtensionTestCommand/BarEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public class BarEntity : IRevitEntity
[Field(Documentation = "Integer property")]
public int Property2 { get; set; }

[Field(UnitType = UnitType.UT_Piping_Velocity)]
#if FORGETYPEID
[Field(SpecTypeId = Utils.specTypeIdPrefix + ".piping:velocity" + Utils.specTypeIdSuffix)]
#else
[Field(UnitType = UnitType.UT_Piping_Velocity)]
#endif
public double Property3 { get; set; }

[Field]
Expand Down
43 changes: 36 additions & 7 deletions Revit.ES.ExtensionTestCommand/Command2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
intEntity.SomeValue = 777;

// attach to the element
element.SetEntity(intEntity);
using (Transaction t = new Transaction(element.Document, "Set Entity"))
{
t.Start();
element.SetEntity(intEntity);
t.Commit();
}


//read entity
Expand Down Expand Up @@ -73,7 +78,12 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
entity.Set("SomeValue", 888);

// 6. Attach entity to the element
element.SetEntity(entity);
using (Transaction t = new Transaction(element.Document, "Set Entity"))
{
t.Start();
element.SetEntity(entity);
t.Commit();
}

// read

Expand Down Expand Up @@ -122,7 +132,12 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme

entity4.Set("MapField", mapOfEntities);

element.SetEntity(entity4);
using (Transaction t = new Transaction(element.Document, "Set Entity"))
{
t.Start();
element.SetEntity(entity4);
t.Commit();
}


//Change value in map field
Expand All @@ -142,7 +157,12 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
// write changes =
entity10.Set("MapField", mapField);

element.SetEntity(entity10);
using (Transaction t = new Transaction(element.Document, "Set Entity"))
{
t.Start();
element.SetEntity(entity10);
t.Commit();
}
}
}

Expand All @@ -157,8 +177,12 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
{9, new IntEntity(){SomeValue = 9}},
{10, new IntEntity(){SomeValue = 10}}
};

element.SetEntity(complexEntity);
using (Transaction t = new Transaction(element.Document, "Set Entity"))
{
t.Start();
element.SetEntity(complexEntity);
t.Commit();
}

//Change value in map field
var complexEntity2 =
Expand All @@ -171,7 +195,12 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
complexEntity.MapField[9];
entityInMapField.SomeValue = 9898;

element.SetEntity(complexEntity2);
using (Transaction t = new Transaction(element.Document, "Set Entity"))
{
t.Start();
element.SetEntity(complexEntity2);
t.Commit();
}
}
}

Expand Down
Loading