Calling Robot Structural Analysis using Revit API

Calling Robot Structural Analysis using Revit API

Anonymous
Not applicable
3,598 Views
15 Replies
Message 1 of 16

Calling Robot Structural Analysis using Revit API

Anonymous
Not applicable

I am trying to call autodesk Robot Structural analysis link using Revit API. (I want to send the Revit model to Robot using API for Analysis).

 

I have tried following code but it is not working:

 

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.ExternalService;
using Autodesk.Revit.ApplicationServices;
using RobotOM;

namespace Dataextraction
{
    [Transaction(TransactionMode.ReadOnly)]
    [Regeneration(RegenerationOption.Manual)]

    public class Dataextraction : IExternalCommand
    {

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;           

 

            RevitCommandId idbuilt = RevitCommandId.LookupPostableCommandId(PostableCommand.SheetIssuesOrRevisions);

            string name_addin = "CustomCtrl_%CustomCtrl_%CustomCtrl_%" + "Analyze%Structural Analysis%AnalysisAndCodeCheck%RobotStructuralAnalysisLink";

            RevitCommandId id_addin = RevitCommandId.LookupCommandId(name_addin);

            uiApp.PostCommand(id_addin);

 

            return Result.Succeeded;
        }
    }
}

 

Please help

0 Likes
Accepted solutions (2)
3,599 Views
15 Replies
Replies (15)
Message 2 of 16

jeremytammik
Autodesk
Autodesk

Dear Machauu,

 

Happy New Year!

 

I am checking with the RST development team.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 16

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Machauu,

  

I received some initial feedback from the development team. They say:

 

I just wonder: why doesn’t the command work? Is there any indication of the cause, e.g. a record in the journal file? Specifically, I am curious about the transaction mode that was used. It is set to 'read-only' which prohibits making transactions to anyone, including Revit itself. If the Robot Analysis command happens to be checking modifiability of a document, then if would fail in this read-only mode. Does changing the transaction mode make any difference?

By the way, the regeneration mode does nothing. It has not had any effect for about five years now.

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 16

Anonymous
Not applicable

 

Dear Jeremy,

 

        Thanks for your help. I have tried all the three transaction modes viz. readolny, automatic and manual.There is same error in the journal file as under:

 

' 0:< DBG_WARN: Exception caught from managed method RevitAPIUI::Void Execute(Autodesk.Revit.UI.UIApplication) <System.Collections.Generic.KeyNotFoundException> <The given key was not present in the dictionary.>: line 115 of Objects\APIExternalEvent.cpp.


' 0:< External event handler <ADSK_RVT_PostCommand> failed with an exception {The given key was not present in the dictionary.}. The event was registered by an AddIn Panel (89eb700a-3c85-4888-a78d-31429ecae9ed)

 

Please help

0 Likes
Message 5 of 16

jeremytammik
Autodesk
Autodesk

Dear Machauu,

 

Thank you for trying the different modes.

 

You can skip the automatic mode; it is almost obsolete.

 

You should probably keep that in mind for future furtehr tests.

  

I received some additional feedback from the development team. They say:

 

Debugging confirms that this code doesn’t work, but I’m afraid it is not connected to Robot Structural Analysis Add-In.

 

The problem occurs in the PostCommand implementation; it should execute command in idle time, but it never does.

 

During debugging Revit code I’ve found that PostCommandHandler::execute_ returns before execution of external command, no error is returned only debug warning is reported.

 

Here is the code:

 

class PostCommandHandler : public IPostCommandHandler
   {
   public:
      OVERRIDE(void, execute_, ())
      {
         /** some code */
 
               // check again and dbg info the command name.
               if(!UIFramework::ShortcutsHelper::Commands->ContainsKey(cmdName))
               {
                  DBG_INFO((commandName + "does not exist."));
                  return; // function returns without execution of command
               }
 
         /** some code */
  }
}

 

It looks like ShortcutsHelper doesn’t contain information about external command and execution is stopped.

 

Are you sure that the command indentification key you are sending in is correct?

 

Where did you obtain that from?

 

Normally, you get it from the journal file after successfully executing the command you wish to drive programmatically.

 

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 16

Anonymous
Not applicable

Dear Jeremy,

 

         I got the key from Journal file. Some of the lines are pasted here

 

Jrn.RibbonEvent "Execute external command:CustomCtrl_%CustomCtrl_%CustomCtrl_%Analyze%Structural Analysis%AnalysisAndCodeCheck%RobotStructuralAnalysisLink:REX.DRevit2Robot.DirectRevitAccess"


 ' 1:< ::13:: Delta VM: Avail -30 -> 8384632 MB, Used +108 -> 562 MB, Peak +107 -> 562 MB; RAM: Avail -117 -> 8801 MB, Used +110 -> 684 MB, Peak +109 -> 684 MB


 'E 05-Jan-2016 15:02:26.525;   1:<

 

so how to make the code work?

 

Regards

 

Mohit

0 Likes
Message 7 of 16

jeremytammik
Autodesk
Autodesk

Dear Mohit,

 

Thank you for clarifying that.

 

I passed it on to the development team and hope that they can help.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 16

Anonymous
Not applicable
Dear Jeremy

. Thank you for kind consideration.

Regards

Mohit
0 Likes
Message 9 of 16

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Mohit,

 

Thank you for your appreciation.

 

I heard back again from the development team and hope that we have a viable solution here now:

 

This solution launches link using its internal types directly.

It requires referencing the link assembly DRevit2Robot.dll which is located (for version 2016) in

 

C:\Program Files\Common Files\Autodesk Shared\Extensions 2016\Modules\RSA\DRevit2Robot\DRevit2Robot.dll


I was able to launch link successfully using this solution and perform transfer.

Add the following .NET assembly references to your add-in project:

 

  • RevitAPI.dll
  • RevitAPIUI.dll
  • DRevit2Robot.dll


Source code:

using Autodesk.Revit;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
 
using System.Reflection;
 
namespace LinkLauncher
{
  [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
  [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
  [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
  public class Command : IExternalCommand
  {
    bool assemblyLoaded = false;
 
    public Command()
    {
      // load assembly before using types explicitly - path for version 2016
      try
      {
        Assembly **** = System.Reflection.Assembly.LoadFrom(@"c:\Program Files\Common Files\Autodesk Shared\Extensions 2016\Modules\RSA\DRevit2Robot\DRevit2Robot.dll");
        if (**** != null)
          assemblyLoaded = true;
      }
      catch
      {
        Autodesk.Revit.UI.TaskDialog.Show("Failure", "Link DRevit2Robot is not installed.");
      }
    }
 
    public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
    {
      if (assemblyLoaded)
      {
        return ExecuteInternal(commandData, ref message, elements);
      }
      else
        return Result.Failed;
    }
 
    /// <summary>
    /// Internal method using types explicitly
    /// </summary>
    private Autodesk.Revit.UI.Result ExecuteInternal(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
    {
      REX.DRevit2Robot.DirectRevitAccess dra = new REX.DRevit2Robot.DirectRevitAccess();
      return dra.Execute(commandData, ref message, elements);
    }
  }
}

 

Please confirm that this works for you as well.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 10 of 16

Anonymous
Not applicable

 

Dear Jeremy,

 

       That works!!!!

 

Thanks a lot for your help in the matter

 

Regards

 

Mohit

0 Likes
Message 11 of 16

jeremytammik
Autodesk
Autodesk

Dear Mohit,

 

Wow, great!

 

Thank you for your confirmation and appreciation.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 12 of 16

Anonymous
Not applicable

Hi Jeremy, 

Thanks for posting the solution, sorry for awaking up the issue after long. kindly If may I ask u for your help in this part.  I using this function new

 

REX.DRevit2Robot.DirectRevitAccess dra = new REX.DRevit2Robot.DirectRevitAccess();
dra.Execute(commandData, ref message, elements);

 

to convert from Revit to Robot but this class open the "Integration with Robot structural analysis " window dialog as usual. this required human interaction to select the options. 

I would like away to pass this selection or overcome by programming  to just select the default option (it works perfectly to my case) is there any class can run this without any human interaction? 

 

Looking forward to you kind help.

 

Tarik 

 

 

0 Likes
Message 13 of 16

jeremytammik
Autodesk
Autodesk
0 Likes
Message 14 of 16

HadiMoosavi
Enthusiast
Enthusiast

Hello All and thank you for this discussion.
Just checking if the solution is still the best practice to run Robot through Revit API.

0 Likes
Message 15 of 16

jeremy_tammik
Alumni
Alumni

No, probably not. The development team is even thinking about deprecating REX, and have recently asked for your opinion on that:

 

https://thebuildingcoder.typepad.com/blog/2022/05/structural-questions-and-the-future-of-rex.html#2

 

Please get in touch with Tomasz if you would like to discuss:

 

https://forums.autodesk.com/t5/revit-api-forum/rex-framework-utilization-in-revit-share-your-experie...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 16 of 16

HadiMoosavi
Enthusiast
Enthusiast

Thank you Jeremy for the links.
The forum post you mentioned above does not seem to be very active.
1st: When you refer to REX, is it the same as Robot add-in for Revit?
2nd: So you mean this add-in will likely be discontinued?

0 Likes