在Revit打开文件时,修改文件信息。并记录状态,存到log文件中。

#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI;
#endregion namespace AutoUpdate
{
[Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]
[Autodesk.Revit.Attributes.Journaling(JournalingMode.NoCommandData)]
class App : IExternalApplication
{
private TextWriterTraceListener m_txtListener;
private static string m_directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
private string m_tempFile = Path.Combine(m_directory, "temp.log"); public Result OnStartup(UIControlledApplication a)
{
try
{
CreateTempFile(); a.ControlledApplication.DocumentOpened += ControlledApplication_DocumentOpened;
}
catch (Exception)
{
return Result.Failed;
}
return Result.Succeeded;
} public Result OnShutdown(UIControlledApplication a)
{
a.ControlledApplication.DocumentOpened -= ControlledApplication_DocumentOpened;
CloseLogFile();
return Result.Succeeded;
} void ControlledApplication_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
{
DumpEventArgs(e);
Document doc = e.Document; if (doc.IsFamilyDocument)
{
return;
} try
{
Transaction eventTransaction = new Transaction(doc, "Event handler modify project information");
eventTransaction.Start();
doc.ProjectInformation.Address =
"United States - Massachusetts - Waltham - 610 Lincoln St";
eventTransaction.Commit();
}
catch (Exception ee)
{
Trace.WriteLine("Failed to modify project information!-" + ee.Message);
} Trace.WriteLine("The value after running the sample ------>");
Trace.WriteLine(" [Address] :" + doc.ProjectInformation.Address);
} private void CreateTempFile()
{
if (File.Exists(m_tempFile)) File.Delete(m_tempFile);
m_txtListener = new TextWriterTraceListener(m_tempFile);
Trace.AutoFlush = true;
Trace.Listeners.Add(m_txtListener);
} private void DumpEventArgs(DocumentOpenedEventArgs args)
{
Trace.WriteLine("DocumentOpenedEventArgs Parameters ------>");
Trace.WriteLine(" Event Cancel : " + args.IsCancelled());
Trace.WriteLine(" Event Cancvellable : " + args.Cancellable);
Trace.WriteLine(" Status : " + args.Status);
} private void CloseLogFile()
{
Trace.Flush();
Trace.Listeners.Remove(m_txtListener);
Trace.Close();
m_txtListener.Close(); string logFile = Path.Combine(m_directory, "AutoUpdate.log");
if (File.Exists(logFile)) File.Delete(logFile);
File.Copy(m_tempFile, logFile);
File.Delete(m_tempFile);
}
}
}

Revit二次开发示例:AutoUpdate的更多相关文章

  1. Revit二次开发示例:HelloRevit

    本示例实现Revit和Revit打开的文件的相关信息. #region Namespaces using System; using System.Collections.Generic; using ...

  2. Revit二次开发示例:EventsMonitor

    在该示例中,插件在Revit启动时弹出事件监控选择界面,供用户设置,也可在添加的Ribbon界面完成设置.当Revit进行相应操作时,弹出窗体会记录事件时间和名称. #region Namespace ...

  3. Revit二次开发示例:ErrorHandling

    本示例介绍了Revit的错误处理.   #region Namespaces using System; using System.Collections.Generic; using Autodes ...

  4. Revit二次开发示例:ChangesMonitor

    在本示例中,程序监控Revit打开文件事件,并在创建的窗体中更新文件信息.   #region Namespaces using System; using System.Collections.Ge ...

  5. Revit二次开发示例:AutoStamp

    该示例中,在Revit启动时添加打印事件,在打印时向模型添加水印,打印完成后删除该水印.   #region Namespaces using System; using System.Collect ...

  6. Revit二次开发示例:ModelessForm_ExternalEvent

    使用Idling事件处理插件任务. #region Namespaces using System; using System.Collections.Generic; using Autodesk. ...

  7. Revit二次开发示例:Journaling

    关于Revit Journal读写的例子.   #region Namespaces using System; using System.Collections.Generic; using Sys ...

  8. Revit二次开发示例:DisableCommand

    Revit API 不支持调用Revit内部命令,但可以用RevitCommandId重写它们(包含任意选项卡,菜单和右键命令).使用RevitCommandId.LookupCommandId()可 ...

  9. Revit二次开发示例:DesignOptions

    本例只要演示Revit的类过滤器的用法,在对话框中显示DesignOption元素. #region Namespaces using System; using System.Collections ...

随机推荐

  1. 【转】.NET中的三种Timer的区别和用法

    最近正好做一个WEB中定期执行的程序,而.NET中有3个不同的定时器.所以正好研究研究.这3个定时器分别是: //1.实现按用户定义的时间间隔引发事件的计时器.此计时器最宜用于 Windows 窗体应 ...

  2. 05.UIDynamic

    CHENYILONG Blog 05.UIDynamic Fullscreen © chenyilong. Powered by Postach.io Blog

  3. 【leetcode 简单】 第七十九题 区域和检索 - 数组不可变

    给定一个整数数组  nums,求出数组从索引 i 到 j  (i ≤ j) 范围内元素的总和,包含 i,  j 两点. 示例: 给定 nums = [-2, 0, 3, -5, 2, -1],求和函数 ...

  4. 【leetcode 简单】 第六十题 反转链表

    反转一个单链表. 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 进阶: 你可以迭代 ...

  5. Oracle分析函数Over()

    一.Over()分析函数 说明:聚合函数(如sum().max()等)可以计算基于组的某种聚合值,但是聚合函数对于某个组只能返回一行记录.若想对于某组返回多行记录,则需要使用分析函数. 1.rank( ...

  6. 20165320 第四次实验 Android开发

    实验内容: Android程序设计-1 实验要求: - 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)>第二十四章: - 参 ...

  7. Linux input子系统学习总结(三)----Input设备驱动

    Input 设备驱动 ---操作硬件获取硬件寄存器中设备输入的数据,并把数据交给核心层: 一 .设备驱动的注册步骤: 1.分配一个struct  input_dev :          struct ...

  8. 十分钟搞懂快速傅里叶变换(FFT)

    己学习的笔记,欢迎大家指正.

  9. 打造 Laravel 优美架构 谈可维护性与弹性设计

    转载:https://juejin.im/post/5be4475c518825170559c044

  10. java基础80 JSP基础知识点(网页知识)

    1.jsp的引入 Servlet的作用:用java语言开发动态资源技术!!!    Jsp的作用:用java语言(+html语言)开发的动态资源技术!!!     Jsp就是servlet 问题:为什 ...