7 Replies Latest reply on Sep 1, 2008 1:38 AM by (SomeDude)


      How do I create a Gradient? Does it require more than a Rectangle object? Does it requre a Swatch? Is there some example code of this?

      Thanks in advance.
        • 1. Re: Gradient
          (SomeDude) Level 1
          Using CS2 & Windows COM (C#).
          I would like to draw a gradient rectangle. Can I do this with a only the Rectangle object, or do I need any other objects?
          • 2. Re: Gradient
            Level 1
            You mean a rectangle with a gradient fill?

            There is no such thing as a "gradient rectangle".

            If the gradient exists as a swatch, then set the fill color of the rectangle to the gradient swatch.

            • 3. Re: Gradient
              (SomeDude) Level 1
              1. How do I create a gradient swatch?

              2. What are the methods on in the Recangle class: GradientFillAngle, GradientFillLength & GradientFillStart used for? Are they useful for something, or is the gradient fully controlled by the swatch?
              • 4. Re: Gradient
                Kasyan Servetsky Level 5
                Hi SomeDude,

                Here is an example; I hope it will help you.
                If you need more control, see GradientStop and Gradient objects in OMV.
                var myDoc = app.activeDocument;
                var myColor1 = myDoc.colors.add({name:"Color 1", colorValue:[100, 0, 30, 0]});
                var myColor2 = myDoc.colors.add({name:"Color 2", colorValue:[0, 20, 100, 0]});
                var myColor3 = myDoc.colors.add({name:"Color 3", colorValue:[0, 10, 50, 0]});
                var myColor4 = myDoc.colors.add({name:"Color 4", colorValue:[0, 80, 10, 0]});
                var myGradient = myDoc.gradients.add({name:"My New Gradient Swatch", type:GradientType.LINEAR});
                myGradient.gradientStops[0].stopColor = myColor1;
                myGradient.gradientStops[1].stopColor = myColor2;
                myGradient.gradientStops.add({location:25, stopColor:myColor3});
                myGradient.gradientStops.add({location:75, stopColor:myColor4});
                var myRec = myDoc.rectangles.add({geometricBounds:[10, 20, 110, 120]});
                myRec.fillColor = myGradient;
                • 5. Re: Gradient
                  Kasyan Servetsky Level 5
                  Now question #2:
                  gradientFillAngle The angle of a linear gradient applied to the fill of the Rectangle. (Range: -180 to 180)
                  gradientFillLength The length (for a linear gradient) or radius (for a radial gradient) applied to the fill of the Rectangle.
                  gradientFillStart The starting point (in page coordinates) of a gradient applied to the fill of the Rectangle, in the format [x, y].

                  I suppose it's the scripting analog to the Gradient tool.
                  e.g. try to add the following lines at the end of the above script:
                  myRec.gradientFillAngle = 45;
                  myRec.gradientFillLength = 50;
                  myRec.gradientFillStart = [10, 20];
                  • 6. Re: Gradient
                    (SomeDude) Level 1
                    Syntax looks a bit different in C#, but your example got me in the right course.

                    • 7. Re: Gradient
                      (SomeDude) Level 1