Making Lines Not Print (with Events)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I came across this post (https://boostyourbim.wordpress.com/2012/12/12/making-lines-not-print-with-events/) a while back and thought I'd give it a go whilst it's a little quiet due to Xmas.
Running it on Revit 2022
As a complete newbie to C# I cannot workout why I'm getting the following errors
Inconsistent accessibility: parameter type 'DocumentPrintingEventArgs' is less accessible than method 'AuscoNoPrint.ThisDocument.myPrintingEvent(object, DocumentPrintingEventArgs)' (CS0051)
'DocumentPrintingEventArgs' is inaccessible due to its protection level (CS0122)
Inconsistent accessibility: parameter type 'DocumentPrintedEventArgs' is less accessible than method 'AuscoNoPrint.ThisDocument.myPrintedEvent(object, DocumentPrintedEventArgs)' (CS0051)
'DocumentPrintedEventArgs' is inaccessible due to its protection level (CS0122)
/*
* Created by SharpDevelop.
* User: Saezed
* Date: 19/12/2023
* Time: 11:28 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
//using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace AuscoNoPrint
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("CB5C92FC-F218-4D2A-A260-BAEDEEC7A7B0")]
public partial class ThisDocument
{
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>();
views.AddRange(args.GetFailedViewElementIds());
views.AddRange(args.GetPrintedViewElementIds());
// 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))
{
t.Start();
// set the visibility of the category
view.setVisibility(doNotPrint, visible);
t.Commit();
}
}
}
private void CategoryLineColor(Color newColor)
{
Document doc = this.ActiveUIDocument.Document;
// 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 value of the color (0 or 255) in the transaction name
using (Transaction t = new Transaction(doc,"Do Not Print color = " + newColor.Blue))
{
t.Start();
// set the style's line color to the "newColor"
doNotPrint.LineColor = newColor;
t.Commit();
}
}
// private void Module_Startup(object sender, EventArgs e)
// {
//
// }
//
// private void Module_Shutdown(object sender, EventArgs e)
// {
//
// }
//
// #region Revit Macros generated code
// private void InternalStartup()
// {
// this.Startup += new System.EventHandler(Module_Startup);
// this.Shutdown += new System.EventHandler(Module_Shutdown);
// }
// #endregion
// public void GetSheetParams()
// {
Any assistance would be greatful.
Thanks