Text to Capitals

This is a short macro that I wrote today for a task that has always been bothering me. I spend equal amounts of time changing the first several text notes by hand, looking for an existing solution in the Revit Store as well as everywhere else (Google) and finally writing the small script up.

It is the smallest possible amount of code and you can surely make it prettier if it is your wish. You can have it up and running in no time by following these steps:

1.      Go to Manage tab ->Macro Manager -> Application

2.      Click on ‘Module’, give it a name

3.      Copy/Paste the code below right after ‘Revit Macros generated code’  (click after the last ‘, hit ‘Enter’, paste)

4.      Go to Build -> Build Solution (F8) and Ctrl+S to save it out.

5.      Close the Sharp Develop window

6.      Under the Macro Manager you should now see your new Macro named ‘Capitalize’ if you haven’t changed it

7.      Now ‘Run’ the Macro and select the Texts you want to change.

There you go. You now write Revit Macros. Congratulations!

 

public void Capitalize()

  {
            UIDocument uidoc = ActiveUIDocument;
            Document doc = ActiveUIDocument.Document;
            
IList<Reference> selection = uidoc.Selection.PickObjects(ObjectType.Element, “Text to edit“);

if(selection.Count == 0)
{
TaskDialog.Show(“Error“, “No selected elements“);
return;
}

using (Transaction t = new Transaction(doc, “Capitalise Text”))
{
t.Start();
foreach(Reference r in selection)
{
TextNote note = doc.GetElement(r.ElementId) as TextNote;

if(note != null)
{
note.Text = note.Text.ToUpper();
}
}
t.Commit();
}
}

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.