Revit二次开发示例:AutoUpdate
在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的更多相关文章
- Revit二次开发示例:HelloRevit
本示例实现Revit和Revit打开的文件的相关信息. #region Namespaces using System; using System.Collections.Generic; using ...
- Revit二次开发示例:EventsMonitor
在该示例中,插件在Revit启动时弹出事件监控选择界面,供用户设置,也可在添加的Ribbon界面完成设置.当Revit进行相应操作时,弹出窗体会记录事件时间和名称. #region Namespace ...
- Revit二次开发示例:ErrorHandling
本示例介绍了Revit的错误处理. #region Namespaces using System; using System.Collections.Generic; using Autodes ...
- Revit二次开发示例:ChangesMonitor
在本示例中,程序监控Revit打开文件事件,并在创建的窗体中更新文件信息. #region Namespaces using System; using System.Collections.Ge ...
- Revit二次开发示例:AutoStamp
该示例中,在Revit启动时添加打印事件,在打印时向模型添加水印,打印完成后删除该水印. #region Namespaces using System; using System.Collect ...
- Revit二次开发示例:ModelessForm_ExternalEvent
使用Idling事件处理插件任务. #region Namespaces using System; using System.Collections.Generic; using Autodesk. ...
- Revit二次开发示例:Journaling
关于Revit Journal读写的例子. #region Namespaces using System; using System.Collections.Generic; using Sys ...
- Revit二次开发示例:DisableCommand
Revit API 不支持调用Revit内部命令,但可以用RevitCommandId重写它们(包含任意选项卡,菜单和右键命令).使用RevitCommandId.LookupCommandId()可 ...
- Revit二次开发示例:DesignOptions
本例只要演示Revit的类过滤器的用法,在对话框中显示DesignOption元素. #region Namespaces using System; using System.Collections ...
随机推荐
- 20155310 2016-2017-2 《Java程序设计》第六周学习总结
20155310 2016-2017-2 <Java程序设计>第六周学习总结 教材学习内容总结 4.1 Y86指令集体系结构 •有8个程序寄存器:%eax.%ecx.%edx.%ebx.% ...
- 微服务深入浅出(4)-- 负载均衡Ribbon
Spring Cloud中可以使用RestTemplate+Ribbon的解决方案来将负载均衡以代码的形式封装到客户端中. 通过查阅官方文档可以知道,只需要在程序的IoC容器中注入一个restTemp ...
- Python中的and和or
引子: 出现以上情况的原因是什么呢? print(bool('')) # False print(bool(0)) # False 所有变量的位操作都是通过强制转换成bool实现的,并且表达式的值是从 ...
- [Openwrt 扩展上篇]USB挂载&U盘启动&Samba共享
最近偷懒,没学习,反想起自己的路由刷了Openwrt,正好闲置了一个硬盘想拿来做个网络硬盘,于是开始了折腾....这里将不谈论如何刷Openwrt,如何ssh,如何添加PPOE,如何添加相对应服务的包 ...
- 动态SQL中变量赋值
在动态SQL语句中进行变量的值绑定比较麻烦,这儿做个记录 declare @COUNT int,@sql nvarchar(max) set @sql = 'select @COUNT = count ...
- 命名实体识别(NER)
一.任务 Named Entity Recognition,简称NER.主要用于提取时间.地点.人物.组织机构名. 二.应用 知识图谱.情感分析.机器翻译.对话问答系统都有应用.比如,需要利用命名实体 ...
- Struts2笔记2--动态方法调用和Action接收请求方式
动态方法调用(在请求的时候,再明确具体的响应方法,配置的时候不明确): LoginAction类中有两个方法some和second 1. 动态方法的调用(修改常量struts.enable.Dynam ...
- 使用RegSetValueEx修改注册表时遇到的问题(转)
原文转自 http://blog.csdn.net/tracyzhongcf/article/details/4076870 1.今天在使用RegSetValueEx时发现一个问题: RegSetVa ...
- 5 - django-csrf-session&cookie
目录 1 CSRF跨站请求伪造 1.1 CSRF攻击介绍及防御 1.2 防御CSRF攻击 1.2.1 验证 HTTP Referer 字段 1.2.2 在请求地址中添加 token 并验证 1.2.3 ...
- Python Webdriver 重新使用已经打开的浏览器实例
因为Webdriver每次实例化都会新开一个全新的浏览器会话,在有些情况下需要复用之前打开未关闭的会话.比如爬虫,希望结束脚本时,让浏览器处于空闲状态.当脚本重新运行时,它将继续使用这个会话工作.还就 ...