ActionsBuilderForm.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. using Autodesk.Max;
  5. namespace Max2Babylon
  6. {
  7. public partial class ActionsBuilderForm : Form
  8. {
  9. private IINode _node = null;
  10. private HtmlDocument _document;
  11. private string _objectName;
  12. private string _propertyName = "babylon_actionsbuilder";
  13. private string _jsonResult = "";
  14. private bool isRootNode;
  15. public ActionsBuilderForm()
  16. {
  17. InitializeComponent();
  18. }
  19. private void ActionsBuilderForm_Load(object sender, EventArgs e)
  20. {
  21. if (Loader.Core.SelNodeCount > 0)
  22. {
  23. isRootNode = false;
  24. _node = Loader.Core.GetSelNode(0);
  25. }
  26. else
  27. {
  28. isRootNode = true;
  29. _node = Loader.Core.RootNode;
  30. }
  31. _objectName = _node.Name;
  32. string currentDirectory = System.IO.Directory.GetCurrentDirectory();
  33. ActionsBuilderWebView.Url = new Uri(string.Format("file:///{0}/bin/assemblies/BabylonActionsBuilder/index.html", currentDirectory), System.UriKind.Absolute);
  34. }
  35. private void ActionsBuilderWebView_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  36. {
  37. _document = ActionsBuilderWebView.Document;
  38. _document.GetElementById("ActionsBuilderObjectName").SetAttribute("value", _objectName);
  39. if (isRootNode)
  40. _document.InvokeScript("setIsScene");
  41. else
  42. _document.InvokeScript("setIsObject");
  43. _document.InvokeScript("updateObjectName");
  44. if (getProperty())
  45. {
  46. _document.GetElementById("ActionsBuilderJSON").SetAttribute("value", _jsonResult);
  47. _document.InvokeScript("updateGraphFromJSON");
  48. }
  49. }
  50. private void butOK_Click(object sender, EventArgs e)
  51. {
  52. _document.InvokeScript("updateJSONFromGraph");
  53. _jsonResult = _document.GetElementById("ActionsBuilderJSON").GetAttribute("value");
  54. setProperty();
  55. }
  56. private void setProperty()
  57. {
  58. if (_node != null)
  59. Tools.SetStringProperty(_node, _propertyName, _jsonResult);
  60. }
  61. private bool getProperty()
  62. {
  63. if (_node != null)
  64. _jsonResult = Tools.GetStringProperty(_node, _propertyName, _jsonResult);
  65. else
  66. return false;
  67. return true;
  68. }
  69. }
  70. }