Search code examples
c#revit-apirevit

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. If I write class as class InteropCommand then I need to change the .Addin file accordingly otherwise the command will not work. Now I have question that how can I write a command class in such a way that it will load the Revit addin command. In current scenario I am not able to load the Revit command.

My .Addin file look like below. 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>

Solution

  • 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.