예제 #1
0
        private static string GetBundleTemplate(PyRevitBundleTypes bundleType, string templatesDir = null)
        {
            templatesDir = templatesDir != null ? templatesDir : PyRevitCLIAppCmds.GetTemplatesPath();
            if (CommonUtils.VerifyPath(templatesDir))
            {
                var bundleTempPath =
                    Path.Combine(templatesDir, "template" + PyRevitBundle.GetBundleDirExt(bundleType));
                if (CommonUtils.VerifyPath(bundleTempPath))
                {
                    return(bundleTempPath);
                }
            }
            else
            {
                throw new pyRevitException(
                          string.Format("Templates directory does not exist at \"{0}\"", templatesDir)
                          );
            }

            return(null);
        }
예제 #2
0
        InitBundle(bool tab, bool panel, bool panelopt, bool pull, bool split,
                   bool splitpush, bool push, bool smart, bool command,
                   string bundleName, string templatesDir, bool useTemplate)
        {
            // determine bundle
            PyRevitBundleTypes bundleType = PyRevitBundleTypes.Unknown;

            if (tab)
            {
                bundleType = PyRevitBundleTypes.Tab;
            }
            else if (panel)
            {
                bundleType = PyRevitBundleTypes.Panel;
            }
            else if (panelopt)
            {
                bundleType = PyRevitBundleTypes.PanelButton;
            }
            else if (pull)
            {
                bundleType = PyRevitBundleTypes.PullDown;
            }
            else if (split)
            {
                bundleType = PyRevitBundleTypes.SplitButton;
            }
            else if (splitpush)
            {
                bundleType = PyRevitBundleTypes.SplitPushButton;
            }
            else if (push)
            {
                bundleType = PyRevitBundleTypes.PushButton;
            }
            else if (smart)
            {
                bundleType = PyRevitBundleTypes.SmartButton;
            }
            else if (command)
            {
                bundleType = PyRevitBundleTypes.NoButton;
            }

            if (bundleType != PyRevitBundleTypes.Unknown)
            {
                if (bundleName != null)
                {
                    var pwd = Directory.GetCurrentDirectory();

                    if (CommonUtils.EnsureFileNameIsUnique(pwd, bundleName))
                    {
                        var bundleDir = Path.Combine(
                            pwd,
                            string.Format("{0}{1}", bundleName, PyRevitBundle.GetBundleDirExt(bundleType))
                            );

                        var bundleTempDir = GetBundleTemplate(bundleType, templatesDir: templatesDir);
                        if (useTemplate && bundleTempDir != null)
                        {
                            CommonUtils.CopyDirectory(bundleTempDir, bundleDir);
                            Console.WriteLine(
                                string.Format("Bundle directory created from template: \"{0}\"", bundleDir)
                                );
                        }
                        else
                        {
                            if (!Directory.Exists(bundleDir))
                            {
                                var dinfo = Directory.CreateDirectory(bundleDir);
                                Console.WriteLine(string.Format("Bundle directory created: \"{0}\"", bundleDir));
                            }
                            else
                            {
                                throw new pyRevitException("Directory already exists.");
                            }
                        }
                    }
                    else
                    {
                        throw new pyRevitException(
                                  string.Format("Another bundle with name \"{0}\" already exists.", bundleName)
                                  );
                    }
                }
            }
        }