1111using System ;
1212using System . Collections . Generic ;
1313using System . Diagnostics ;
14+ using System . Linq ;
1415using Autodesk . Revit . ApplicationServices ;
1516using Autodesk . Revit . Attributes ;
1617using Autodesk . Revit . DB ;
1718using Autodesk . Revit . UI ;
18-
1919#endregion // Namespaces
2020
2121namespace BuildingCoder
2222{
23- [ Transaction ( TransactionMode . Automatic ) ]
23+ [ Transaction ( TransactionMode . Manual ) ]
2424 class CmdListMarks : IExternalCommand
2525 {
2626 static bool _modify_existing_marks = true ;
@@ -38,10 +38,12 @@ public Result Execute(
3838 //Autodesk.Revit.Creation.Application creApp = app.Application.Create;
3939 //Autodesk.Revit.Creation.Document creDoc = doc.Create;
4040
41- IList < Element > doors = Util . GetElementsOfType (
42- doc , typeof ( FamilyInstance ) , BuiltInCategory . OST_Doors ) . ToElements ( ) ;
41+ FilteredElementCollector doors
42+ = Util . GetElementsOfType ( doc ,
43+ typeof ( FamilyInstance ) ,
44+ BuiltInCategory . OST_Doors ) ;
4345
44- int n = doors . Count ;
46+ int n = doors . Count ( ) ;
4547
4648 Debug . Print ( "{0} door{1} found." ,
4749 n , Util . PluralSuffix ( n ) ) ;
@@ -88,36 +90,48 @@ Dictionary<string, List<Element>> marks
8890
8991 if ( _modify_existing_marks )
9092 {
91- //ElementSet els = uidoc.Selection.Elements; // 2014
93+ using ( Transaction tx = new Transaction ( doc ) )
94+ {
95+ tx . Start ( "Modify Existing Door Marks" ) ;
9296
93- ICollection < ElementId > ids = uidoc . Selection . GetElementIds ( ) ; // 2015
97+ //ElementSet els = uidoc.Selection.Elements ; // 2014
9498
95- //foreach( Element e in els ) // 2014
99+ ICollection < ElementId > ids = uidoc . Selection
100+ . GetElementIds ( ) ; // 2015
96101
97- foreach ( ElementId id in ids ) // 2015
98- {
99- Element e = doc . GetElement ( id ) ; // 2015
102+ //foreach( Element e in els ) // 2014
100103
101- if ( e is FamilyInstance
102- && null != e . Category
103- && ( int ) BuiltInCategory . OST_Doors
104- == e . Category . Id . IntegerValue )
104+ foreach ( ElementId id in ids ) // 2015
105105 {
106- e . get_Parameter (
107- BuiltInParameter . ALL_MODEL_MARK )
108- . Set ( _the_answer ) ;
109-
110- ++ n ;
106+ Element e = doc . GetElement ( id ) ; // 2015
107+
108+ if ( e is FamilyInstance
109+ && null != e . Category
110+ && ( int ) BuiltInCategory . OST_Doors
111+ == e . Category . Id . IntegerValue )
112+ {
113+ e . get_Parameter (
114+ BuiltInParameter . ALL_MODEL_MARK )
115+ . Set ( _the_answer ) ;
116+
117+ ++ n ;
118+ }
111119 }
120+ tx . Commit ( ) ;
112121 }
113122 }
114123
115124 // return Succeeded only if we wish to commit
116125 // the transaction to modify the database:
126+ //
127+ //return 0 < n
128+ // ? Result.Succeeded
129+ // : Result.Failed;
130+ //
131+ // That was only useful before the introduction
132+ // of the manual and read-only transaction modes.
117133
118- return 0 < n
119- ? Result . Succeeded
120- : Result . Failed ;
134+ return Result . Succeeded ;
121135 }
122136
123137 /*
0 commit comments