Skip to content

Commit 55dfd34

Browse files
author
Jeremy Tammik
committed
updated CmdListMarks to use TransactionMode.Manual instead of Automatic
1 parent 9410857 commit 55dfd34

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

BuildingCoder/BuildingCoder/CmdListMarks.cs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
using System;
1212
using System.Collections.Generic;
1313
using System.Diagnostics;
14+
using System.Linq;
1415
using Autodesk.Revit.ApplicationServices;
1516
using Autodesk.Revit.Attributes;
1617
using Autodesk.Revit.DB;
1718
using Autodesk.Revit.UI;
18-
1919
#endregion // Namespaces
2020

2121
namespace 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
/*

BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
// 2015-02-10 2015.0.117.2 eliminated all deprecated API usage to compile with zero warnings now
7373
// 2015-02-14 2015.0.117.3 implemented PlaceFamilyInstanceOnFace
7474
// 2015-02-19 2015.0.117.4 updated CmdInstallLocation from Revit 2010 to 2015 and replaced TransactionMode.Automatic by ReadOnly
75+
// 2015-02-20 2015.0.117.5 updated CmdListMarks to use TransactionMode.Manual instead of Automatic
7576
//
76-
[assembly: AssemblyVersion( "2015.0.117.4" )]
77-
[assembly: AssemblyFileVersion( "2015.0.117.4" )]
77+
[assembly: AssemblyVersion( "2015.0.117.5" )]
78+
[assembly: AssemblyFileVersion( "2015.0.117.5" )]

0 commit comments

Comments
 (0)