应用程序:APIAppStartup

 Revit平台:所有

Revit版本:2011.0

首次发布用于:2008.0

编程语言:C#

技能等级:初级

类别:基础

类型:外部应用

主题:启动外部应用程序。

摘要:此示例演示了如何在Revit启动和关闭时启动外部应用程序。

相关类:Autodesk.Revit.UI.IExternalApplication

项目文件:

AppSample.cs此文件包含类AppSample,该类继承自IExternalApplication接口并实现OnStartup和OnShutdown方法。

SplashWindow.cs此文件包含一个窗体类SplashWindow,它由一个窗体组成,用于在Revit启动时向用户显示Revit徽标和版本信息。

功能:

该示例在Revit应用程序启动时显示一个启动窗口,在Revit应用软件关闭时弹出一个消息框。

响应启动外部应用程序的类必须实现IExternalApplication接口。并且应该在OnStartup和OnShutdown方法中调用外部应用程序。

实施:

1.运行Revit,然后您可以看到一个显示Revit徽标和版本信息的启动窗口。

2.关闭Revit,然后会出现一个消息框。

完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码

AppSample.cs

//
// (C) Copyright 2003-2019 by Autodesk, Inc. All rights reserved.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.

//
// AUTODESK PROVIDES THIS PROGRAM 'AS IS' AND WITH ALL ITS FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable. 

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;

using Autodesk;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;

namespace APIAppStartup
{
   [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
   [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
   [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
   public class AppSample : IExternalApplication
   {
      #region IExternalApplication Members

      public Autodesk.Revit.UI.Result OnShutdown(UIControlledApplication application)
      {
         TaskDialog.Show("Revit", "Quit External Application!");
         return Autodesk.Revit.UI.Result.Succeeded;
      }

       public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
      {
         String version = application.ControlledApplication.VersionName;

         //display splash window for 10 seconds
         SplashWindow.StartSplash();
         SplashWindow.ShowVersion(version);
         System.Threading.Thread.Sleep(10000);
         SplashWindow.StopSplash();

         return Autodesk.Revit.UI.Result.Succeeded;
      }

      #endregion
   }
}

SplashWindow.cs

namespace APIAppStartup
{
   partial class SplashWindow
   {
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.IContainer components = null;

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
      protected override void Dispose(bool disposing)
      {
         if (disposing && (components != null))
         {
            components.Dispose();
         }
         base.Dispose(disposing);
      }


      #region Windows Form Designer generated code

      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         this.Version = new System.Windows.Forms.Label();
         this.SuspendLayout();
         // 
         // Version
         // 
         this.Version.AutoSize = true;
         this.Version.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
         this.Version.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
         this.Version.Location = new System.Drawing.Point(258, 291);
         this.Version.Name = "Version";
         this.Version.Size = new System.Drawing.Size(71, 24);
         this.Version.TabIndex = 0;
         this.Version.Text = "version";
         this.Version.UseWaitCursor = true;
         // 
         // SplashWindow
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.BackColor = System.Drawing.SystemColors.Desktop;
         this.BackgroundImage = global::APIAppStartup.Properties.Resources.test_rvt_Revit_black_93694;
         this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
         this.ClientSize = new System.Drawing.Size(682, 473);
         this.ControlBox = false;
         this.Controls.Add(this.Version);
         this.DoubleBuffered = true;
         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
         this.Name = "SplashWindow";
         this.ShowInTaskbar = false;
         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
         this.Text = "SplashWindow";
         this.TopMost = true;
         this.UseWaitCursor = true;
         this.ResumeLayout(false);
         this.PerformLayout();

      }

      #endregion

      private System.Windows.Forms.Label Version;
   }
}