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 ...
随机推荐
- 【51nod】1766 树上的最远点对
[题意]给定n个点的树,m次求[a,b]和[c,d]中各选出一个点的最大距离.abcd是标号区间,n,m<=10^5 [算法]LCA+树的直径理论+线段树 [题解] 树的直径性质:距离树上任意点 ...
- 一个愚蠢的python逻辑语法错误
这个事情再次佐证了一个莫名其妙的现象背后一定会有一个愚蠢到无以复加的错误的真理. 写python单元测试的时候发现一个莫名其妙的问题: def xmlStandander(self,s): retur ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1004 HDU 6153 A Secret (字符串处理 KMP)
题目链接 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a presen ...
- Eureka简介
Eureka是Spring Cloud Netfix 的一个子模块,也是核心模块之一,用于云端服务发现.一个基于RestFul的服务,用于定位服务,以实现云端中间层服务发现和中间层转移. 服务注册与发 ...
- yii验证系统学习记录,基于yiicms(二)
/** * Validates the specified object. * @param \yii\base\Model $model the data model being validated ...
- Java枚举类型的用法
JDK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. 1.用法一:常量 在JDK1.5 之前,我们定义常量都是: public static fia ...
- Docker Compose practice
Docker Compose 什么是 Docker-Compose? Compose 可以让用户在集群中部署分布式应用.简单的说,Docker Compose 属于一个"应用层"的 ...
- mac 下安装pip
pip是常用的Python包管理工具,类似于Java的maven.用python的同学,都离不开pip. 在新mac中想用home-brew安装pip时,遇到了一些小问题: bogon:~ wangl ...
- jexus linux x64[标准版] - 未集成mono 配置https
一.找到mono安装位置 sudo find / -name mono 二.首先查看“/lib”或“/usr/lib”等系统库文件夹中是否有SSL库文件的名字,该文件名应该是“libssl.so.版本 ...
- 制作macOS10.12系列的系统镜像文件
制作macOS10.12系列的系统镜像文件步骤,过程也比较简单,十来个命令.以10.12.6为例,首先,在苹果商店下载系统安装包APP,或者网上下载后把安装APP复制到 应用程序 文件夹. 然后打 ...