示例#1
0
        // managing attachments ======================================================================================
        // attach primary or given clone to revit version
        // @handled @logs
        public static void Attach(int revitYear,
                                  PyRevitClone clone,
                                  int 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(string.Format("Engine {0} can not be used as runtime.", engineVer));
            }
        }
示例#2
0
        // managing attachments ======================================================================================
        // attach primary or given clone to revit version
        // @handled @logs
        public static void Attach(int revitYear,
                                  PyRevitClone clone,
                                  int 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));
                RevitAddons.CreateManifestFile(revitYear,
                                               PyRevitConsts.AddinFileName,
                                               PyRevitConsts.AddinName,
                                               engine.AssemblyPath,
                                               PyRevitConsts.AddinId,
                                               PyRevitConsts.AddinClassName,
                                               PyRevitConsts.VendorId,
                                               allusers: allUsers);
            }
            else
            {
                throw new PyRevitException(string.Format("Engine {0} can not be used as runtime.", engineVer));
            }
        }
示例#3
0
        PrepareAddonsDir(string revitYear, bool allUses)
        {
            int revitYearNumber = 0;

            if (int.TryParse(revitYear, out revitYearNumber))
            {
                RevitAddons.PrepareAddonPath(revitYearNumber, allUsers: allUses);
            }
        }
示例#4
0
 private void GenerateManifest()
 {
     RevitAddons.CreateManifestFile(Revit.ProductYear,
                                    Path.GetFileName(PyRevitRunnerManifestFile),
                                    "pyRevitRunner",
                                    PyRevitCloneRunner,
                                    "D49D3677-61C4-47A8-BFFF-49E6616D54C1",
                                    "PyRevitRunner.PyRevitRunnerApplication",
                                    PyRevitConsts.VendorId,
                                    addinPath: WorkingDirectory);
 }
示例#5
0
        // get all attached revit versions
        // @handled @logs
        public static List <PyRevitAttachment> GetAttachments()
        {
            var attachments = new List <PyRevitAttachment>();

            foreach (var revit in RevitProduct.ListInstalledProducts())
            {
                logger.Debug("Checking attachment to Revit \"{0}\"", revit.Version);
                var userManifest     = RevitAddons.GetAttachedManifest(PyRevitConsts.AddinName, revit.ProductYear, allUsers: false);
                var allUsersManifest = RevitAddons.GetAttachedManifest(PyRevitConsts.AddinName, revit.ProductYear, allUsers: true);

                PyRevitAttachment attachment = null;
                if (allUsersManifest != null)
                {
                    logger.Debug("pyRevit (All Users) is attached to Revit \"{0}\"", revit.Version);
                    attachment = new PyRevitAttachment(allUsersManifest, revit, PyRevitAttachmentType.AllUsers);
                }
                else if (userManifest != null)
                {
                    logger.Debug("pyRevit (Current User) is attached to Revit \"{0}\"", revit.Version);
                    attachment = new PyRevitAttachment(userManifest, revit, PyRevitAttachmentType.CurrentUser);
                }

                // verify attachment has found
                if (attachment != null)
                {
                    // try to find clone in registered clones
                    foreach (var clone in PyRevitClones.GetRegisteredClones())
                    {
                        if (attachment.Clone != null && attachment.Clone.ClonePath.Contains(clone.ClonePath))
                        {
                            attachment.SetClone(clone);
                            break;
                        }
                    }

                    attachments.Add(attachment);
                }
                else
                {
                    logger.Debug("No attachment found for Revit \"{0}\"", revit.Version);
                }
            }

            return(attachments);
        }
示例#6
0
 // detach from revit version
 // @handled @logs
 public static void Detach(int revitYear, bool currentAndAllUsers = false)
 {
     logger.Debug("Detaching from Revit {0}", revitYear);
     RevitAddons.RemoveManifestFile(revitYear, PyRevitConsts.AddinName, currentAndAllUsers: currentAndAllUsers);
 }
示例#7
0
 // detach from revit version
 // @handled @logs
 public static void Detach(int revitYear)
 {
     logger.Debug("Detaching from Revit {0}", revitYear);
     RevitAddons.RemoveManifestFile(revitYear, PyRevitConsts.AddinName);
 }