Skip to content

Commit

Permalink
updated CmdListMarks to use TransactionMode.Manual instead of Automatic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Tammik committed Feb 20, 2015
1 parent 9410857 commit 55dfd34
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
60 changes: 37 additions & 23 deletions BuildingCoder/BuildingCoder/CmdListMarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

#endregion // Namespaces

namespace BuildingCoder
{
[Transaction( TransactionMode.Automatic )]
[Transaction( TransactionMode.Manual )]
class CmdListMarks : IExternalCommand
{
static bool _modify_existing_marks = true;
Expand All @@ -38,10 +38,12 @@ public Result Execute(
//Autodesk.Revit.Creation.Application creApp = app.Application.Create;
//Autodesk.Revit.Creation.Document creDoc = doc.Create;

IList<Element> doors = Util.GetElementsOfType(
doc, typeof( FamilyInstance ), BuiltInCategory.OST_Doors ).ToElements();
FilteredElementCollector doors
= Util.GetElementsOfType( doc,
typeof( FamilyInstance ),
BuiltInCategory.OST_Doors );

int n = doors.Count;
int n = doors.Count();

Debug.Print( "{0} door{1} found.",
n, Util.PluralSuffix( n ) );
Expand Down Expand Up @@ -88,36 +90,48 @@ Dictionary<string, List<Element>> marks

if( _modify_existing_marks )
{
//ElementSet els = uidoc.Selection.Elements; // 2014
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Modify Existing Door Marks" );

ICollection<ElementId> ids = uidoc.Selection.GetElementIds(); // 2015
//ElementSet els = uidoc.Selection.Elements; // 2014

//foreach( Element e in els ) // 2014
ICollection<ElementId> ids = uidoc.Selection
.GetElementIds(); // 2015

foreach( ElementId id in ids ) // 2015
{
Element e = doc.GetElement( id ); // 2015
//foreach( Element e in els ) // 2014

if( e is FamilyInstance
&& null != e.Category
&& (int) BuiltInCategory.OST_Doors
== e.Category.Id.IntegerValue )
foreach( ElementId id in ids ) // 2015
{
e.get_Parameter(
BuiltInParameter.ALL_MODEL_MARK )
.Set( _the_answer );

++n;
Element e = doc.GetElement( id ); // 2015

if( e is FamilyInstance
&& null != e.Category
&& (int) BuiltInCategory.OST_Doors
== e.Category.Id.IntegerValue )
{
e.get_Parameter(
BuiltInParameter.ALL_MODEL_MARK )
.Set( _the_answer );

++n;
}
}
tx.Commit();
}
}

// return Succeeded only if we wish to commit
// the transaction to modify the database:
//
//return 0 < n
// ? Result.Succeeded
// : Result.Failed;
//
// That was only useful before the introduction
// of the manual and read-only transaction modes.

return 0 < n
? Result.Succeeded
: Result.Failed;
return Result.Succeeded;
}

/*
Expand Down
5 changes: 3 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
// 2015-02-10 2015.0.117.2 eliminated all deprecated API usage to compile with zero warnings now
// 2015-02-14 2015.0.117.3 implemented PlaceFamilyInstanceOnFace
// 2015-02-19 2015.0.117.4 updated CmdInstallLocation from Revit 2010 to 2015 and replaced TransactionMode.Automatic by ReadOnly
// 2015-02-20 2015.0.117.5 updated CmdListMarks to use TransactionMode.Manual instead of Automatic
//
[assembly: AssemblyVersion( "2015.0.117.4" )]
[assembly: AssemblyFileVersion( "2015.0.117.4" )]
[assembly: AssemblyVersion( "2015.0.117.5" )]
[assembly: AssemblyFileVersion( "2015.0.117.5" )]

0 comments on commit 55dfd34

Please sign in to comment.