Greetings, folks!

Here is a quick solution to an inconvenience I was having when setting up some Window Legend sheets today. In this particular case I’ve decided to use the Phased Out Legends approach discussed many years ago in this blog post by Martijn de Riet. This is from 2012 but it’s still a valid approach in my opinion. We’ve enjoyed quite a few treats in the recent years, sadly Legends are still to get the attention they need.

The premise is that you setup your Window views as plain old Plan and Elevation views using one long long wall containing all your window types. In order to hide that in all your normal views, you place this rig inside the ‘Existing’ phase and you also demolish them in that same phase. Then you simply adjust your views to show said phases correctly. These dummy windows would remain hidden in all normal views including schedules. That’s the gist of it.

I bet there were a number of ways to automate the task of creating all the ‘mini views’ for each window type, but what I found myself doing is duplicating the same plan and elevation view as dependant views, adjusting the crop region as needed and placing them on the appropriate sheet. Tedious, tedious work.

Duplicate Views on Sheets

What came out of my frustration was a neat way to duplicate Views on Sheets. I can see how that can be quite handy in so many situations where you simply want to save some of the hustle of all the duplicating and dragging and dropping. So here you go, folks, a nice little Macro that you can use inside your Application Macros straight away (unless you need Administrative rights in which case you can go and kick your IT’s butt from me).


// Use inside the Application Macros
public void DuplicateViewPort()
{
	Document doc = this.ActiveUIDocument.Document;			
				
	Viewport viewportToDuplicate = ViewportToDuplicateFromSelection(this.ActiveUIDocument);
	View viewToDuplicate = ViewToDuplicate(doc, viewportToDuplicate);
	XYZ placementPoint = viewportToDuplicate.GetBoxOutline().MaximumPoint;
	using(Transaction t = new Transaction(doc, "dulicate viewport"))
	{
		t.Start();
		Viewport.Create(doc, viewportToDuplicate.SheetId, viewToDuplicate.Id, placementPoint);				
		t.Commit();
	}
}
// Returns the Selected Viewport to Duplicate - promps for selection
internal Viewport ViewportToDuplicateFromSelection(UIDocument uidoc)
{
	var selectedViewPort = uidoc.Selection.PickObject(ObjectType.Element, "Pick Viewport");						
	var viewport = uidoc.Document.GetElement(selectedViewPort.ElementId) as Viewport;
							
	return viewport;
}
// Returns the duplicate View to be placed on the Sheet
internal View ViewToDuplicate(Document doc, Viewport viewport)
{
	using(Transaction t = new Transaction(doc, "duplicate view"))
	{
		t.Start();	
		var view = doc.GetElement(viewport.ViewId) as View;				
		var duplicateView = doc.GetElement(view.Duplicate(ViewDuplicateOption.AsDependent)) 
                   as Autodesk.Revit.DB.View;
		t.Commit();
		
		return duplicateView;
	}			
}

Feel free to use it as you see fit. Ask away, if you have issues implementing it. Use the code to create Dynamo nodes of any sort or kind and generally knock yourselves out.

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();
}
}