Last active
December 17, 2015 04:39
-
-
Save pzurek/5552402 to your computer and use it in GitHub Desktop.
A simple Revit macro written in Ruby. Upon execution it detects and deletes all unnamed reference planes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load_assembly "RevitAPI" | |
load_assembly "RevitAPIUI" | |
include Autodesk::Revit::DB | |
include Autodesk::Revit::UI | |
include Autodesk::Revit::UI::Selection | |
include System::Collections::Generic | |
include System::Collections | |
include System | |
class ThisApplication < Autodesk::Revit::UI::Macros::ApplicationEntryPoint | |
#region Revit Macros generated code | |
protected | |
def FinishInitialization | |
super | |
self.InternalStartup | |
end | |
def OnShutdown | |
self.InternalShutdown | |
super | |
end | |
def InternalStartup | |
self.Startup | |
end | |
def InternalShutdown | |
self.Shutdown | |
end | |
def Startup | |
end | |
def Shutdown | |
end | |
#endregion | |
public | |
def PurgeRefPlanes | |
unless self.ActiveUIDocument.nil? | |
doc = self.ActiveUIDocument.Document | |
# collecting all ref planes in the project | |
ref_plane_collector = FilteredElementCollector.new(doc) | |
ref_plane_collector.OfClass(ReferencePlane.to_clr_type) | |
ref_planes = ref_plane_collector.ToElements | |
name_parameter_id = ElementId.new(BuiltInParameter.DATUM_TEXT) | |
pvp = ParameterValueProvider.new(name_parameter_id) | |
evaluator = FilterStringEquals.new() | |
rule = FilterStringRule.new(pvp, evaluator, "", false) | |
filter = ElementParameterFilter.new(rule) | |
unnamed_ref_plane_collector = FilteredElementCollector.new(doc) | |
unnamed_ref_plane_collector.OfClass(ReferencePlane.to_clr_type) | |
unnamed_ref_plane_collector.WherePasses(filter) | |
unnamed_ref_planes = unnamed_ref_plane_collector.ToElements | |
transaction = Transaction.new(doc, "Purging unnamed reference planes") | |
transaction.Start | |
unnamed_ref_planes.map { |ref_plane| doc.Delete(ref_plane) } | |
transaction.Commit | |
TaskDialog.Show("Purge Unnamed Ref Planes", "#{ref_planes.Count} reference planes found.\n#{unnamed_ref_planes.Count} unnamed ref planes deleted.") | |
end | |
end | |
# Transaction mode | |
def GetTransactionMode() | |
return Autodesk::Revit::Attributes::TransactionMode.Manual | |
end | |
# Addin Id | |
def GetAddInId() | |
return System::String.new("4596A3CA-FEB6-42C2-8EAA-81B0E9FE404D") | |
end | |
end |
OK, done. Now it doesn't check the element name but instead the value of the parameter that populates the name.
Should work for all localizations.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This uses a simple selection method, simply searching for ref planes called "Reference Plane".
The next, proper version should check the built-in parameter Name which should be nil or empty for unnamed ref planes.