Skip to content

Instantly share code, notes, and snippets.

@jordanrobot
Created December 31, 2024 01:42
Show Gist options
  • Save jordanrobot/aa9e99b747b1cb0f582d02104cdb63a9 to your computer and use it in GitHub Desktop.
Save jordanrobot/aa9e99b747b1cb0f582d02104cdb63a9 to your computer and use it in GitHub Desktop.

Revisions

  1. jordanrobot created this gist Dec 31, 2024.
    42 changes: 42 additions & 0 deletions EnsureSupportPaths.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    public static bool EnsureSupportPaths()
    {
    List<string> supportPaths = [
    $@"{RoamingAppData}\Autodesk\ApplicationPlugins\plugin.bundle\Contents\",
    $@"{RoamingAppData}\Autodesk\ApplicationPlugins\plugin.bundle\Contents\lisp\",
    $@"{RoamingAppData}\Autodesk\ApplicationPlugins\plugin.bundle\Contents\assets\objects\",
    $@"{RoamingAppData}\Autodesk\ApplicationPlugins\plugin.bundle\Contents\assets\templates\",
    $@"{RoamingAppData}\Autodesk\ApplicationPlugins\plugin.bundle\Contents\assets\plot styles\",
    $@"{RoamingAppData}\Autodesk\ApplicationPlugins\plugin.bundle\Contents\icons\",
    $@"{RoamingAppData}\Autodesk\ApplicationPlugins\plugin.bundle\Contents\cui\",
    $@"{RoamingAppData}\Autodesk\ApplicationPlugins\plugin.bundle\Contents\opendcl\"
    ];

    try
    {
    dynamic preferences = Autodesk.AutoCAD.ApplicationServices.Application.Preferences;
    string rawPaths = preferences.Files.SupportPath;

    List<string> existingPaths = new();
    existingPaths = rawPaths.Split(';').ToList();

    bool pathsWereChanged = false;
    foreach (string str in supportPaths)
    {
    if (!existingPaths.Any(p => p.Equals(str, StringComparison.OrdinalIgnoreCase)))
    {
    existingPaths.Add(str);
    pathsWereChanged = true;
    }
    }

    if (pathsWereChanged)
    preferences.Files.SupportPath = String.Join(";", existingPaths.ToArray());

    return true;
    }
    catch (System.Exception ex)
    {
    Serilog.Log.Error("The support paths could not be set; exiting.", ex);
    return false;
    }
    }