Announcement

Collapse
No announcement yet.

Can a class with interface run another class with interface?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can a class with interface run another class with interface?

    As I understand classes with IExternalCommand implemented are our entry points.
    Is it possible for one class such as to run another one after what it does.
    For example how can I make classA to run classB after itself?

    namespace name
    {
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Rev it.Attributes.TransactionMode.Manual)]

    public class classA : IExternalCommand
    {
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
    //code
    }
    }

    public class classB : IExternalCommand
    {
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
    //code
    }
    }
    }
    http://www.redhotbim.com
    http://www.revitkutuphanesi.com (in Turkish)

    #2
    I don´t get the point of doing it.
    It might just work, but it doesn´t seem logic.
    Why don´t you put both blocks of code inside classA ?
    What am I missing?
    Gonçalo Feio
    "Ignorance, ignorance, sheer ignorance - you know there's no confidence to equal it. It's only when you know something about a profession, I think, that you're timid and careful." George Orson Welles

    Comment


      #3
      I do something like this all the time, but I create a void within the class, as feio suggests.

      Usually, I do this when I need to do the same thing to a group of objects. For example, find all families in the casework category. For each faimily, if there are types defined, Now_Do_This(). If there are not types defined, Now_Do_Something_Else(). (The example below does not do any looping)

      Code:
      namespace name
      {
       [Autodesk.Revit.Attributes.Transaction(Autodesk.Rev it.Attributes.TransactionMode.Manual)]
       
       public class classA : IExternalCommand
       {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
         //code
         Now_Do_This(with_this_string_variable);
         //more code
         Now_Do_Something_Else(family_name, element_id, param, number_of_things);   
         return Result.Succeeded;
        }//result
      
       //inside classA, add this code to pass a string to your new code
       public void Now_Do_This(string with_this_string_variable)
       {
          //do stuff with with_this_string_variable
        }//Now_Do_This
      
       //add this code to pass a string, an element id, a parameter and an integer
       // to your new code - the variable names do not have to match, i am showing
       // them as matching to show how it works
       public void Now_Do_Something_Else(string family_name, ElementId element_id, Parameter param, int number_of_things)
       {
          //do stuff with the four variables
        }//Now_Do_Something_Else
        
       }//classA
      }//namespace

      Comment


        #4
        Thank you very much.
        http://www.redhotbim.com
        http://www.revitkutuphanesi.com (in Turkish)

        Comment

        Related Topics

        Collapse

        Working...
        X