示例#1
0
        public static PyRevitRunnerExecEnv Run(PyRevitAttachment attachment,
                                               string scriptPath,
                                               IEnumerable <string> modelPaths,
                                               PyRevitRunnerOptions opts = null)
        {
            var product   = attachment.Product;
            var clone     = attachment.Clone;
            var engineVer = attachment.Engine != null ? attachment.Engine.Version : 0;

            logger.Debug("Running script: \"{0}\"", scriptPath);
            logger.Debug("With: {0}", product);
            logger.Debug("Using: {0}", clone);
            logger.Debug("On Engine: {0}", engineVer);

            // setup the execution environment
            if (opts is null)
            {
                opts = new PyRevitRunnerOptions();
            }

            var execEnv = new PyRevitRunnerExecEnv(attachment, scriptPath, modelPaths);

            // purge files if requested
            if (opts.ImportPath != null)
            {
                execEnv.CopyExistingAddons(opts.ImportPath);
            }

            // run the process
            ProcessStartInfo revitProcessInfo = new ProcessStartInfo(product.ExecutiveLocation)
            {
                Arguments        = execEnv.JournalFile,
                WorkingDirectory = execEnv.WorkingDirectory,
                UseShellExecute  = false,
                CreateNoWindow   = true
            };

            logger.Debug("Running Revit in playback mode with journal: \"{0}\"", execEnv.JournalFile);
            var revitProcess = Process.Start(revitProcessInfo);

            revitProcess.WaitForExit();

            // purge files if requested
            if (opts.PurgeTempFiles)
            {
                execEnv.Purge();
            }

            return(execEnv);
        }
示例#2
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);
        }
示例#3
0
        public PyRevitRunnerExecEnv(PyRevitAttachment attachment, string script, IEnumerable <string> modelPaths)
        {
            Attachment = attachment;
            Script     = script;
            ModelPaths = modelPaths;

            // check if clone is compatible
            if (!CommonUtils.VerifyFile(PyRevitCloneRunner))
            {
                throw new PyRevitException("Clone does not have Run feature. Update your clone to latest.");
            }

            // generate unique id for this execution
            ExecutionId = Guid.NewGuid().ToString();
            // setup working dir
            WorkingDirectory = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), ExecutionId);
            CommonUtils.EnsurePath(WorkingDirectory);

            // generate journal and manifest file
            GenerateJournal();
            GenerateManifest();
        }
示例#4
0
 // detach pyrevit attachment
 // @handled @logs
 public static void Detach(PyRevitAttachment attachment)
 {
     logger.Debug("Detaching from Revit {0}", attachment.Product.ProductYear);
     Detach(attachment.Product.ProductYear);
 }
示例#5
0
 // detach pyrevit attachment
 // @handled @logs
 public static void Detach(PyRevitAttachment attachment, bool currentAndAllUsers = false)
 {
     logger.Debug("Detaching from Revit {0}", attachment.Product.ProductYear);
     Detach(attachment.Product.ProductYear, currentAndAllUsers);
 }