0

I'm not entirely sure at all why this is happening... So I have a ExternalCommand and an application for making a ribbon tab and button. These two programs are in the same solution and under the same namespace, which allows me to have fewer files to deal with. When I create a button for my command, I want to put in the current path of the application that is currently running. I do this with Directory.GetCurrentDirectory() + \AddInsAll\Ribbon17.dll (where AddInsAll is the folder and Ribbon17 is the dll, obviously). I use @ when necessary to avoid escape sequences. This string contains the exact assembly name needed, but Revit tells me "Assembly does not exist." If I replace this String variable with the hard coded C:\ProgramData\Autodesk\Revit\Addins\2017\AddInsAll\Ribbon17.dll it works. I want it obviously more robust than that. My code will be below, thanks in advance.

FYI: I have a TaskDialog showing when it first runs, and the fullPath that it returns is exacly the same as the hard coded path. I have to do a replace (Program Files to ProgramData) due to some weird bug with the get directory. Also, I add "\AddInsAll\Ribbon17.dll" to the end of the string because the CurrentDirectory goes only to Addins\2017. Finally, if you think the problem is due to the @'s, I have already tried putting it and taking it off of variables and none of the attempts work. But if you think of them is the problem, I welcome the advice. Thanks.

public class RibApp : IExternalApplication
{
    public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application)
    {
        // Create a custom ribbon tab
        String tabName = "Add-Ins";
        String fakeFullPath = @Directory.GetCurrentDirectory() + @"\AddInsAll\Ribbon17.dll";
        String fullPath = fakeFullPath.Replace(@"\Program Files\", @"\ProgramData\");
        TaskDialog.Show("Hi", @fullPath);
        application.CreateRibbonTab(tabName);

        //Create buttons and panel
            // Create two push buttons
            PushButtonData CommandButton = new PushButtonData("Command17", "Command",
                @fullPath, "Ribbon17.Command");
Jacob Bunzel
  • 165
  • 1
  • 4
  • 15

1 Answers1

0

I suggest you skip the @ and replace each backslash \ by a forward slash /.

KISS!

Better still, use an approach similar to the CreateRibbonTab implementation in the HoloLens Escape Path Waypoint JSON Exporter.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Thank you for the response, I will try these out – Jacob Bunzel Aug 18 '17 at 12:09
  • For some reason using Assembly to get the path rather than Directory.GetCurrentDirectory seemed to have fixed it. Thank you! Now all my add-ins are in only one file. :) – Jacob Bunzel Aug 18 '17 at 17:25
  • `Directory.GetCurrentDirectory` is probably not what you want anyway. Where does that even point to? It is highly dependant on things not under your control. Hint: The current directory that Revit was started in. Depending on how Revit was started... – Daren Thomas Aug 21 '17 at 09:10
  • That is exactly why I prefer using the assembly path :-) – Jeremy Tammik Aug 22 '17 at 08:15