How to pass arguments from ribbon elemnts to function (commad class)

How to pass arguments from ribbon elemnts to function (commad class)

sai.yashwanthkumar
Explorer Explorer
596 Views
2 Replies
Message 1 of 3

How to pass arguments from ribbon elemnts to function (commad class)

sai.yashwanthkumar
Explorer
Explorer

Hi,

 

I have 2 push buttons which will do execute same functions but but with diff set of variables should be passed to the function on clicking on the push buttopns

 

for examples i have 2 push buttons to show/hide elemts in revit drawing, i will be managing the hide/show in one function(command class) if i click on show push button it should pass the parameter show to the function.

 

is there any way to do this in revit.

 

Thanks in advance.

 

/yashwnath 

0 Likes
Accepted solutions (2)
597 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

No that is the wrong approach for the external commands.

 

You provide class name when creating the button to point to an Implementation of IExternalCommand.  So when execute executes on that interface you don't know from what button that came, this is the issue.

 

You have to create a class for each command but with inheritance this can be very minimal e.g.

 

 

Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI

Public MustInherit Class RT_ExternalCommandsBase
    Implements IExternalCommand
    Public ReadOnly Property MethodName As String
        Get
            Return Me.GetType.Name
        End Get
    End Property
    Public Function MainExecute(CMDName As String, commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result

        Select Case CMDName
            Case "CMD1"
                TaskDialog.Show("Title", CMDName)
            Case "CMD2"
                TaskDialog.Show("Title", CMDName)
            Case Else
                TaskDialog.Show("Title", CMDName)
        End Select

    End Function

    Public Function Execute(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result Implements IExternalCommand.Execute
        Return MainExecute(Me.MethodName, commandData, message, elements)
    End Function
End Class

<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)>
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)>
Public Class CMD1
    Inherits RT_ExternalCommandsBase
End Class
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)>
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)>
Public Class CMD2
    Inherits RT_ExternalCommandsBase
End Class
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)>
<Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)>
Public Class CMD3
    Inherits RT_ExternalCommandsBase
End Class

 

 

 

0 Likes
Message 3 of 3

sai.yashwanthkumar
Explorer
Explorer
Accepted solution

It works thank you .. 🙂

0 Likes