For future reference, if anyone is facing the same challenge, @AlanRynne’s answer was very helpful in coming up with the solution. Thanks Alan.
I’m not sure I implemented it correctly (?) but using the KitManager seems to work for machines with Speckle and for machines without Speckle.
Here’s the code for the initiation of our Speckle Controller ( / Connector) within our larger plugin.
public SpeckleController()
{
IsInitialised = Task.Run(() => Initialize()).Result;
}
private Task<bool> Initialize()
{
// This function initializes our Speckle Controller ("connector")
// It tries to initialize the KitManager from a specific location on the user's machine
// And if that fails, we assume Speckle is already loaded and there's no reason to load kits and converters once more
var thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
thisAssemblyPath = Path.GetDirectoryName(thisAssemblyPath);
// THIS IS THE PATH OF OUR OWN DEPLOYMENT OF THE SPECKLE KITS, OBJECTS AND CONVERTERS DLLs
var specklePath = Path.Combine(thisAssemblyPath, "speckle");
var appName = AppSetup.AppName;
try
{
KitManager.Initialize(specklePath);
}
catch (Exception e)
{
// Looks like the KitManager is already initialized, Speckle probably installed on this machine, ignore
}
try
{
var kit = KitManager.GetKitsWithConvertersForApp(appName).First();
if (kit == null)
kit = KitManager.GetDefaultKit();
// THIS IS THE MAIN CHANGE FROM PREVIOUS VERSION OF THE CODE!
// INSTEAD OF CREATING A CONVERTER REVIT INSTANCE MANUALLY, WE HANDLE IT THROUGH THE KIT MANAGER
converter = kit.LoadConverter(appName);
}
catch (Exception e)
{
Util.HandleError(e);
return Task.FromResult(false);
}
return Task.FromResult(true);
}