23 Replies Latest reply on Dec 22, 2015 5:22 PM by Qwertyfly...

    How to add multiple strokes with offset path?

    arteangelus

      Hello,

       

      I would like to create a script that can create multiple strokes with offset path ( incremental or decremental (user will enter value) )

      Is it possible to add multiple strokes? I could not find any example in scripting reference or elsewhere.

      Note: Blending does not give exactly the same results because sometimes especially when you're dealing with font outline paths it is being blended in wrong a way.

      I'd be glad if someone give at least the main command in for loop.  I would try to do rest and will be sharing here as I find the solution.

      Thanks,

      Best Regards.

       

      question.jpg

        • 1. Re: How to add multiple strokes with offset path?
          Silly-V Adobe Community Professional

          You can try to apply multiple graphic styles. I am not sure and have no time to test, but you should be able to make a graphic style of a stroke with an offset path in it. Then you can use the script to apply this graphic style using the graphicStyle.mergeTo() method- notice that artStyles in the OMV documentation are actually mislabelled as they are really "graphicStyles". Let me know if it works!

          • 2. Re: How to add multiple strokes with offset path?
            arteangelus Level 1

            I'm still searching, in one article it is written that;

            " Unfortunately, the documentation does say; Scripts cannot create new graphic styles."

            On the other hand I guess I have found a solution ;

            app.executeMenuCommand('Adobe New Stroke Shortcut');
            

            command creates new stroke. Now time to find offset then collect them inside of a loop.

            Thanks.

            • 3. Re: How to add multiple strokes with offset path?
              arteangelus Level 1

              Then I have found ;

              app.executeMenuCommand('Live Offset Path');
              

               

              for offset;

              But I now I could not find how to add any variable, like do offset for +2 px ...

               

              I have found a solution in this article https://forums.adobe.com/thread/1405101?start=0&tstart=0

              by Qwertyfly... but I tried with my action it gives an error.

              I have opened but aia file then added ' both in the begining and at the end of each line similar to his example. But it's not working. I guess I'm missing something.

              Does anyone have an idea?

              Thank you,

              Best Regards.

              • 4. Re: How to add multiple strokes with offset path?
                Silly-V Adobe Community Professional

                Try the new solution which is discovered and described here:

                PageItem.applyEffect(LiveEffectXML)

                 

                You can apply new effects, but I am not sure how they will be applied. Are they going to add the effect to the new stroke, or add the effect to the parent shape, which will not achieve your goal?

                • 5. Re: How to add multiple strokes with offset path?
                  arteangelus Level 1

                  Hi Silly-V;

                  I got it, made some tests and working but except of applyEffect

                  I could not find how to add stroke (offset path should be under stroke in appearance panel)

                  I guess applyEffect command only works with effects as its name says:)

                   

                  Working ;

                  //xmlstring = '<LiveEffect name="Live Offset Path"><Dict data="R mlim '+miterlimitvalue + ' R ofst ' + offsetvalue + ' I jntp ' + jointype + '"/></LiveEffect></ai:Stroke>';

                   

                  Not Working;

                  xmlstring = '<stroke><SolidColorStroke caps="none" joints="miter" miterLimit="10"/></stroke>';

                   

                  What I'm trying to do is create a for loop;

                  And script should create stroke with offset path 2 px, then another stroke with offset path 4 px and goes on according to user's input value, do you think it's possible?

                  Thanks.

                  Regards.

                  • 6. Re: How to add multiple strokes with offset path?
                    Silly-V Adobe Community Professional

                    Okay, I'm going to try and help test it. First, your xml strings are wrong, 1st one and 2nd one.

                     

                    Here is the correct syntax:

                        var offsetEffectXML = '<LiveEffect name="Adobe Offset Path"><Dict data="R mlim '+ 4 + ' R ofst ' + 4 + ' I jntp 0"/></LiveEffect>';

                     

                    So I tried to first add a new stroke and then apply this effect, but it did not work- because the appearance panel focus , even if it was materialized during this command, does not remain for the live effect to get attached to the stroke- it rather gets attached to the general art piece, which is useless.

                     

                    However, if you were to copy and duplicate your target path item, the visual appearance of this would be achieved- although it will not be a single path with many strokes.


                    I tried to do a loop where this is applied to the path which repeatedly is nested within new groups, but not only did this effect not produce desired results as the effect was not applied to stroke (how I found out about this), but it took a very long time by the 10th iteration to render this simple effect, due to the many nestings.


                    It is also possible to have an existing graphic style which can be applied, I tried this with the group method and it did work. Unfortunately, exactly because of the limitation of not being able to place an effect into an appearance stroke via script, the graphic style has to be pre-made.

                     

                    This worked, but relies on existing style and grouping. Grouping is necessary so that the style is not prevented from being applied due to existing instance of this style already being present on the target item.

                        var doc = app.activeDocument;

                        var p = doc.pageItems[0];

                        for(var i=0; i< 3; i++){

                            var newGroup = doc.groupItems.add();

                            newGroup.name = "Parent Group_" + i;

                            p.move(newGroup, ElementPlacement.INSIDE);

                            p = newGroup;

                            doc.graphicStyles['MyStyle'].applyTo(p);

                        }

                     

                    I also tried to mess with compounding an offset path stroke effect by using a transform effect in a combination, but it doesn't work that way, of course.

                     

                    There's probably some strange way yet to be discovered which could deal with this issue, including maybe some way to apply the effect to a stroke..

                    • 7. Re: How to add multiple strokes with offset path?
                      arteangelus Level 1

                      Thank you,

                      Yes that technique works (but really slow). But still I might prefer to use xml way. I could not make it work since I couldn't find any command like add stroke, I guess one solution would be creating an action with script apply it. I remember I have seen one example in forum. I even tried to make it with that but was unsuccessful for embedding aia xml structure into javascript. ( I wish there would be a script to do that...like xtool's photoshop atn to javascript converter script)

                      Please let me know if you find any solution.

                      And I'll be sharing the script that embeds actions if I can be successful.

                       

                      Thank you again...

                      • 8. Re: How to add multiple strokes with offset path?
                        Qwertyfly... Level 4

                        I have not read this thread properly so am not 100% on topic.
                        this link is to a recent script I wrote that has a more complete function for adding an action via script.
                        it's a bit more robust then the one shown in the above link.

                        if you need a hand getting any of that to work let me know.

                        need to write a script to count objects/brush-objects on a layer

                        • 9. Re: How to add multiple strokes with offset path?
                          arteangelus Level 1

                          Hello,

                          Thank you for your help;

                          I have found japan script and tried to adapt it but it gives error for load actions. Where am I doing wrong?

                          (I have created one action then saved it, opened aia copied text and added " ' " both at beginning and at end with commas.

                          Original Source : [Illustrator]Create, load and execute action all by JS only · GitHub

                           

                          #target illustrator
                          var doc = app.activeDocument;  
                          var sel = doc.selection;  
                          doc.selection = null; 
                          var action = "Offset Path";  
                          var set = "OffsetPath";  
                          var currentInteractionLevel = app.userInteractionLevel;  
                          app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;  
                          
                          
                          var actionStr = [
                                          '/version 3',
                          '/name [ ' + set.length,
                                  ascii2Hex(set),
                                  ']',
                          '/isOpen 1',
                          '/actionCount 1',
                          '/action-1 {',
                          '/name [ ' + action.length,
                                  ascii2Hex(action),
                                  ']',
                          ' /keyIndex 0',
                          ' /colorIndex 0',
                          ' /isOpen 1',
                          ' /eventCount 2',
                          ' /event-1 {',
                          ' /useRulersIn1stQuadrant 0',
                          ' /internalName (ai_plugin_appearance)',
                          ' /localizedName [ 10',
                          ' 417070656172616e6365',
                          ' ]',
                          ' /isOpen 0',
                          ' /isOn 1',
                          ' /hasDialog 0',
                          ' /parameterCount 1',
                          ' /parameter-1 {',
                          ' /key 1835363957',
                          ' /showInPalette -1',
                          ' /type (enumerated)',
                          ' /name [ 14',
                          ' 416464204e6577205374726f6b65',
                          ' ]',
                          ' /value 2',
                          ' }',
                          ' }',
                          ' /event-2 {',
                          ' /useRulersIn1stQuadrant 0',
                          ' /internalName (adobe_commandManager)',
                          ' /localizedName [ 16',
                          ' ]',
                          ' 416363657373204d656e75204974656d',
                          ' /isOpen 0',
                          ' /isOn 1',
                          ' /hasDialog 0',
                          ' /parameterCount 3',
                          ' /parameter-1 {',
                          ' /key 1769238125',
                          ' /showInPalette -1',
                          ' /type (ustring)',
                          ' /value [ 16',
                          ' 4c697665204f66667365742050617468',
                          ' ]',
                          ' }',
                          ' /parameter-2 {',
                          ' /key 1818455661',
                          ' /showInPalette -1',
                          ' /type (ustring)',
                          ' /value [ 25',
                          ' 4566666563743a20506174683a204f66667365742050617468',
                          ' ]',
                          ' }',
                          ' /parameter-3 {',
                          ' /key 1668114788',
                          ' /showInPalette -1',
                          ' /type (integer)',
                          ' /value -2130705931',
                          ' }',
                          ' }',
                          '}'
                           ].join('\n');   
                          
                          
                          createAction(actionStr, set);
                          
                          app.userInteractionLevel = currentInteractionLevel;  
                              
                          function  ascii2Hex (hex) {
                              return hex.replace(/./g, function (a) {return a.charCodeAt(0).toString(16)})
                          }
                          
                          
                          function createAction (actionstrings, setname) {
                          var f = new File(action + '.aia');
                          f.open('w');
                          f.write(actionStr);
                          f.close();
                          app.loadAction(f);
                          f.remove();
                          }
                          
                          
                          
                          
                          app.doScript(action, set);
                          
                          • 10. Re: How to add multiple strokes with offset path?
                            Qwertyfly... Level 4

                            First up, big thanks to moluaple, this is where I discovered this little secret...

                             

                             

                            ok with your code there are a few things.
                            the first 3 lines will stop the script working as you need an object selected for the action to work on.

                            (delete first 3 lines of code)

                            var doc = app.activeDocument;    
                            var sel = doc.selection;    
                            doc.selection = null; 
                            
                            

                             

                            next there is a line in your action string that is not correct.

                            line 50 and 51 need to be swapped.

                            snip.JPG

                             

                            also the createAction function takes 2 variables, neither get used. this will not stop the script running but is confusing...

                             

                            lastly, as the script does not test to see if the action exists, and does not remove the action when done, it will create many copies of the same action in the actions list...

                            • 11. Re: How to add multiple strokes with offset path?
                              arteangelus Level 1

                              Thanks again Qwertyfly...

                               

                              So I tried to replace as you said; but still does not work... (I also embed createaction function inside do_script...) By the way it doesn't show any error but nothing happens. I also swapped line 50-51.

                               

                              var myAction = "OffsetPath";  
                              var mySet = "Offset Path";  
                              
                              
                                  function do_script(){  
                                      // Set your action name and the set name that it belongs to here  
                                      var myAction = "OffsetPath";  
                                      var mySet = "Offset Path";  
                                      //---------------------------------------------------------------------------------  
                                      var currentInteractionLevel = app.userInteractionLevel;  
                                      app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;  
                              
                                          var actionStr = [  
                                              '/version 3',
                              '/name [ ' + mySet.length,
                                      ascii2Hex(mySet),
                                      ']',
                              '/isOpen 1',
                              '/actionCount 1',
                              '/action-1 {',
                              '/name [ ' + myAction.length,
                                      ascii2Hex(myAction),
                                      ']',
                              ' /keyIndex 0',
                              ' /colorIndex 0',
                              ' /isOpen 1',
                              ' /eventCount 2',
                              ' /event-1 {',
                              ' /useRulersIn1stQuadrant 0',
                              ' /internalName (ai_plugin_appearance)',
                              ' /localizedName [ 10',
                              ' 417070656172616e6365',
                              ' ]',
                              ' /isOpen 0',
                              ' /isOn 1',
                              ' /hasDialog 0',
                              ' /parameterCount 1',
                              ' /parameter-1 {',
                              ' /key 1835363957',
                              ' /showInPalette -1',
                              ' /type (enumerated)',
                              ' /name [ 14',
                              ' 416464204e6577205374726f6b65',
                              ' ]',
                              ' /value 2',
                              ' }',
                              ' }',
                              ' /event-2 {',
                              ' /useRulersIn1stQuadrant 0',
                              ' /internalName (adobe_commandManager)',
                              ' /localizedName [ 16',
                              ' 416363657373204d656e75204974656d',
                              ' ]',
                              ' /isOpen 0',
                              ' /isOn 1',
                              ' /hasDialog 0',
                              ' /parameterCount 3',
                              ' /parameter-1 {',
                              ' /key 1769238125',
                              ' /showInPalette -1',
                              ' /type (ustring)',
                              ' /value [ 16',
                              ' 4c697665204f66667365742050617468',
                              ' ]',
                              ' }',
                              ' /parameter-2 {',
                              ' /key 1818455661',
                              ' /showInPalette -1',
                              ' /type (ustring)',
                              ' /value [ 25',
                              ' 4566666563743a20506174683a204f66667365742050617468',
                              ' ]',
                              ' }',
                              ' /parameter-3 {',
                              ' /key 1668114788',
                              ' /showInPalette -1',
                              ' /type (integer)',
                              ' /value -2130705931',
                              ' }',
                              ' }',
                              '}'
                                          ].join('\n');  
                                      var f = new File(mySet + myAction + '.aia');    
                                      f.open('w');    
                                      f.write(actionStr);    
                                      f.close();    
                                      app.loadAction(f);    
                                      f.remove(); 
                                          
                                      }
                              var currentInteractionLevel = app.userInteractionLevel;  
                              app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;  
                              
                              
                                
                                function  ascii2Hex (hex) {
                                  return hex.replace(/./g, function (a) {return a.charCodeAt(0).toString(16)})
                              }
                              
                              
                              app.doScript(myAction, mySet, false); 
                              
                              • 12. Re: How to add multiple strokes with offset path?
                                Qwertyfly... Level 4

                                your myAction and mySet get declared twice in different scopes which may cause confusion.

                                user interaction is in correct at end.

                                do_script function is never called.

                                file is not in a good location, add '~/' +  to the start to use user dir so you have a good chance permissions are ok.

                                 

                                this action does ask for user input, not sure why and have not had time to find out if this can be bypassed.

                                 

                                var myAction = "OffsetPath";    
                                var mySet = "Offset Path";    
                                  
                                  
                                    function do_script(){      
                                        var currentInteractionLevel = app.userInteractionLevel;    
                                        app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;    
                                  
                                            var actionStr = [    
                                                '/version 3',  
                                '/name [ ' + mySet.length,  
                                        ascii2Hex(mySet),  
                                        ']',  
                                '/isOpen 1',  
                                '/actionCount 1',  
                                '/action-1 {',  
                                '/name [ ' + myAction.length,  
                                        ascii2Hex(myAction),  
                                        ']',  
                                ' /keyIndex 0',  
                                ' /colorIndex 0',  
                                ' /isOpen 1',  
                                ' /eventCount 2',  
                                ' /event-1 {',  
                                ' /useRulersIn1stQuadrant 0',  
                                ' /internalName (ai_plugin_appearance)',  
                                ' /localizedName [ 10',  
                                ' 417070656172616e6365',  
                                ' ]',  
                                ' /isOpen 0',  
                                ' /isOn 1',  
                                ' /hasDialog 0',  
                                ' /parameterCount 1',  
                                ' /parameter-1 {',  
                                ' /key 1835363957',  
                                ' /showInPalette -1',  
                                ' /type (enumerated)',  
                                ' /name [ 14',  
                                ' 416464204e6577205374726f6b65',  
                                ' ]',  
                                ' /value 2',  
                                ' }',  
                                ' }',  
                                ' /event-2 {',  
                                ' /useRulersIn1stQuadrant 0',  
                                ' /internalName (adobe_commandManager)',  
                                ' /localizedName [ 16',  
                                ' 416363657373204d656e75204974656d',  
                                ' ]',  
                                ' /isOpen 0',  
                                ' /isOn 1',  
                                ' /hasDialog 0',  
                                ' /parameterCount 3',  
                                ' /parameter-1 {',  
                                ' /key 1769238125',  
                                ' /showInPalette -1',  
                                ' /type (ustring)',  
                                ' /value [ 16',  
                                ' 4c697665204f66667365742050617468',  
                                ' ]',  
                                ' }',  
                                ' /parameter-2 {',  
                                ' /key 1818455661',  
                                ' /showInPalette -1',  
                                ' /type (ustring)',  
                                ' /value [ 25',  
                                ' 4566666563743a20506174683a204f66667365742050617468',  
                                ' ]',  
                                ' }',  
                                ' /parameter-3 {',  
                                ' /key 1668114788',  
                                ' /showInPalette -1',  
                                ' /type (integer)',  
                                ' /value -2130705931',  
                                ' }',  
                                ' }',  
                                '}'  
                                            ].join('\n');    
                                        var f = new File('~/' + mySet + myAction + '.aia');      
                                        f.open('w');      
                                        f.write(actionStr);      
                                        f.close();      
                                        app.loadAction(f);      
                                        f.remove();   
                                        app.userInteractionLevel = currentInteractionLevel;     
                                        }  
                                
                                
                                  function  ascii2Hex (hex) {  
                                    return hex.replace(/./g, function (a) {return a.charCodeAt(0).toString(16)})  
                                }  
                                  
                                do_script()
                                app.doScript(myAction, mySet, false);  
                                

                                 

                                this will still create a new action when ever it is run...

                                • 13. Re: How to add multiple strokes with offset path?
                                  arteangelus Level 1

                                  Thank Qwertyfly... but it did not worked.

                                  By the way as a beginner I should ask I'm running scripts from ExtendScript manager. It's marking  app.loadAction(f);  as an error.

                                   

                                   

                                  I tried that one also did not work.

                                  #target illustrator
                                  
                                  
                                  var myAction = "OffsetPath";    
                                  var mySet = "OffsetPath";    
                                  
                                  
                                  
                                  
                                  var actionStr = [
                                  '/version 3',
                                  '/name [ 11',
                                  ' 4f66667365742050617468',
                                  ']',
                                  '/isOpen 1',
                                  '/actionCount 1',
                                  '/action-1 {',
                                  ' /name [ 10',
                                  ' 4f666673657450617468',
                                  ' ]',
                                  ' /keyIndex 0',
                                  ' /colorIndex 0',
                                  ' /isOpen 1',
                                  ' /eventCount 2',
                                  ' /event-1 {',
                                  ' /useRulersIn1stQuadrant 0',
                                  ' /internalName (ai_plugin_appearance)',
                                  ' /localizedName [ 10',
                                  ' 417070656172616e6365',
                                  ' ]',
                                  ' /isOpen 0',
                                  ' /isOn 1',
                                  ' /hasDialog 0',
                                  ' /parameterCount 1',
                                  ' /parameter-1 {',
                                  ' /key 1835363957',
                                  ' /showInPalette -1',
                                  ' /type (enumerated)',
                                  ' /name [ 14',
                                  ' 416464204e6577205374726f6b65',
                                  ' ]',
                                  ' /value 2',
                                  ' }',
                                  ' }',
                                  ' /event-2 {',
                                  ' /useRulersIn1stQuadrant 0',
                                  ' /internalName (adobe_commandManager)',
                                  ' /localizedName [ 16',
                                  ' ]',
                                  ' 416363657373204d656e75204974656d',
                                  ' /isOpen 0',
                                  ' /isOn 1',
                                  ' /hasDialog 0',
                                  ' /parameterCount 3',
                                  ' /parameter-1 {',
                                  ' /key 1769238125',
                                  ' /showInPalette -1',
                                  ' /type (ustring)',
                                  ' /value [ 16',
                                  ' 4c697665204f66667365742050617468',
                                  ' ]',
                                  ' }',
                                  ' /parameter-2 {',
                                  ' /key 1818455661',
                                  ' /showInPalette -1',
                                  ' /type (ustring)',
                                  ' /value [ 25',
                                  ' 4566666563743a20506174683a204f66667365742050617468',
                                  ' ]',
                                  ' }',
                                  ' /parameter-3 {',
                                  ' /key 1668114788',
                                  ' /showInPalette -1',
                                  ' /type (integer)',
                                  ' /value -2130705931',
                                  ' }',
                                  ' }',
                                  '}'
                                  
                                  
                                  ].join('\n'); 
                                  
                                  
                                  
                                  
                                  
                                   function doScript(a,b, c){      
                                          var f =  new File('~/' + a + b + '.txt');      
                                          f.open('w');      
                                          f.write(c); 
                                          f.close();      
                                          app.loadAction(f);      
                                          f.remove();   
                                          } 
                                      
                                  
                                  
                                  function  ascii2Hex (hex) {      return hex.replace(/./g, function (a) {return a.charCodeAt(0).toString(16)})  }  
                                  
                                  
                                  app.doScript(mySet,myAction, actionStr); 
                                  
                                  
                                  • 14. Re: How to add multiple strokes with offset path?
                                    Qwertyfly... Level 4

                                    I should say sorry as I believe I have caused confusion with the function named do_script.

                                    this is not the same as app.doScript() !!!

                                     

                                    copy and paste this to ESTK, don't try to rewrite the changes to an existing piece of code.

                                    the one you just posted has issues we fixed further up this thread.

                                     

                                    this one will work. though its not perfect

                                    var myAction = "OffsetPath";      
                                    var mySet = "Offset Path";      
                                    
                                    
                                    var actionStr = [  
                                    '/version 3',  
                                    '/name [ 11',  
                                    ' 4f66667365742050617468',  
                                    ']',  
                                    '/isOpen 1',  
                                    '/actionCount 1',  
                                    '/action-1 {',  
                                    ' /name [ 10',  
                                    ' 4f666673657450617468',  
                                    ' ]',  
                                    ' /keyIndex 0',  
                                    ' /colorIndex 0',  
                                    ' /isOpen 1',  
                                    ' /eventCount 2',  
                                    ' /event-1 {',  
                                    ' /useRulersIn1stQuadrant 0',  
                                    ' /internalName (ai_plugin_appearance)',  
                                    ' /localizedName [ 10',  
                                    ' 417070656172616e6365',  
                                    ' ]',  
                                    ' /isOpen 0',  
                                    ' /isOn 1',  
                                    ' /hasDialog 0',  
                                    ' /parameterCount 1',  
                                    ' /parameter-1 {',  
                                    ' /key 1835363957',  
                                    ' /showInPalette -1',  
                                    ' /type (enumerated)',  
                                    ' /name [ 14',  
                                    ' 416464204e6577205374726f6b65',  
                                    ' ]',  
                                    ' /value 2',  
                                    ' }',  
                                    ' }',  
                                    ' /event-2 {',  
                                    ' /useRulersIn1stQuadrant 0',  
                                    ' /internalName (adobe_commandManager)',  
                                    ' /localizedName [ 16',  
                                    ' 416363657373204d656e75204974656d', 
                                    ' ]',   
                                    ' /isOpen 0',  
                                    ' /isOn 1',  
                                    ' /hasDialog 0',  
                                    ' /parameterCount 3',  
                                    ' /parameter-1 {',  
                                    ' /key 1769238125',  
                                    ' /showInPalette -1',  
                                    ' /type (ustring)',  
                                    ' /value [ 16',  
                                    ' 4c697665204f66667365742050617468',  
                                    ' ]',  
                                    ' }',  
                                    ' /parameter-2 {',  
                                    ' /key 1818455661',  
                                    ' /showInPalette -1',  
                                    ' /type (ustring)',  
                                    ' /value [ 25',  
                                    ' 4566666563743a20506174683a204f66667365742050617468',  
                                    ' ]',  
                                    ' }',  
                                    ' /parameter-3 {',  
                                    ' /key 1668114788',  
                                    ' /showInPalette -1',  
                                    ' /type (integer)',  
                                    ' /value -2130705931',  
                                    ' }',  
                                    ' }',  
                                    '}'  
                                    ].join('\n');   
                                       
                                    var f =  new File('~/greyHair.aia'); // we dont care what the name is as it is removed in a few lines
                                    f.open('w');        
                                    f.write(actionStr);   
                                    f.close();        
                                    app.loadAction(f);        
                                    f.remove();     
                                      
                                    app.doScript(myAction, mySet ,false);   
                                    
                                    • 15. Re: How to add multiple strokes with offset path?
                                      arteangelus Level 1

                                      Hi again Qwertyfly...

                                      First of all I'd like to thank you for your interest and support.

                                      It's working but it open up a dialogue box, what I was trying to do is actually creating a loop with user specific values which creates say 10 px offset paths with new strokes. Like 2,4,6,8,10... offset values.

                                      Also as you said it creates new action set each time. I tried unload action command.

                                      Now I tried to mix this code with CarlosCanto 's code. But as a newbie coder I could not find again It becomes an obsession to me.

                                      I also tried adding xmlstring way in order to add user options.

                                       

                                      xmlstring = '<LiveEffect name="Live Offset Path"><Dict data="R mlim '+miterlimitvalue + ' R ofst ' + offsetvalue + ' I jntp ' + jointype + '"/></LiveEffect>';
                                      

                                       

                                      But this way it applies offset path outside of stroke which is not what I want.

                                      What I really want is exactly in screenshot;

                                      example.jpg

                                       

                                       

                                      var idoc = app.activeDocument;
                                      var ipath = idoc.selection[0];
                                      var offsetvalue = '8';
                                      var jointype ='Round';
                                      var miterlimitvalue = '4';
                                      var myAction = "OffsetPath";        
                                      var mySet = "OffsetPath";        
                                      
                                      
                                      xmlstring = '<LiveEffect name="Live Offset Path"><Dict data="R mlim '+miterlimitvalue + ' R ofst ' + offsetvalue + ' I jntp ' + jointype + '"/></LiveEffect>';
                                      
                                      
                                      var actionStr = [    
                                      '/version 3',    
                                      '/name [ ' + mySet.length,
                                      ascii2Hex(mySet),
                                      ']',
                                      '/isOpen 1',    
                                      '/actionCount 1',    
                                      '/action-1 {',    
                                      '/name [ ' + myAction.length,
                                      ascii2Hex(myAction),
                                      ']',
                                      ' /keyIndex 0',    
                                      ' /colorIndex 0',    
                                      ' /isOpen 1',    
                                      ' /eventCount 2',    
                                      ' /event-1 {',    
                                      ' /useRulersIn1stQuadrant 0',    
                                      ' /internalName (ai_plugin_appearance)',    
                                      ' /localizedName [ 10',    
                                      ' 417070656172616e6365',    
                                      ' ]',    
                                      ' /isOpen 0',    
                                      ' /isOn 1',    
                                      ' /hasDialog 0',    
                                      ' /parameterCount 1',    
                                      ' /parameter-1 {',    
                                      ' /key 1835363957',    
                                      ' /showInPalette -1',    
                                      ' /type (enumerated)',    
                                      ' /name [ 14',    
                                      ' 416464204e6577205374726f6b65',    
                                      ' ]',    
                                      ' /value 2',    
                                      ' }',    
                                      ' }',    
                                      ' /event-2 {',    
                                      ' /useRulersIn1stQuadrant 0',    
                                      ' /internalName (adobe_commandManager)',    
                                      ' /localizedName [ 16',    
                                      ' 416363657373204d656e75204974656d',   
                                      ' ]', 
                                      ' }',    
                                      '}'    
                                      ].join('\n');     
                                      
                                       try {  
                                             app.doScript (myAction, mySet); // missing action doesn't trigger an error, but it brings up Illustrator warning about action not being available - Click on "Stop" to continue                                                                                
                                             app.unloadAction (mySet, myAction); // unloads action but it keeps the set folder, loading actions keep duplicating folder actions  
                                          }  
                                          catch (e) {  
                                              var f = new File('~/ScriptAction.aia');
                                              f.write(actionStr);  
                                              
                                              app.loadAction (f);  
                                              app.doScript (myAction, mySet);  
                                              ipath.applyEffect(xmlstring);
                                              f.close();
                                              f.remove();
                                               
                                          }  
                                      
                                      
                                      function  ascii2Hex (hex) {
                                          return hex.replace(/./g, function (a) {return a.charCodeAt(0).toString(16)})
                                      }
                                      
                                      
                                      
                                      
                                      
                                      
                                      
                                      
                                      • 16. Re: How to add multiple strokes with offset path?
                                        Qwertyfly... Level 4

                                        OK, I'm going to assume your on windows going by the screen shot in the opening post.

                                         

                                        here is a completely different approach.

                                         

                                        this uses executeMenuCommand so is only compatible with CS6+

                                        and is Windows only as it uses VB

                                         

                                        //-------------------------------------------------------------------
                                        
                                        
                                        // Offset Path in apperence panel
                                        
                                        
                                        // Script by Qwertyfly
                                        // contact tristan@qwertyfly.com
                                        // version 0.1 beta
                                        
                                        
                                        //-------------------------------------------------------------------
                                        
                                        
                                        //number of offset paths
                                        var Qty = 5;
                                        
                                        
                                        //amount to offset
                                        var Offset = -5;
                                        
                                        
                                        //units to offest in
                                        var Unit = "px"; 
                                        
                                        
                                        //time to wait in milliseconds before sending keys.
                                        // more time is slower but more stable
                                        // I was able to run this with it set to 0, but a little bit of a pause is a good idea.
                                        var wait = 10;
                                        
                                        
                                        //-------------------------------------------------------------------
                                        function FillDialog_Windows(distance){
                                            var VB = [
                                                'WScript.Sleep ' + wait + '',
                                                'Set WshShell = WScript.CreateObject("WScript.Shell")',
                                                'WshShell.SendKeys "' + distance + '"',
                                                'WshShell.SendKeys "{ENTER}"'
                                                ].join('\n');
                                            var VBgo = new File('~/go.vbs');
                                            VBgo.open('w');
                                            VBgo.write(VB);
                                            VBgo.close();
                                            VBgo.execute();
                                        }
                                        function MakeStroke(offset){
                                            app.executeMenuCommand('Adobe New Stroke Shortcut'); 
                                            FillDialog_Windows(offset);
                                            app.executeMenuCommand('Live Offset Path');
                                        }
                                        
                                        
                                        for(var i = 1; i<Qty+1; i++){
                                            MakeStroke(i*Offset + Unit);
                                        }
                                        
                                        • 17. Re: How to add multiple strokes with offset path?
                                          arteangelus Level 1

                                          Thank you so much it's working great:))))

                                          • 18. Re: How to add multiple strokes with offset path?
                                            arteangelus Level 1

                                            Qwertyfly...

                                            It would be even better if we would set joins type (miter,round,bevel) and stroke size... I'm still searching... But again thank you:)

                                            By the way;

                                            If anyone interested setting stroke width ; I guess I have found a way.

                                            from this link;

                                            Adobe Illustrator CS6 Type Library JS: PageItem

                                            My Example;

                                            path.resize (100,100,true,true,true,true,200,Transformation.CENTER); // Increase stroke width for %200.

                                            • 19. Re: How to add multiple strokes with offset path?
                                              Qwertyfly... Level 4

                                              ok now there are a few arrays to fill out so you can set the join, miter, width of each stroke including the original.

                                               

                                              //-------------------------------------------------------------------
                                              
                                              
                                              // Offset Path in apperence panel
                                              
                                              
                                              // Script by Qwertyfly
                                              // contact tristan@qwertyfly.com
                                              // version 0.1 beta
                                              
                                              
                                              //-------------------------------------------------------------------
                                              
                                              
                                              //number of offset paths
                                              var Qty = 5;
                                              
                                              
                                              //amount to offset
                                              var Offset = -5;
                                              
                                              
                                              //units to offest in
                                              var Unit = "px"; 
                                              
                                              
                                              //time to wait in milliseconds before sending keys.
                                              // more time is slower but more stable
                                              // I was able to run this with it set to 0, but a little bit of a pause is a good idea.
                                              var wait = 10;
                                              //-------------------------------------------------------------------
                                              var J_Bev = StrokeJoin.BEVELENDJOIN;
                                              var J_Rnd = StrokeJoin.ROUNDENDJOIN;
                                              var J_Mit = StrokeJoin.MITERENDJOIN;
                                              var Join = [J_Rnd, J_Rnd, J_Rnd, J_Mit, J_Bev, J_Bev]; //Note that this has 6 items while Qty is only 5, so it can set the Original Stroke as well
                                              var Width = [3,5,4,3,2,1]; // this is in pts
                                              var Miter = [4,4,4,4,4,4];
                                              var count = 0;
                                              //-------------------------------------------------------------------
                                              var doc = app.activeDocument;
                                              var sel = doc.selection;
                                              
                                              
                                              //set props for original strokes
                                              for(var i=0; i<sel.length; i++){
                                                  sel[i].strokeJoin = Join[0];
                                                  sel[i].strokeWidth = Width[0];
                                                  sel[i].strokeMiterLimit = Miter[0];
                                              }
                                              
                                              
                                              function Set_Stroke_Properties(){
                                                  for(var i=0; i<sel.length; i++){
                                                      sel[i].strokeJoin = Join[count];
                                                      sel[i].strokeWidth = Width[count];
                                                      sel[i].strokeMiterLimit = Miter[count];
                                                  }
                                              }
                                              
                                              
                                              function FillDialog_Windows(distance){
                                                  var VB = [
                                                      'WScript.Sleep ' + wait + '',
                                                      'Set WshShell = WScript.CreateObject("WScript.Shell")',
                                                      'WshShell.SendKeys "' + distance + '"',
                                                      'WshShell.SendKeys "{ENTER}"'
                                                      ].join('\n');
                                                  var VBgo = new File('~/go.vbs');
                                                  VBgo.open('w');
                                                  VBgo.write(VB);
                                                  VBgo.close();
                                                  VBgo.execute();
                                              }
                                              
                                              
                                              function MakeStroke(offset){
                                                  app.executeMenuCommand('Adobe New Stroke Shortcut'); 
                                                  count++
                                                  Set_Stroke_Properties();
                                                  FillDialog_Windows(offset);
                                                  app.executeMenuCommand('Live Offset Path');
                                              }
                                              
                                              
                                              for(var i = 1; i<Qty+1; i++){
                                                  MakeStroke(i*Offset + Unit);
                                              }
                                              
                                              • 20. Re: How to add multiple strokes with offset path?
                                                arteangelus Level 1

                                                Qwertyfly... This is just an amazing script :))) Thank you very very much.. I think it will be very useful for designers...

                                                 

                                                • 21. Re: How to add multiple strokes with offset path?
                                                  Qwertyfly... Level 4

                                                  after I posted the above code it started to give some strange results.

                                                  looks like it was not creating the first new stroke which was messing it all up.

                                                  but I don't know what was causing it.
                                                  It seems to be working fine now.


                                                  let me know if anyone else get strange results so I can try to find out what the issue may be.

                                                   

                                                  • 22. Re: How to add multiple strokes with offset path?
                                                    arteangelus Level 1

                                                    Qwertyfly...

                                                    Hi, it is also happening to me...I tried to modify code a bit ...(I would more like to add step incremental or inverse stroke width...Please consider I'm a beginner:))) )

                                                     

                                                    //-------------------------------------------------------------------  
                                                    // Offset Path in apperence panel  // Script by Qwertyfly  // contact tristan@qwertyfly.com  // version 0.1 beta  
                                                    //-------------------------------------------------------------------  
                                                    //number of offset paths  
                                                    var Qty = 25;  
                                                    // JoinTypes :1 = Miter // 2 = Round // 3 = Bevel
                                                    var JoinType = 3;
                                                    var Step = .3;
                                                    //amount to offset  
                                                    var Offset = -10;  
                                                    //units to offest in  
                                                    var Unit = "px";   
                                                    var wait = 5;  
                                                    //-------------------------------------------------------------------  
                                                    var J_Bev = StrokeJoin.BEVELENDJOIN;  
                                                    var J_Rnd = StrokeJoin.ROUNDENDJOIN;  
                                                    var J_Mit = StrokeJoin.MITERENDJOIN;
                                                    if (JoinType == 1) { jt = J_Mit; } if (JoinType == 2) { jt = J_Rnd; } if (JoinType == 3) { jt = J_Bev; }
                                                    //var Join = [J_Rnd, J_Rnd, J_Rnd, J_Mit, J_Bev, J_Bev]; //Note that this has 6 items while Qty is only 5, so it can set the Original Stroke as well  
                                                    var Width = [];
                                                    for (var i = Step; i <= Qty+1; i++) { Width.push(i); }
                                                    var Miter = []; 
                                                    for (var i = 1; i <= Qty+1; i++) { Miter.push(i); }
                                                    var count = 0;  
                                                    //-------------------------------------------------------------------  
                                                    var doc = app.activeDocument;  
                                                    var sel = doc.selection;  
                                                      
                                                      
                                                    //set props for original strokes  
                                                    for(var i=0; i<sel.length; i++){  
                                                        //sel[i].strokeJoin = Join[0];  
                                                        sel[i].strokeWidth = Width[0];  
                                                        sel[i].strokeMiterLimit = Miter[0];  
                                                    }  
                                                      
                                                      
                                                    function Set_Stroke_Properties(){  
                                                        for(var i=0; i<sel.length; i++){  
                                                            //sel[i].strokeJoin = Join[count];  
                                                            sel[i].strokeWidth = Width[count];  
                                                            sel[i].strokeMiterLimit = Miter[count];  
                                                        }  
                                                    }  
                                                      
                                                      
                                                    function FillDialog_Windows(distance){  
                                                        var VB = [  
                                                            'WScript.Sleep ' + wait + '',  
                                                            'Set WshShell = WScript.CreateObject("WScript.Shell")',  
                                                            'WshShell.SendKeys "' + distance + '"',
                                                            'WshShell.SendKeys "{TAB}"' , 
                                                            'WshShell.SendKeys "' + jt + '"',
                                                            // 'WshShell.SendKeys "{DOWN}"' , 
                                                            'WshShell.SendKeys "{TAB}"' , 
                                                            'WshShell.SendKeys "1"',
                                                            'WshShell.SendKeys "{ENTER}"'  
                                                            ].join('\n');  
                                                        var VBgo = new File('~/go.vbs');  
                                                        VBgo.open('w');  
                                                        VBgo.write(VB);  
                                                        VBgo.close();  
                                                        VBgo.execute();  
                                                    }  
                                                    
                                                    
                                                    function MakeStroke(offset){  
                                                        app.executeMenuCommand('Adobe New Stroke Shortcut');   
                                                        count++  
                                                        Set_Stroke_Properties();  
                                                        FillDialog_Windows(offset);  
                                                        app.executeMenuCommand('Live Offset Path');  
                                                    }  
                                                      
                                                      
                                                    for(var i = 1; i<Qty+1; i++){  
                                                        MakeStroke(i*Offset + Unit);  
                                                    }  
                                                    
                                                    • 23. Re: How to add multiple strokes with offset path?
                                                      Qwertyfly... Level 4

                                                      if your doing it with the VB then I believe that jt should be equal to r , m , or b.

                                                       

                                                      but I don't have time to test it right now.