Revit API:使用字符串作为具有当前路径的按钮程序集名称
Revit API: Use String as Button Assembly Name with Current Path
我完全不确定为什么会这样...
所以我有一个 ExternalCommand 和一个用于制作功能区选项卡和按钮的应用程序。这两个程序在同一个解决方案和同一个命名空间下,这让我可以处理更少的文件。当我为我的命令创建一个按钮时,我想放入当前 运行 的应用程序的当前路径。我使用 Directory.GetCurrentDirectory() + \AddInsAll\Ribbon17.dll
执行此操作(显然,AddInsAll 是文件夹,Ribbon17 是 dll)。我在必要时使用 @ 来避免转义序列。此字符串包含所需的确切程序集名称,但 Revit 告诉我 "Assembly does not exist." 如果我用硬编码 C:\ProgramData\Autodesk\Revit\Addins17\AddInsAll\Ribbon17.dll
替换此字符串变量,它会起作用。我希望它显然比那更健壮。我的代码将在下面,提前致谢。
仅供参考:我有一个 TaskDialog 在它首次运行时显示,它 returns 的 fullPath 与硬编码路径完全相同。由于 get 目录存在一些奇怪的错误,我必须进行替换(Program Files to ProgramData)。此外,我将“\AddInsAll\Ribbon17.dll”添加到字符串的末尾,因为 CurrentDirectory 仅转到 Addins17。最后,如果您认为问题是由于 @ 引起的,我已经尝试将它从变量中取出来,并且 none 的尝试有效。但是如果你觉得是他们的问题,欢迎指教。谢谢
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");
我建议您跳过 @ 并将每个反斜杠 \ 替换为正斜杠 /。
KISS!
更好的是,使用类似于 HoloLens Escape Path Waypoint JSON Exporter 中的 CreateRibbonTab
实现的方法。
我完全不确定为什么会这样...
所以我有一个 ExternalCommand 和一个用于制作功能区选项卡和按钮的应用程序。这两个程序在同一个解决方案和同一个命名空间下,这让我可以处理更少的文件。当我为我的命令创建一个按钮时,我想放入当前 运行 的应用程序的当前路径。我使用 Directory.GetCurrentDirectory() + \AddInsAll\Ribbon17.dll
执行此操作(显然,AddInsAll 是文件夹,Ribbon17 是 dll)。我在必要时使用 @ 来避免转义序列。此字符串包含所需的确切程序集名称,但 Revit 告诉我 "Assembly does not exist." 如果我用硬编码 C:\ProgramData\Autodesk\Revit\Addins17\AddInsAll\Ribbon17.dll
替换此字符串变量,它会起作用。我希望它显然比那更健壮。我的代码将在下面,提前致谢。
仅供参考:我有一个 TaskDialog 在它首次运行时显示,它 returns 的 fullPath 与硬编码路径完全相同。由于 get 目录存在一些奇怪的错误,我必须进行替换(Program Files to ProgramData)。此外,我将“\AddInsAll\Ribbon17.dll”添加到字符串的末尾,因为 CurrentDirectory 仅转到 Addins17。最后,如果您认为问题是由于 @ 引起的,我已经尝试将它从变量中取出来,并且 none 的尝试有效。但是如果你觉得是他们的问题,欢迎指教。谢谢
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");
我建议您跳过 @ 并将每个反斜杠 \ 替换为正斜杠 /。
KISS!
更好的是,使用类似于 HoloLens Escape Path Waypoint JSON Exporter 中的 CreateRibbonTab
实现的方法。