简体   繁体   English

我想创建Revit插件,并且该命令类将是通用的

[英]I want to create Revit Plugin and in that the command class will be generic

[Transaction(TransactionMode.Manual)]
    public class InteropCommand<T, V> : IExternalCommand
    {
        public Result Execute( ExternalCommandData commandData, ref string message,
                               ElementSet elements )
        {
             InterfaceDialog<T, V> interfaceDlgBox = new InterfaceDialog<T, V>( (IDocumentationModel<T>)Revit2014Model );

        }
}

The command.cs file looks like shown above. command.cs文件类似于上图所示。 If I write class as class InteropCommand then I need to change the .Addin file accordingly otherwise the command will not work. 如果我将类写为InteropCommand类,则需要相应地更改.Addin文件,否则该命令将不起作用。 Now I have question that how can I write a command class in such a way that it will load the Revit addin command. 现在,我有一个问题,我该如何编写一种命令类,以使其能够加载Revit插件命令。 In current scenario I am not able to load the Revit command. 在当前情况下,我无法加载Revit命令。

My .Addin file look like below. 我的.Addin文件如下所示。 Do you have any idea how to tackle with this kind of problem ? 您知道如何解决此类问题吗?

<RevitAddIns>
  <AddIn Type="Command">
    <Text>Test</Text>
    <Description>Test Command</Description>
    <Assembly>test.dll</Assembly>
    <FullClassName>InteropCommand</FullClassName>
    <ClientId>0072bf73-c900-449b-bce2-e50a899a72ae</ClientId>
    <VendorId>XYZ</VendorId>
    <VendorDescription>XYZ</VendorDescription>
  </AddIn>
</RevitAddIns>

You need to implement a separate class for each command. 您需要为每个命令实现一个单独的类。

You can derive all your external command implementation classes from a single base class to share part of the implementation, or call a generic class from each individual external command implementation class' Execute method. 您可以从单个基类派生所有外部命令实现类以共享部分实现,也可以从每个单独的外部命令实现类的Execute方法调用通用类。

Adding to Jeremy's reply , you can have a class that implements IExternalApplication, then on the OnStartup method, create as many IExternalCommands as you want, on the fly, without changing the .addin file. 除了Jeremy的答复外 ,您可以拥有一个实现IExternalApplication的类,然后在OnStartup方法上即时创建任意数量的IExternalCommands,而无需更改.addin文件。

This still requires one class for each command, as already mentioned. 如前所述,这仍然需要每个命令一个类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM