Exemplo n.º 1
0
        InitExtension(bool ui, bool lib, bool run, string extensionName, string templatesDir, bool useTemplate)
        {
            PyRevitExtensionTypes extType = PyRevitExtensionTypes.Unknown;

            if (ui)
            {
                extType = PyRevitExtensionTypes.UIExtension;
            }
            else if (lib)
            {
                extType = PyRevitExtensionTypes.LibraryExtension;
            }
            else if (run)
            {
                extType = PyRevitExtensionTypes.RunnerExtension;
            }


            var extDirPostfix = PyRevitExtension.GetExtensionDirExt(extType);

            if (extensionName != null)
            {
                var pwd = Directory.GetCurrentDirectory();

                if (CommonUtils.EnsureFileNameIsUnique(pwd, extensionName))
                {
                    var extDir = Path.Combine(
                        pwd,
                        string.Format("{0}{1}", extensionName, extDirPostfix)
                        );

                    var extTemplateDir = GetExtensionTemplate(extType, templatesDir: templatesDir);
                    if (useTemplate && extTemplateDir != null)
                    {
                        CommonUtils.CopyDirectory(extTemplateDir, extDir);
                        Console.WriteLine(
                            string.Format("Extension directory created from template: \"{0}\"", extDir)
                            );
                    }
                    else
                    {
                        if (!Directory.Exists(extDir))
                        {
                            var dinfo = Directory.CreateDirectory(extDir);
                            Console.WriteLine(string.Format("{0} directory created: \"{1}\"", extType, extDir));
                        }
                        else
                        {
                            throw new pyRevitException("Directory already exists.");
                        }
                    }
                }
                else
                {
                    throw new pyRevitException(
                              string.Format("Another extension with name \"{0}\" already exists.", extensionName)
                              );
                }
            }
        }
Exemplo n.º 2
0
        // private extensions and bundles
        private static string GetExtensionTemplate(PyRevitExtensionTypes extType, string templatesDir = null)
        {
            templatesDir = templatesDir != null ? templatesDir : PyRevitCLIAppCmds.GetTemplatesPath();
            if (CommonUtils.VerifyPath(templatesDir))
            {
                var extTempPath =
                    Path.Combine(templatesDir, "template" + PyRevitExtension.GetExtensionDirExt(extType));
                if (CommonUtils.VerifyPath(extTempPath))
                {
                    return(extTempPath);
                }
            }
            else
            {
                throw new pyRevitException(
                          string.Format("Templates directory does not exist at \"{0}\"", templatesDir)
                          );
            }


            return(null);
        }