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.
AutoCAD Ensure Support Paths C#
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment