Skip to content

Commit

Permalink
removed deprecated API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremytammik committed Apr 19, 2021
1 parent 0abf6e6 commit 5230505
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 116 deletions.
23 changes: 12 additions & 11 deletions BuildingCoder/BuildingCoder/CmdCategories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ CategoryNameMap subcats
#endregion // HideLightingFixtureHosts

#region ProblemAddingParameterBindingForCategory
static Util.SpellingErrorCorrector
_spellingErrorCorrector = null;
//static Util.SpellingErrorCorrector
// _spellingErrorCorrector = null;

void ProblemAddingParameterBindingForCategory(
Document doc )
{
Application app = doc.Application;

if( null == _spellingErrorCorrector )
{
_spellingErrorCorrector
= new Util.SpellingErrorCorrector( app );
}
//if( null == _spellingErrorCorrector )
//{
// _spellingErrorCorrector
// = new Util.SpellingErrorCorrector( app );
//}

DefinitionFile sharedParametersFile
= app.OpenSharedParameterFile();
Expand All @@ -89,11 +89,12 @@ ExternalDefinitionCreationOptions opt // 2022
// To handle both ExternalDefinitonCreationOptions
// and ExternalDefinitionCreationOptions:

def = _spellingErrorCorrector.NewDefinition(
group.Definitions, "ReinforcementParameter",
ParameterType.Text );
//def = _spellingErrorCorrector.NewDefinition(
// group.Definitions, "ReinforcementParameter",
// //ParameterType.Text // 2021
// SpecTypeId.String.Text ); // 2022

List<BuiltInCategory> bics
List <BuiltInCategory> bics
= new List<BuiltInCategory>();

//bics.Add(BuiltInCategory.OST_AreaRein);
Expand Down
2 changes: 1 addition & 1 deletion BuildingCoder/BuildingCoder/CmdCollectorPerformance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ Element projInfoElem
ParameterValueProvider provider
= new ParameterValueProvider( paraId );

FilterRule rule = new FilterStringRule(
FilterRule rule = new FilterStringRule( // 2021
provider, new FilterStringEquals(),
paramValue, true );

Expand Down
3 changes: 2 additions & 1 deletion BuildingCoder/BuildingCoder/CmdCreateSharedParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class CmdCreateSharedParams : IExternalCommand
const string _filename = "C:/tmp/SharedParams.txt";
const string _groupname = "The Building Coder Parameters";
const string _defname = "SP";
ParameterType _deftype = ParameterType.Number;
//ParameterType _deftype = ParameterType.Number; // 2021
ForgeTypeId _deftype = SpecTypeId.Number; // 2022

// What element types are we interested in? The standard
// SDK FireRating sample uses BuiltInCategory.OST_Doors.
Expand Down
3 changes: 2 additions & 1 deletion BuildingCoder/BuildingCoder/CmdGetMaterials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@ public Material GetMaterial(

if( p.StorageType == StorageType.ElementId
&& def.ParameterGroup == BuiltInParameterGroup.PG_MATERIALS
&& def.ParameterType == ParameterType.Material )
//&& def.ParameterType == ParameterType.Material // 2021)
&& def.GetDataType() == SpecTypeId.Reference.Material ) // 2022
{
ElementId materialId = p.AsElementId();

Expand Down
4 changes: 3 additions & 1 deletion BuildingCoder/BuildingCoder/CmdNewDimensionLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ FamilyParameter familyParam
= doc.FamilyManager.AddParameter(
"length",
BuiltInParameterGroup.PG_IDENTITY_DATA,
ParameterType.Length, false );
ParameterType.Length, // 2021
//SpecTypeId.Length, // 2022
false );

//dim.Label = familyParam; // 2013
dim.FamilyLabel = familyParam; // 2014
Expand Down
6 changes: 4 additions & 2 deletions BuildingCoder/BuildingCoder/CmdSetTagType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ public void SetTagColorToElementColor( UIDocument uiDoc )
foreach( var e in tags )
{
IndependentTag tag = doc.GetElement( e.Id ) as IndependentTag;
Element taggedElem = tag.GetTaggedLocalElement();
taggedElements.Add( taggedElem );
//Element taggedElem = tag.GetTaggedLocalElement(); // 2021
//taggedElements.Add( taggedElem );
ICollection<Element> taggedElems = tag.GetTaggedLocalElements(); // 2022
taggedElements.AddRange( taggedElems );
}

//get the color of the ductsystem
Expand Down
199 changes: 100 additions & 99 deletions BuildingCoder/BuildingCoder/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,8 @@ public static void ListForgeTypeIds()
}
}

IList<ForgeTypeId> specs = UnitUtils.GetAllSpecs();
//IList<ForgeTypeId> specs = UnitUtils.GetAllSpecs(); // 2021
IList<ForgeTypeId> specs = UnitUtils.GetAllMeasurableSpecs(); // 2022

Debug.Print( "{0} specs:", specs.Count );

Expand Down Expand Up @@ -2288,63 +2289,63 @@ void GenerateAddInManifest(
}
#endregion // Generate add-in manifest on the fly

#region Compatibility fix for spelling error change
/// <summary>
/// Wrapper to fix a spelling error prior to Revit 2016.
/// </summary>
public class SpellingErrorCorrector
{
static bool _in_revit_2015_or_earlier;
static Type _external_definition_creation_options_type;

public SpellingErrorCorrector( Application app )
{
_in_revit_2015_or_earlier = 0
<= app.VersionNumber.CompareTo( "2015" );

string s
= _in_revit_2015_or_earlier
? "ExternalDefinitonCreationOptions"
: "ExternalDefinitionCreationOptions";

_external_definition_creation_options_type
= System.Reflection.Assembly
.GetExecutingAssembly().GetType( s );
}

object NewExternalDefinitionCreationOptions(
string name,
ParameterType parameterType )
{
object[] args = new object[] {
name, parameterType };

return _external_definition_creation_options_type
.GetConstructor( new Type[] {
_external_definition_creation_options_type } )
.Invoke( args );
}

public Definition NewDefinition(
Definitions definitions,
string name,
ParameterType parameterType )
{
//return definitions.Create(
// NewExternalDefinitionCreationOptions() );

object opt
= NewExternalDefinitionCreationOptions(
name,
parameterType );

return typeof( Definitions ).InvokeMember(
"Create", BindingFlags.InvokeMethod, null,
definitions, new object[] { opt } )
as Definition;
}
}
#endregion // Compatibility fix for spelling error change
//#region Compatibility fix for spelling error change
///// <summary>
///// Wrapper to fix a spelling error prior to Revit 2016.
///// </summary>
//public class SpellingErrorCorrector
//{
// static bool _in_revit_2015_or_earlier;
// static Type _external_definition_creation_options_type;

// public SpellingErrorCorrector( Application app )
// {
// _in_revit_2015_or_earlier = 0
// <= app.VersionNumber.CompareTo( "2015" );

// string s
// = _in_revit_2015_or_earlier
// ? "ExternalDefinitonCreationOptions"
// : "ExternalDefinitionCreationOptions";

// _external_definition_creation_options_type
// = System.Reflection.Assembly
// .GetExecutingAssembly().GetType( s );
// }

// object NewExternalDefinitionCreationOptions(
// string name,
// ParameterType parameterType )
// {
// object[] args = new object[] {
// name, parameterType };

// return _external_definition_creation_options_type
// .GetConstructor( new Type[] {
// _external_definition_creation_options_type } )
// .Invoke( args );
// }

// public Definition NewDefinition(
// Definitions definitions,
// string name,
// ParameterType parameterType )
// {
// //return definitions.Create(
// // NewExternalDefinitionCreationOptions() );

// object opt
// = NewExternalDefinitionCreationOptions(
// name,
// parameterType );

// return typeof( Definitions ).InvokeMember(
// "Create", BindingFlags.InvokeMethod, null,
// definitions, new object[] { opt } )
// as Definition;
// }
//}
//#endregion // Compatibility fix for spelling error change
}

#region Extension Method Classes
Expand Down Expand Up @@ -2813,47 +2814,47 @@ public static XYZ GetPoint2(
}
#endregion // Autodesk.Revit.DB.Curve

#region Autodesk.Revit.DB.Definitions
public static Definition Create2(
this Definitions definitions,
Document doc,
string nome,
ParameterType tipo,
bool visibilidade )
{
// Does this need updating to check for
// ExternalDefinitionCreationOptions with
// the additional 'i' in Revit 2016?

Definition value = null;
List<Type> ls = doc.GetType().Assembly
.GetTypes().Where( a => a.IsClass && a
.Name == "ExternalDefinitonCreationOptions" ).ToList();
if( ls.Count > 0 )
{
Type t = ls[ 0 ];
ConstructorInfo c = t
.GetConstructor( new Type[] { typeof(string),
typeof(ParameterType) } );
object ed = c
.Invoke( new object[] { nome, tipo } );
ed.GetType().GetProperty( "Visible" )
.SetValue( ed, visibilidade, null );
value = definitions.GetType()
.GetMethod( "Create", new Type[] { t } ).Invoke( definitions,
new object[] { ed } ) as Definition;
}
else
{
value = definitions.GetType()
.GetMethod( "Create", new Type[] { typeof(string),
typeof(ParameterType), typeof(bool) } ).Invoke( definitions,
new object[] { nome, tipo,
visibilidade } ) as Definition;
}
return value;
}
#endregion // Autodesk.Revit.DB.Definitions
//#region Autodesk.Revit.DB.Definitions
//public static Definition Create2(
// this Definitions definitions,
// Document doc,
// string nome,
// ParameterType tipo,
// bool visibilidade )
//{
// // Does this need updating to check for
// // ExternalDefinitionCreationOptions with
// // the additional 'i' in Revit 2016?

// Definition value = null;
// List<Type> ls = doc.GetType().Assembly
// .GetTypes().Where( a => a.IsClass && a
// .Name == "ExternalDefinitonCreationOptions" ).ToList();
// if( ls.Count > 0 )
// {
// Type t = ls[ 0 ];
// ConstructorInfo c = t
// .GetConstructor( new Type[] { typeof(string),
// typeof(ParameterType) } );
// object ed = c
// .Invoke( new object[] { nome, tipo } );
// ed.GetType().GetProperty( "Visible" )
// .SetValue( ed, visibilidade, null );
// value = definitions.GetType()
// .GetMethod( "Create", new Type[] { t } ).Invoke( definitions,
// new object[] { ed } ) as Definition;
// }
// else
// {
// value = definitions.GetType()
// .GetMethod( "Create", new Type[] { typeof(string),
// typeof(ParameterType), typeof(bool) } ).Invoke( definitions,
// new object[] { nome, tipo,
// visibilidade } ) as Definition;
// }
// return value;
//}
//#endregion // Autodesk.Revit.DB.Definitions

#region Autodesk.Revit.DB.Document
public static Element GetElement2(
Expand Down

0 comments on commit 5230505

Please sign in to comment.