home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / scripts / dag_test.javascript < prev    next >
Encoding:
Text File  |  2004-07-23  |  1.4 KB  |  49 lines

  1. //javascript
  2.  
  3. /// Boilerplate to determine which document to modify ...
  4. function FindDocument(ScriptName)
  5. {
  6.     if(Document)
  7.             return Document;
  8.     else
  9.             {
  10.                     if(Application.documents.length == 1)
  11.                             return Application.documents[0];
  12.                     else if(Application.documents.length == 0)
  13.                             Application.ui.ErrorMessage("You must have an open document to run this script!", ScriptName + ":");
  14.                     else
  15.                             Application.ui.ErrorMessage("Not sure which document to use ... try using the desired document's Document Window > Tools > Play Script.", ScriptName + ":");
  16.             }
  17.             
  18.     return null;
  19. }
  20.  
  21. document = FindDocument("dag_test.javascript");
  22. if(document)
  23.     {
  24.         // Start recording changes for undo-purposes ...
  25.         document.StartChangeSet();
  26.  
  27.         sphere1 = document.CreateObject("Sphere");
  28.         sphere2 = document.CreateObject("Sphere");
  29.  
  30.         // Link the first sphere's radius property to the second's ...
  31.         document.SetDependency(sphere1.Property("radius"), sphere2.Property("radius"));
  32.  
  33.         // Finish recording undos ...
  34.         document.FinishChangeSet("DAG Test");
  35.  
  36.         sphere1.name = "Sphere1";
  37.         sphere2.name = "Sphere2";
  38.  
  39.         sphere1.position = [-6, 0, 0];
  40.         sphere2.position = [6, 0, 0];
  41.  
  42.         document.RedrawAll();
  43.  
  44.         Application.ui.Show(sphere2);
  45.         Application.ui.Message("Modify the Sphere2 radius to see that the Sphere1 radius is linked", "dag_test:");
  46.     }
  47.  
  48.  
  49.