// attach clone to all installed revit versions // @handled @logs public static void AttachToAll(PyRevitClone clone, PyRevitEngineVersion engineVer, bool allUsers = false) { foreach (var revit in RevitProduct.ListInstalledProducts()) { Attach(revit.ProductYear, clone, engineVer: engineVer, allUsers: allUsers); } }
// get engine from clone path // returns latest with default engineVer value // @handled @logs public static PyRevitEngine GetEngine(string clonePath, PyRevitEngineVersion engineVer) { logger.Debug("Finding engine \"{0}\" path in \"{1}\"", engineVer, clonePath); if (engineVer == PyRevitEngineVersion.Default) { var defaultEng = GetDefaultEngine(clonePath); if (defaultEng is null) { throw new PyRevitException("Can not find default engine"); } return(defaultEng); } else { var engines = GetEngines(clonePath).Where(x => x.Version == engineVer); var engineCount = engines.Count(); if (engineCount == 0) { throw new PyRevitException($"Can not find engine with specified version \"{engineVer.Version}\" is found"); } else if (engineCount > 1) { throw new PyRevitException($"More than one engine with specified version \"{engineVer.Version}\" is found"); } return(engines.First()); } }
// managing attachments ====================================================================================== // attach primary or given clone to revit version // @handled @logs public static void Attach(int revitYear, PyRevitClone clone, PyRevitEngineVersion engineVer, bool allUsers = false, bool force = false) { // make the addin manifest file var engine = clone.GetEngine(engineVer); if (engine.Runtime) { logger.Debug(string.Format("Attaching Clone \"{0}\" @ \"{1}\" to Revit {2}", clone.Name, clone.ClonePath, revitYear)); // remove existing attachments first // this is critical as there might be invalid attachments to expired clones Detach(revitYear, currentAndAllUsers: true); // now recreate attachment RevitAddons.CreateManifestFile( revitYear, PyRevitConsts.AddinFileName, PyRevitConsts.AddinName, engine.AssemblyPath, PyRevitConsts.AddinId, PyRevitConsts.AddinClassName, PyRevitConsts.VendorId, allusers: allUsers ); } else { throw new PyRevitException($"Engine {engineVer} can not be used as runtime."); } }
public PyRevitEngine GetEngine(PyRevitEngineVersion engineVer) => GetEngine(ClonePath, engineVer: engineVer);