示例#1
0
 /// <summary>
 /// Handler method for ViewPrinting event.
 /// This method will dump detailed information of view, like view type, id and start start time of print for this view.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void AppViewPrinting(object sender, Autodesk.Revit.DB.Events.ViewPrintingEventArgs e)
 {
     // header information
     Trace.WriteLine(System.Environment.NewLine + "View Print Start: -----------------------------------------------");
     //
     // Start new watch for ViewPrint
     StartNewWatch(e.Document, true);
     //
     // Dump the events arguments
     DumpEventArguments(e);
 }
示例#2
0
 void doc_ViewPrinting(object sender, Autodesk.Revit.DB.Events.ViewPrintingEventArgs e)
 {
     DisplayEvent("View printing");
 }
示例#3
0
        /// <summary>
        /// Handler method for ViewPrinting event.
        /// This method will dump EventArgument information of event firstly and then create TextNote element for this view.
        /// View print will be canceled if TextNote creation failed.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments of ViewPrinting event.</param>
        public void AppViewPrinting(object sender, Autodesk.Revit.DB.Events.ViewPrintingEventArgs e)
        {
            // Setup log file if it still is empty
            if (null == m_eventsLog)
            {
                SetupLogFiles();
            }
            //
            // header information
            Trace.WriteLine(System.Environment.NewLine + "View Print Start: ------------------------");
            //
            // Dump the events arguments
            DumpEventArguments(e);
            //
            // Create TextNote for current view, cancel the event if TextNote creation failed
            bool failureOccured = false; // Reserves whether failure occurred when create TextNote

            try
            {
                String strText = String.Format("Printer Name: {0}{1}User Name: {2}",
                                               e.Document.PrintManager.PrinterName, System.Environment.NewLine, System.Environment.UserName);
                //
                // Use non-debug compile symbol to write constant text note
#if !(Debug || DEBUG)
                strText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#endif
                using (Transaction eventTransaction = new Transaction(e.Document, "External Tool"))
                {
                    eventTransaction.Start();
                    TextNoteOptions options = new TextNoteOptions();
                    options.HorizontalAlignment = HorizontalTextAlignment.Center;
                    options.TypeId = e.Document.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
                    TextNote newTextNote = TextNote.Create(e.Document, e.View.Id, XYZ.Zero, strText, options);
                    eventTransaction.Commit();

                    // Check to see whether TextNote creation succeeded
                    if (null != newTextNote)
                    {
                        Trace.WriteLine("Create TextNote element successfully...");
                        m_newTextNoteId = newTextNote.Id;
                    }
                    else
                    {
                        failureOccured = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                failureOccured = true;
                Trace.WriteLine("Exception occurred when creating TextNote, print will be canceled, ex: " + ex.Message);
            }
            finally
            {
                // Cancel the TextNote creation when failure occurred, meantime the event is cancellable
                if (failureOccured && e.Cancellable)
                {
                    e.Cancel();
                }
            }
        }
示例#4
0
        /// <summary>
        /// Handler method for ViewPrinting event.
        /// This method will dump EventArgument information of event firstly and then create TextNote element for this view.
        /// View print will be cancelled if TextNote creation failed.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments of ViewPrinting event.</param>
        public void AppViewPrinting(object sender, Autodesk.Revit.DB.Events.ViewPrintingEventArgs e)
        {
            // Setup log file if it still is empty
            if (null == m_eventsLog)
            {
                SetupLogFiles();
            }
            //
            // header information
            Trace.WriteLine(System.Environment.NewLine + "View Print Start: ------------------------");
            //
            // Dump the events arguments
            DumpEventArguments(e);
            //
            // Create TextNote for current view, cancel the event if TextNote creation failed
            bool faileOccur = false; // Reserves whether failure occurred when create TextNote

            try
            {
                String strText = String.Format("Printer Name: {0}{1}User Name: {2}",
                                               e.Document.PrintManager.PrinterName, System.Environment.NewLine, System.Environment.UserName);
                //
                // Use non-debug compile symbol to write constant text note
#if !(Debug || DEBUG)
                strText = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#endif
                //now event framework will not provide transaction, user need start by self(2009/11/18)
                Transaction eventTransaction = new Transaction(e.Document, "External Tool");
                eventTransaction.Start();
                TextNote newTextNote = e.Document.Create.NewTextNote(
                    e.View,                                            // View
                    new Autodesk.Revit.DB.XYZ(0, 0, 0),                // origin
                    new Autodesk.Revit.DB.XYZ(1.0, 0.0, 0.0),          // baseVec
                    new Autodesk.Revit.DB.XYZ(0.0, 1.0, 0.0),          // upVec
                    1.0,                                               // lineWidth
                    Autodesk.Revit.DB.TextAlignFlags.TEF_ALIGN_CENTER, // textAlign
                    strText
                    );
                eventTransaction.Commit();
                //
                // Check to see whether TextNote creation succeeded
                if (null != newTextNote)
                {
                    Trace.WriteLine("Create TextNote element successfully...");
                    m_newTextNoteId = new ElementId(newTextNote.Id.IntegerValue);
                }
                else
                {
                    faileOccur = true;
                }
            }
            catch (System.Exception ex)
            {
                faileOccur = true;
                Trace.WriteLine("Exception occurred when creating TextNote, print will be cancelled, ex: " + ex.Message);
            }
            finally
            {
                // Cancel the TextNote creation when failure occurred, meantime the event is cancellable
                if (faileOccur && e.Cancellable)
                {
                    e.Cancel();
                }
            }
        }