diff --git a/a/1602_place_famil_instance.html b/a/1602_place_famil_instance.html new file mode 100644 index 00000000..f60e6636 --- /dev/null +++ b/a/1602_place_famil_instance.html @@ -0,0 +1,125 @@ +

+ + + + +

+ + +

Migrating PlaceInstances to Revit 2018

+

Migrating a Revit add-in to a new release of the Revit API is generally very easy.

+

The API features slight changes from version to version.

+

Modifications are announced a year or two in advance, and signalled during compilation by deprecated API usage warnings.

+

If you clean up your code every year or two and remove all API usage that causes warning messages, you will normally have very little to do to migrate it later on.

+

If you run into any problems, just search the documentation on What's New in the Revit API; most modifications are listed there, including instructions on how to update the code to handle them:

+ +

As an example, let's look at the migration of +the PlaceInstances add-in implementing text file driven automatic placement of family instances from +Revit 2014 to Revit 2018, prompted +by two comments by +Campbell and Renzo:

+

Question:

+
+

I'm trying to get this to work in Revit 2016; however, FamilySymbolSet was removed in 2016. +Is there a workaround to get the plug in on this page to work without it? +I can get the form to populate with families, but not show the types when I select one...

+

Could you find the solution?

+
+

Answer: Yes, this is easy.

+

The class FamilySymbolSet no longer exists; use a generic collection of element ids instead, in this case, ISet<ElementId>.

+

The property Family.Symbols no longer exists; use GetFamilySymbolIds instead.

+

I first performed a flat migration from the Revit 2014 API to Revit 2018, sinply updating the license year, .NET build target version and Revit API DLL references.

+

That causes the following errors and warnings:

+
+------ Rebuild All started: Project: PlaceInstances, Configuration: Debug Any CPU ------
+
+error CS0246: The type or namespace name 'FamilySymbolSet' could not be found (are you missing a using directive or an assembly reference?)
+
+error CS1061: 'Family' does not contain a definition for 'Symbols' and no extension method 'Symbols' accepting a first argument of type 'Family' could be found (are you missing a using directive or an assembly reference?)
+
+warning CS0162: Unreachable code detected
+========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
+
+ +

The warning message is intentional.

+

The Revit 2014 code causing the two errors looks like this:

+
+  FamilySymbolSet symbols = f.Symbols;
+
+  // I have to convert the FamilySymbolSet to a
+  // List, or the DataSource assignment will throw 
+  // an exception saying "Complex DataBinding 
+  // accepts as a data source either an IList or
+  // an IListSource.
+
+  List<FamilySymbol> symbols2
+    = new List<FamilySymbol>(
+      symbols.Cast<FamilySymbol>() );
+
+ +

I converted it to compile for Revit 2018 like this:

+
+  ISet<ElementId> ids = f.GetFamilySymbolIds();
+
+  Document doc = f.Document;
+
+  List<FamilySymbol> symbols2
+    = new List<FamilySymbol>( 
+      ids.Select<ElementIdFamilySymbol>( id 
+        => doc.GetElement( id ) as FamilySymbol ) );
+
+ +

The update is provided in +the PlaceInstances GitHub repository +in release 2018.0.0.0.

+

You can check out the changes I made in +the diff to the preceding version.

+

For the sake of completeness, here are +the error lists before and after the fix.

+

I hope this helps.

+

+Migration +

\ No newline at end of file diff --git a/a/1602_place_famil_instance.md b/a/1602_place_famil_instance.md new file mode 100644 index 00000000..92b54a67 --- /dev/null +++ b/a/1602_place_famil_instance.md @@ -0,0 +1,143 @@ + + + + + + + + + +### Migrating PlaceInstances to Revit 2018 + +Migrating a Revit add-in to a new release of the Revit API is generally very easy. + +The API features slight changes from version to version. + +Modifications are announced a year or two in advance, and signalled during compilation by deprecated API usage warnings. + +If you clean up your code every year or two and remove all API usage that causes warning messages, you will normally have very little to do to migrate it later on. + +If you run into any problems, just search the documentation on *What's New in the Revit API*; most modifications are listed there, including instructions on how to update the code to handle them: + +- [What's New in the Revit 2010 API](http://thebuildingcoder.typepad.com/blog/2013/02/whats-new-in-the-revit-2010-api.html) +- [What's New in the Revit 2011 API](http://thebuildingcoder.typepad.com/blog/2013/02/whats-new-in-the-revit-2011-api.html) +- [What's New in the Revit 2012 API](http://thebuildingcoder.typepad.com/blog/2013/02/whats-new-in-the-revit-2012-api.html) +- [What's New in the Revit 2013 API](http://thebuildingcoder.typepad.com/blog/2013/03/whats-new-in-the-revit-2013-api.html) +- [What's New in the Revit 2014 API](http://thebuildingcoder.typepad.com/blog/2013/04/whats-new-in-the-revit-2014-api.html) +- [What's New in the Revit 2015 API](http://thebuildingcoder.typepad.com/blog/2014/04/whats-new-in-the-revit-2015-api.html) +- [What's New in the Revit 2016 API](http://thebuildingcoder.typepad.com/blog/2015/04/whats-new-in-the-revit-2016-api.html) +- [What's New in the Revit 2017 API](http://thebuildingcoder.typepad.com/blog/2016/04/whats-new-in-the-revit-2017-api.html) +- [What's New in the Revit 2017.1 API](http://thebuildingcoder.typepad.com/blog/2016/11/whats-new-in-the-revit-20171-api.html) +- [What's New in the Revit 2018 API](http://thebuildingcoder.typepad.com/blog/2017/04/whats-new-in-the-revit-2018-api.html) +- Revit 2018.1 API: + - [Revit 2018.1 and the Visual Materials API](http://thebuildingcoder.typepad.com/blog/2017/08/revit-20181-and-the-visual-materials-api.html) + - [Revit 2018.1.1 API documentation](http://thebuildingcoder.typepad.com/blog/2017/09/revit-201811-fixes-cropbox-setting.html) + +As an example, let's look at the migration of +the [PlaceInstances add-in implementing text file driven automatic placement of family instances](http://thebuildingcoder.typepad.com/blog/2013/10/text-file-driven-automatic-placement-of-family-instances.html) from +Revit 2014 to Revit 2018, prompted +by [two comments](http://thebuildingcoder.typepad.com/blog/2013/10/text-file-driven-automatic-placement-of-family-instances.html#comment-3619372844) by +Campbell and Renzo: + +**Question:** + +> I'm trying to get this to work in Revit 2016; however, `FamilySymbolSet` was removed in 2016. +Is there a workaround to get the plug in on this page to work without it? +I can get the form to populate with families, but not show the types when I select one... + +> Could you find the solution? + +**Answer:** Yes, this is easy. + +The class `FamilySymbolSet` no longer exists; use a generic collection of element ids instead, in this case, ISet<ElementId>. + +The property `Family.Symbols` no longer exists; use `GetFamilySymbolIds` instead. + +I first performed a flat migration from the Revit 2014 API to Revit 2018, sinply updating the license year, .NET build target version and Revit API DLL references. + +That causes the following errors and warnings: + +
+------ Rebuild All started: Project: PlaceInstances, Configuration: Debug Any CPU ------
+
+error CS0246: The type or namespace name 'FamilySymbolSet' could not be found (are you missing a using directive or an assembly reference?)
+
+error CS1061: 'Family' does not contain a definition for 'Symbols' and no extension method 'Symbols' accepting a first argument of type 'Family' could be found (are you missing a using directive or an assembly reference?)
+
+warning CS0162: Unreachable code detected
+========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
+
+ +The warning message is intentional. + +The Revit 2014 code causing the two errors looks like this: + +
+  FamilySymbolSet symbols = f.Symbols;
+ 
+  // I have to convert the FamilySymbolSet to a
+  // List, or the DataSource assignment will throw 
+  // an exception saying "Complex DataBinding 
+  // accepts as a data source either an IList or
+  // an IListSource.
+ 
+  List<FamilySymbol> symbols2
+    = new List<FamilySymbol>(
+      symbols.Cast<FamilySymbol>() );
+
+ +I converted it to compile for Revit 2018 like this: + +
+  ISet<ElementId> ids = f.GetFamilySymbolIds();
+ 
+  Document doc = f.Document;
+ 
+  List<FamilySymbol> symbols2
+    = new List<FamilySymbol>( 
+      ids.Select<ElementIdFamilySymbol>( id 
+        => doc.GetElement( id ) as FamilySymbol ) );
+
+ +The update is provided in +the [PlaceInstances GitHub repository](https://github.com/jeremytammik/PlaceInstances) +in [release 2018.0.0.0](https://github.com/jeremytammik/PlaceInstances/releases/tag/2018.0.0.0). + +You can check out the changes I made in +the [diff to the preceding version](https://github.com/jeremytammik/PlaceInstances/compare/2014.0.0.7...2018.0.0.0). + +For the sake of completeness, here are +the [error lists before and after the fix](zip/2018_placeinstances_01.txt). + +I hope this helps. + +
+Migration +
diff --git a/a/img/NS.PNG b/a/img/NS.PNG new file mode 100644 index 00000000..1790dd2c Binary files /dev/null and b/a/img/NS.PNG differ diff --git a/a/img/OmniClassTable23.png b/a/img/OmniClassTable23.png new file mode 100644 index 00000000..d9569963 Binary files /dev/null and b/a/img/OmniClassTable23.png differ diff --git a/a/img/migration.png b/a/img/migration.png new file mode 100644 index 00000000..7ed71ca8 Binary files /dev/null and b/a/img/migration.png differ diff --git a/a/index.html b/a/index.html index 53573441..d745eb7b 100644 --- a/a/index.html +++ b/a/index.html @@ -3173,6 +3173,7 @@

Table of Contents

15992017-11-01Forge DevCon Highlights   ^  AU, Cloud, DevCon, Events, Forge, Getting Started 16002017-11-09Purge and Detecting an Empty View   ^  Audio, Deletion, Filters, JavaScript, View 16012017-11-13Deleting a Global Parameter and RevitPythonShell   ^  Data Access, Debugging, Deletion, Python +16022017-11-16    ^  2016, Debugging, Getting Started, Migration, Update diff --git a/a/zip/2018_placeinstances_01.txt b/a/zip/2018_placeinstances_01.txt new file mode 100644 index 00000000..ed37e980 --- /dev/null +++ b/a/zip/2018_placeinstances_01.txt @@ -0,0 +1,40 @@ +After updating license year, .NET build target version and Revit API DLL references: + +------ Rebuild All started: Project: PlaceInstances, Configuration: Debug Any CPU ------ +C:\a\vs\PlaceInstances\PlaceInstances\PlaceInstancesForm.cs(167,7,167,22): error CS0246: The type or namespace name 'FamilySymbolSet' could not be found (are you missing a using directive or an assembly reference?) +C:\a\vs\PlaceInstances\PlaceInstances\PlaceInstancesForm.cs(167,35,167,42): error CS1061: 'Family' does not contain a definition for 'Symbols' and no extension method 'Symbols' accepting a first argument of type 'Family' could be found (are you missing a using directive or an assembly reference?) +C:\a\vs\PlaceInstances\PlaceInstances\PlaceInstancesForm.cs(243,9,243,14): warning CS0162: Unreachable code detected +========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== + + +After replacing the Revit 2014 code: + + FamilySymbolSet symbols = f.Symbols; // 2014 + + // I have to convert the FamilySymbolSet to a + // List, or the DataSource assignment will throw + // an exception saying "Complex DataBinding + // accepts as a data source either an IList or + // an IListSource. + + List symbols2 + = new List( + symbols.Cast() ); // 2014 + +By the Revit 2018 code: + + ISet ids = f.GetFamilySymbolIds(); // 2018 + + Document doc = f.Document; + + List symbols2 + = new List( + ids.Select( id + => doc.GetElement( id ) as FamilySymbol ) ); // 2018 + +------ Build started: Project: PlaceInstances, Configuration: Debug Any CPU ------ +C:\a\vs\PlaceInstances\PlaceInstances\PlaceInstancesForm.cs(252,9,252,14): warning CS0162: Unreachable code detected + PlaceInstances -> C:\a\vs\PlaceInstances\PlaceInstances\bin\Debug\PlaceInstances.dll + 1 file(s) copied. + 1 file(s) copied. +========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========