home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / scripts / dag_test2.javascript < prev    next >
Encoding:
Text File  |  2004-07-23  |  1.7 KB  |  57 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_test2");
  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.         channel = document.CreateObject("ScalarBezierChannel");
  30.  
  31.         // Finish recording undos ...
  32.         document.FinishChangeSet("DAG Test 2");
  33.  
  34.         // Link the spheres' radii to the channel ...
  35.         document.SetDependency(channel.Property("input"), document.Object("TimeSource").Property("time"));
  36.         document.SetDependency(sphere1.Property("radius"), channel.Property("output"));
  37.         document.SetDependency(sphere2.Property("radius"), channel.Property("output"));
  38.  
  39.         sphere1.name = "Sphere1";
  40.         sphere2.name = "Sphere2";
  41.         channel.name = "Radii";
  42.  
  43.         sphere1.position = [-6, 0, 0];
  44.         sphere2.position = [6, 0, 0];
  45.         var curve = channel.curve;
  46.         curve.control_points[0][1] = 5.0;
  47.  
  48.         channel.curve = curve;
  49.  
  50.         document.RedrawAll();
  51.  
  52.         Application.ui.Show(channel);
  53.         Application.ui.Message("Modify the channel radius to see that both spheres' radii are linked", "dag_test2:");
  54.     }
  55.  
  56.  
  57.