Beispiel #1
0
        private void PopulateCustomCommands()
        {
            var path        = Path.Combine(ProgramUtils.PathToAssembly(Assembly.GetExecutingAssembly()), "Scripts");
            var scriptFiles = Directory.GetFiles(path, "*.cs");

            foreach (var script in scriptFiles)
            {
                var scriptName = Path.GetFileName(script);
                Context.UIService.AddPromptCommand(new CommandInputItem(
                                                       new PromptDelegateCommand(scriptName, () => {
                    try {
                        ScriptEngine.ExecuteFile(script);
                    } catch (Exception e) {
                        ModalDialog.ShowException(e, e.GetType().ToString());
                    }
                }, "-" + scriptName), null));
            }
        }
Beispiel #2
0
        private void OnObjectEntered(object o, EventArgs args)
        {
            if (!IsHookEnabled)
            {
                return;
            }

            var name = o.ToString();

            if (name.Contains("_TEMP_"))
            {
                return;
            }
            var version       = Context.CurrentProjectVersion;
            var surfaceObject = version.GeometryManager.GetSurfaceObject(name);

            if (surfaceObject == null)
            {
                return;
            }
            string scriptName = "";
            //TODO better way to check that object is just created
            var isNew = DateTime.Now - surfaceObject.Date < TimeSpan.FromSeconds(3);

            if (isNew)
            {
                //Begin invoke, seems that with big models the Entered event comes too early.
                Application.Current.MainWindow.Dispatcher.BeginInvoke(new Action(() => {
                    try {
                        var path        = Path.Combine(ProgramUtils.PathToAssembly(Assembly.GetExecutingAssembly()), "Hooks");
                        var scriptFiles = Directory.GetFiles(path, "*.cs");
                        foreach (var script in scriptFiles)
                        {
                            scriptName = Path.GetFileName(script);
                            var hook   = ScriptEngine.ExecuteFile <IHook>(script);
                            hook.Run(version, name);
                        }
                    } catch (Exception e) {
                        ModalDialog.ShowException(e, "Hook error " + scriptName);
                    }
                }));
            }
        }