13 Replies Latest reply on Dec 14, 2011 11:13 PM by John Hawkinson

    Outline a stroke?  I want to put a stroke on it.

    Stix Hart Level 5

      I want to put a stroke on a stroke, can I convert it into an object somehow I've never heard of before or do I have to redraw it as one?

       

      Having typed that I can't help but think: Yo dawg, I heard you liked strokes so I put a stroke on your stroke so you can stroke it...

       

      xzibit-happy.jpg

        • 1. Re: Outline a stroke?  I want to put a stroke on it.
          Peter Spier Most Valuable Participant (Moderator)

          In ID the closest you can come is a stoke of type stripe where you define only one stripe of wahtever proportion to the other color, the assign one color to the stroke and a second color to the gap.

          1 person found this helpful
          • 2. Re: Outline a stroke?  I want to put a stroke on it.
            Stix Hart Level 5

            Yeah, I hadn't actually thought of that but that won't achieve what I'm wanting.  It's not the first time I've wanted to do it, Indesign can see the strokes shape on the page, you'd think there would be some way to turn it into an object with 4 corner points...

            • 3. Re: Outline a stroke?  I want to put a stroke on it.
              Stix Hart Level 5

              I'll illustrate it in case anyone has any brainwaves, I want to change fig. 1 into fig. 2:

               

              1.png

               

              2.png

              • 4. Re: Outline a stroke?  I want to put a stroke on it.
                Peter Spier Most Valuable Participant (Moderator)

                OK, can you explain the differnce, there? Is this like Illustrator's "expand appearance" function?

                 

                I'm not sure why you aren't just drawing the shape?

                • 5. Re: Outline a stroke?  I want to put a stroke on it.
                  [Jongware] Most Valuable Participant

                  Straight lines are a breeze. Multi-segment ones (still straight) pose more of a challenge, and curved ones are a math nightmare. And then there are stroke styles ...

                   

                  I suppose you could try what the transparency flattener does in that case.

                   

                  Here is a Javascript for straight, 2-point lines only:

                   

                  //DESCRIPTION:Expand Straight Line into Rectangle// A Jongware Script 14-Dec-2011
                  if (app.version < "6")
                      outlineLine();
                  else
                      app.doScript(outlineLine, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand Straight Line");
                  function outlineLine()
                  {
                  if (app.documents.length > 0 && app.selection.length == 1 &&
                    app.selection[0] instanceof GraphicLine && app.selection[0].paths.length == 1 &&
                    app.selection[0].paths[0].pathPoints.length == 2)
                  {
                    obj = app.selection[0];
                    settings = [ app.activeDocument.viewPreferences.horizontalMeasurementUnits,
                     app.activeDocument.viewPreferences.verticalMeasurementUnits ];
                    app.activeDocument.viewPreferences.properties = { horizontalMeasurementUnits:MeasurementUnits.POINTS,
                     verticalMeasurementUnits:MeasurementUnits.POINTS };
                    // 1. get End Points
                    pA = obj.paths[0].pathPoints[0].anchor;
                    pB = obj.paths[0].pathPoints[1].anchor;
                    // 2. get Angle
                    if (Math.abs(pA[1] - pB[1]) < 0.01)
                     angle = 0;
                    else
                     angle = Math.atan (-(pA[0] - pB[0])/(pA[1] - pB[1]));
                  // angle = angle*180/Math.PI;
                    // 3. get Thickness
                    thickness = app.selection[0].strokeWeight/2;
                    // 4. make Rectangle
                    obj.paths[0].entirePath = [
                     [ pA[0]+Math.cos(angle)*thickness, pA[1]+Math.sin(angle)*thickness],
                     [ pA[0]-Math.cos(angle)*thickness, pA[1]-Math.sin(angle)*thickness],
                     [ pB[0]-Math.cos(angle)*thickness, pB[1]-Math.sin(angle)*thickness],
                     [ pB[0]+Math.cos(angle)*thickness, pB[1]+Math.sin(angle)*thickness]
                     ];
                    obj.paths[0].pathType = PathType.CLOSED_PATH;
                    // 5. cleanup
                    obj.fillColor = obj.strokeColor;
                    obj.fillTint = obj.strokeTint;
                    obj.strokeWeight = 0;
                    app.activeDocument.viewPreferences.properties = { horizontalMeasurementUnits:settings[0],
                     verticalMeasurementUnits:settings[1] };
                  }
                  }
                  
                  • 6. Re: Outline a stroke?  I want to put a stroke on it.
                    Eugene Tyson Adobe Community Professional & MVP

                    The only difference there is that one is a line and one is a frame?

                     

                    Can you elaborate further?

                     

                    If it's going under text - then you can include that in the Paragraph Style - using Rule Above and Below and adjusting the Offset - and type of stroke etc.

                     

                    If it's for words in a paragraph, then you can create a Character Style with an Underline and a Strikethrough - again changing the offsets and different types of Rules and thickness etc.

                    • 7. Re: Outline a stroke?  I want to put a stroke on it.
                      Stix Hart Level 5

                      @ Jongware; ah scripting!  That does exactly what I wanted and does it nearly perfectly too, thank you very much.  The odd thng is that if a stroke is perfectly horizontal it creates an object with the same length but no height.  At any other angle it seems to work fine.  I note that in the undo menu it calls it "Expand Straight Line", is that a command only available through scripting?

                       

                      @ Peter & Eugene, yes the only difference is that fig. 2 is a frame, I did draw it, I just want some way to speed it up.  I'm not familiar with that Illustrator function, it well may be.

                      • 8. Re: Outline a stroke?  I want to put a stroke on it.
                        macinbytes Level 4

                        Illustrator has at least two ways to do it.

                         

                        Object > Path > Outline Stroke

                        Object > Expand Apperance

                         

                        Love the xzibit illustration for that.

                        • 9. Re: Outline a stroke?  I want to put a stroke on it.
                          [Jongware] Most Valuable Participant

                          Oops -- I thought I had my math all worked out. No worries I'll look into this a.s.a.p.

                          1 person found this helpful
                          • 10. Re: Outline a stroke?  I want to put a stroke on it.
                            [Jongware] Most Valuable Participant

                            (That took some effort. For some reason CS4 can alter a Graphic Line into a Rectangle or even a Polygon at will -- even right after an Undo! That set me back for several minutes. It's a curious echo of JS CS5.5] How to get the constructor name of an oval? and quite possibly related. Rather than solve, I circumvented the issue.)

                             

                            Here's an improved version, all it finally needed was to set the angle for straight lines to π/2 ... Paint me emberassed, shoulda done that right first time around.

                             

                            //DESCRIPTION:Expand Straight Line into Rectangle
                            // A Jongware Script 14-Dec-2011
                            if (app.version < "6")
                                outlineLine();
                            else
                                app.doScript(outlineLine, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand Straight Line");
                            function outlineLine()
                            {
                            if (app.documents.length > 0 && app.selection.length == 1 &&
                              app.selection[0].paths.length == 1 &&
                              app.selection[0].paths[0].pathPoints.length == 2)
                            {
                              obj = app.selection[0];
                              settings = [ app.activeDocument.viewPreferences.horizontalMeasurementUnits,
                               app.activeDocument.viewPreferences.verticalMeasurementUnits ];
                              app.activeDocument.viewPreferences.properties = { horizontalMeasurementUnits:MeasurementUnits.POINTS,
                               verticalMeasurementUnits:MeasurementUnits.POINTS };
                              // 1. get End Points
                              pA = obj.paths[0].pathPoints[0].anchor;
                              pB = obj.paths[0].pathPoints[1].anchor;
                              // 2. get Angle
                              if (Math.abs(pA[1] - pB[1]) < 0.01)
                               angle = Math.PI/2;
                              else
                               angle = Math.atan (-(pA[0] - pB[0])/(pA[1] - pB[1]));
                            // angle = angle*180/Math.PI;
                              // 3. get Thickness
                              thickness = app.selection[0].strokeWeight/2;
                              // 4. make Rectangle
                              obj.paths[0].entirePath = [
                               [ pA[0]+Math.cos(angle)*thickness, pA[1]+Math.sin(angle)*thickness],
                               [ pA[0]-Math.cos(angle)*thickness, pA[1]-Math.sin(angle)*thickness],
                               [ pB[0]-Math.cos(angle)*thickness, pB[1]-Math.sin(angle)*thickness],
                               [ pB[0]+Math.cos(angle)*thickness, pB[1]+Math.sin(angle)*thickness]
                               ];
                              obj.paths[0].pathType = PathType.CLOSED_PATH;
                              // 5. cleanup
                              obj.fillColor = obj.strokeColor;
                              obj.fillTint = obj.strokeTint;
                              obj.strokeWeight = 0;
                              app.activeDocument.viewPreferences.properties = { horizontalMeasurementUnits:settings[0],
                               verticalMeasurementUnits:settings[1] };
                            } else alert ("No document or no selection or something else amiss");
                            }
                            
                            1 person found this helpful
                            • 11. Re: Outline a stroke?  I want to put a stroke on it.
                              [Jongware] Most Valuable Participant

                              You may consider yourself Officially Pimped now.

                              1 person found this helpful
                              • 12. Re: Outline a stroke?  I want to put a stroke on it.
                                John Hawkinson Level 5

                                The script is all well and good, but what's wrong with just doing it in Illustrator?

                                • 13. Re: Outline a stroke?  I want to put a stroke on it.
                                  John Hawkinson Level 5

                                  I note that in the undo menu it calls it "Expand Straight Line", is that a command only available through scripting?

                                  Not really. Jongware has wrapped his entire script in one function, outlineLine(), and called that function as a single undo entity:

                                  app.doScript(outlineLine, ScriptLanguage.JAVASCRIPT,

                                    undefined, UndoModes.ENTIRE_SCRIPT, "Expand Straight Line");

                                  So it just really means, "the whole script."