Making Lines Not Print Improved (View Viz instead of Line Color)

David makes a great observation regarding my post at

‘That all works great if the background is in fact white. What happens if you have the same situation you were showing above with a floor tile pattern? You’d see the white line.”

The code I wrote in that post was I hope good for a relatively gentle introduction to the concept of Revit API Events. But this is not what anyone wants to see when they print.


I used the approach of changing the Object Styles – Line Color to white because it offered a straightforward way to globally change the appearance of the lines in all views. A better approach that requires greater API complexity could be to turn off the visibility of the Do Not Print sub-category in each view that is being printed.


In the previous post’s code, myPrintingEvent and myPrintedEvent both had input arguments DocumentPrintingEventArgs and DocumentPrintedEventArgs that went unused. Every event has arguments like these that are used to pass data about what is happening in this event. For the printing events, this information includes the list of views to be printed and the list of views that were printed. This will be needed for the new approach of changing  category visibility for each view that is printed.

The structure of the code is the same as the previous post, but the CategoryLineColor method has been replaced with categoryVisInViews which uses View.SetVisibility(category, boolean).

public void PrintingEventRegister()
    // myPrintingEvent will run just BEFORE Revit prints
    this.Application.DocumentPrinting += new EventHandler<DocumentPrintingEventArgs>(myPrintingEvent);

    // myPrintedEvent will run just AFTER Revit prints
    this.Application.DocumentPrinted += new EventHandler<DocumentPrintedEventArgs>(myPrintedEvent);

private void myPrintingEvent(object sender, DocumentPrintingEventArgs args)
    // turn OFF visibility of the ""Generic Annotations - Do Not Print" subcategory in the views being printed
    categoryVisInViews(args.Document, args.GetViewElementIds(), false);

private void myPrintedEvent(object sender, DocumentPrintedEventArgs args)
    // list of views that both printed and failed to print
    List<ElementId> views = new List<ElementId>();

    // turn ON visibility of the ""Generic Annotations - Do Not Print" subcategory in views that were printed & that failed to print
    categoryVisInViews(args.Document, views, true);

// This function takes as inputs:
// 1) The document
// 2) The list of views in which the "Do Not Print" subcategory visibility should be changed
// 3) A boolean (true or false) indicating the desired state of the category visibility 
private void categoryVisInViews(Document doc, IList<ElementId> viewList, bool visible)
    foreach (ElementId id in viewList)
        View view = doc.GetElement(id) as View;
        // Get all categories in the document
        Categories categories = doc.Settings.Categories;

        // The "Generic Annotations" category
        Category genericAnnotations = categories.get_Item("Generic Annotations");

        // The ""Do Not Print" subcategory of the "Generic Annotations" category
        Category doNotPrint = genericAnnotations.SubCategories.get_Item("Do Not Print");

        // Create transaction with the view name & state in the transaction name
        using (Transaction t = new Transaction(doc,"Set Visibility: " + view.Name + ": " + visible))
            // set the visibility of the category
            view.setVisibility(doNotPrint, visible);

6 thoughts on “Making Lines Not Print Improved (View Viz instead of Line Color)

  1. harry- I appreciate the various approaches, as well as keeping things basic (which is what I love about what you’re doing here)! thanks!

  2. Harry – Old time C programmer from the Autolisp days. Trying to get back in to programming and feel like I’m learning to ride a bike again. You’re blog has been invaluable. Great macros.


    1. I ran the noprint macro. I can’t believe Revit does not have this functionality. When I ran it in 2014 it kept giving me error messages. The debugger fixed whatever the problems was.
    2. Is it possible to make this work with other components, lines, text, etc?

    • Hi Tom,

      Glad you’ve been enjoying the blog. You might also find my video lectures at to be helpful.

      What were the errors you were getting in 2014?

      The visibility of different items can be controlled in different ways. This post sets category visibility. You might also use View.HideElements if there are specific elements you want to not display without turning off the whole category.


  3. Harry, just found your website. I’m a BIM Manager but new to Macros and have no programming experience. Is it possible to provide a few steps for a newbie on where to copy and paste the macro and how to run the macro? This would truly help as a lot of users i’m working with still reminisce the CAD days and would like this functionality.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s