加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Revit二次开发之“创建窗体执行Revit命令”

(2016-04-19 08:52:06)
分类: RevitAPI(转编)
Ribbon菜单的空间有限,因此可能需要大量控件放在一个Windows窗体里,
然后在窗体里执行Revit命令。方法就是传递参数,新建IExternalCommand
调用Execute();
 
http://images.cnblogs.com/cnblogs_com/greatverve/cmdForm.png
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DB = Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace RevitBlog
{
    public partial class FrmCmd : Form
    {
        ExternalCommandData cmdDataForm;
        string msgForm;
        DB.ElementSet elementsForm = new DB.ElementSet();
        public FrmCmd()
        {
            InitializeComponent();
        }
        //重载一个构造函数,用来传递参数
        public FrmCmd(ExternalCommandData cmdData, string msg, DB.ElementSet elements)
        {
            InitializeComponent();
            cmdDataForm = cmdData;
            msgForm = msg;
            elementsForm = elements;
        }
        private void btnCmd_Click(object sender, EventArgs e)
        {
            cmdFromForm fromForm = new cmdFromForm();
            fromForm.Execute(cmdDataForm,ref msgForm, elementsForm);
        }
    }
}
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using RevitApp = Autodesk.Revit.ApplicationServices;
namespace RevitBlog
{
    //显示一个非模态窗体
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class cmdShowForm : IExternalCommand
    {
        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
        {
            FrmCmd frmCmd = new FrmCmd(cmdData, msg, elements);
            frmCmd.Show();
            return Result.Succeeded;
        }
    }
    //在窗体里执行Revit命令
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class cmdFromForm : IExternalCommand
    {
        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
        {
            string version = cmdData.Application.Application.VersionBuild;
            version += "\n" + cmdData.Application.Application.VersionName;
            version += "\n" + cmdData.Application.Application.VersionNumber;
            TaskDialog.Show("info", version);
            return Result.Succeeded;
        }
    }
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有