vs2015對revit2018二次開發之helloworld


1.新建

【新建項目】→【Visual C#】→【類庫】

 2.添加引用

【項目】→【添加引用】→【瀏覽】

 在Revit安裝目錄下找到【RevitAPI.dll】和【RevitAPIUI.dll】並添加

 3.設置

(1)右鍵【RevitAPI】和【RevitAPIUI】,點擊【屬性】,將屬性【復制本地】改False

 

 (2)修改類名

Class1改為Test

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

namespace HelloWorld
{
    [Transaction(TransactionMode.Manual)]
    public class Test:IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                TaskDialog.Show("Hello", "First Revit Program.");
            }
            catch (Exception e)
            {
                message = e.Message;
                return Result.Failed;
            }
            return Result.Succeeded;
        }
    }
}

4.生成

(1)【項目】→【屬性】→【調試】→【啟動外部程序】,找到Revit安裝目錄,選擇Revit.exe

(2)生成

  Debug目錄下會生成HelloWorld.dll 

5.部署

在C:\Users\Administrator\AppData\Roaming\Autodesk\Revit\Addins\2018添加

  HelloWorld.addin

內容為

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
    <AddIn Type="Command">
    <VendorId>abc</VendorId>
    <Text>Hello Workd</Text>
    <Description>This is Hello World for revit.</Description>
    <FullClassName>HelloWorld.Test</FullClassName>
    <Assembly>E:/C/revit/HelloWorld/HelloWorld/bin/Debug/helloworld.dll</Assembly>
    <AddInId>6869D1FB-8A0D-4738-958D-1596E99A8244</AddInId>
    </AddIn>
</RevitAddIns>

說明:

  VendorId:開發商Id
  Text:插件的名稱
  Description:插件的描述信息 
  FullClassName:命名空間.類名
  Assembly:剛剛生成的dll路徑
  AddIn:在VS的【工具】→【創建GUID】,選擇注冊表格式,復制,去掉括號

載入

 就可以看到插件了

 

 點擊

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM