12 Replies Latest reply on Jun 15, 2017 11:17 AM by clutch-cargo

    VBscript how to select a custom preset

    clutch-cargo Level 1

      Can someone show me how to select a custom trace preset in VBscript?  I have a single image loaded in Illustrator CS6 which I then need to trace.  I have tried several variations of:

       

      Set DocRef = App.ActiveDocument

      DocRef.TracingOptions.LoadFromPreset("simwest trace 1")

       

      Any help would be most appreciated.

        • 1. Re: VBscript how to select a custom preset
          clutch-cargo Level 1

          I thought it best to include my script for anyone who can help.  It's at around line 22 that's the issue.

           

          Set App = CreateObject("Illustrator.Application")

          Set FSO = CreateObject("Scripting.FileSystemObject")

          Set SourceFolder = FSO.GetFolder("S:\SOCAL\Section_14\Veg TIFFs")

          Set TIFFfile = SourceFolder.Files

           

          Dim FileRef

          For Each FileRef In SourceFolder.Files

              Set AutoCADOpenOptions = App.Preferences.AutoCADFileOptions

                  AutoCADOpenOptions.MergeLayers = false

                  CurrentInteractionLevel = App.UserInteractionLevel

                  App.UserInteractionLevel = -1 ' aiDontDisplayAlerts

                  Set myDoc = App.Open(FileRef.Path,2)

                  App.UserInteractionLevel = CurrentInteractionLevel

                 

                  App.DoScript "AutoVeg1", "Auto Veg TIFF-2-DXF"

                 

                  Set DocRef = App.ActiveDocument

                  DocRef.TracingOptions.LoadFromPreset("SimwestTrace") 

                 

                  ' I have also tried the following without success:

                  ' App.Tracing.TracingOptions.LoadFromPreset("SimwestTrace")

             

                  App.DoScript "Auto Veg2", "Auto Veg TIFF-2-DXF"

                 

                  App.DoScript "SaveVegTIFF-2-DXF", "SavingFiles"

                 

                  MyDoc.Close(2)

          Next

          • 2. Re: VBscript how to select a custom preset
            CarlosCanto Adobe Community Professional & MVP

            preset property is read only and I haven't had any luck loading presets from file...the only way I have made it work is by Recording an Action to trace using my preset, then the script can play such action.

            • 3. Re: VBscript how to select a custom preset
              clutch-cargo Level 1

              Interesting, as that is what I originally did.   But I was seeing no difference between the default and my custom.  But I think I will try again as you said you have gotten it to work in the past.  So I guess Adobe documented the preset options but did not implement them in the code?

               

              On a side note, you have such great experience with vbscript... could I pm or email you with a different issue?

              • 4. Re: VBscript how to select a custom preset
                clutch-cargo Level 1

                Tried several attempts to record a custom action but it only plays back as the default trace. 

                 

                I did find inside my Illustrator program a JavaScript which is for tracing.  If Carlos (or anyone who can help), could either:

                1.  Convert the tracing part of the script to VBscript and/or

                2.  Show me how one can add and run a JavaScript inside my VBscript.

                 

                Maybe one of those ways might work?

                 

                Here's from the JavaScript:

                // Trace the files by placing them in the document.

                 

                 

                                        // Add a document in the app

                                        var doc = app.documents.add();

                                       

                                        // Add a placed item

                                        var p = doc.placedItems.add();

                                        p.file = new File(fileList[i]);

                                       

                                        // Trace the placed item

                                        var t = p.trace();

                                        t.tracing.tracingOptions.loadFromPreset(tracingPresets[3]);

                                        app.redraw();

                 

                Thanks for helping....

                • 5. Re: VBscript how to select a custom preset
                  CarlosCanto Adobe Community Professional & MVP

                  great, didn't remember the default tracing script was there, I had tried getting the app.tracingPresetsList before without success, it always returned "undefined"...and after trying the vbs boom!! it works in javascript as well...weird.

                   

                  anyway, after you add your preset manually, it will be added at the bottom of the presetsList, then you can get it from the list with

                   

                  illustrator.Application.TracingPresetsList(18) 'in my list 18 corresponds to myB&W preset

                   

                  now to get what number myB&W preset has, you can get the last number in the array with

                  ubound(illustrator.Application.TracingPresetsList)

                   

                  or you can go thru the list with

                  illustrator.Application.TracingPresetsList(0)

                  illustrator.Application.TracingPresetsList(1)

                  illustrator.Application.TracingPresetsList(2)

                  etc

                   

                  ******************

                   

                  to play a line of javascript or some short code you can cram in a line, you can use

                  Function DoJavaScript(JavaScriptCode As String, [Arguments], [ExecutionMode]) As String

                   

                  or if your javascript code is in a file, you could use

                  Function DoJavaScriptFile(JavaScriptFile As String, [Arguments], [ExecutionMode]) As String

                  • 6. Re: VBscript how to select a custom preset
                    clutch-cargo Level 1

                    THx Carlos,

                     

                    but I must be thick in the head because nothing is working for me.  Here's my script. You can see the line you suggested added:

                     

                    Set App = CreateObject("Illustrator.Application")

                    Set FSO = CreateObject("Scripting.FileSystemObject")

                    Set SourceFolder = FSO.GetFolder("C:\SOCAL\Section_12\Veg TIFFs")

                     

                    Dim FileRef

                    For Each FileRef In SourceFolder.Files

                      Set AutoCADOpenOptions = App.Preferences.AutoCADFileOptions

                      AutoCADOpenOptions.MergeLayers = false

                      CurrentInteractionLevel = App.UserInteractionLevel

                      App.UserInteractionLevel = -1 ' aiDontDisplayAlerts

                      Set myDoc = App.Open(FileRef.Path,2)

                      App.UserInteractionLevel = CurrentInteractionLevel

                     

                      App.DoScript "Auto Veg1", "Auto Veg TIFF-2-DXF 1m"

                     

                      Illustrator.Application.TracingPresetsList(13)

                     

                      App.DoScript "Auto Veg2", "Auto Veg TIFF-2-DXF"

                     

                      App.DoScript "SaveVegTIFF-2-DXF", "SavingFiles"

                     

                      MyDoc.Close(2)

                    Next

                     

                    In this way I get the error "object Illustrator required"

                    So I tried

                     

                    App.TracingPresetsList(13)

                    and I get "unspecified error, source null"

                     

                    What am I messing up?

                    • 7. Re: VBscript how to select a custom preset
                      CarlosCanto Adobe Community Professional & MVP

                      oh, first you need to get the whole preset list, then you have to trace your object (this will get done with defaults) then you can apply your preset

                       

                      this is VBA, but you get the idea, create a new document, add a linked jpg before running this snippet

                       

                      Sub usingTracingPreset()

                          Dim iapp As New Illustrator.Application

                          Dim idoc As Illustrator.Document

                          Dim iplaced As Illustrator.PlacedItem

                          Dim itraced As Illustrator.PluginItem

                         

                          Set idoc = iapp.ActiveDocument

                          presets = iapp.TracingPresetsList

                         

                          Set iplaced = idoc.PlacedItems(1)

                         

                          Set itraced = iplaced.Trace

                         

                          itraced.Tracing.TracingOptions.LoadFromPreset (presets(13))

                         

                          Set itraced = Nothing

                          Set iplaced = Nothing

                          Set idoc = Nothing

                          Set iapp = Nothing

                      End Sub

                      • 8. Re: VBscript how to select a custom preset
                        clutch-cargo Level 1

                        Well, I gave her a go with your script, editing as best I know to vbscript but I am getting  the error "ActiveX component can't create object:", on the four top lines under 'Sub'.  If I comment out one the next line throws the error.  So this is beyond my knowledge.  Here my altered script from yours:

                         

                        Sub usingTracingPreset()

                            Set App = CreateObject("Illustrator.Application")

                            Dim idoc : idoc = CreateObject("Illustrator.Document")

                            Dim iplaced : iplaced = CreateObject("Illustrator.PlacedItem")

                            Dim itraced : itraced = CreateObject("Illustrator.PluginItem")

                         

                            Set idoc = App.ActiveDocument

                            presets = App.TracingPresetsList

                         

                            Set iplaced = idoc.PlacedItems(1)

                         

                            itraced.Tracing.TracingOptions.LoadFromPreset(presets(13))

                         

                            Set itraced = Nothing

                            Set iplaced = Nothing

                            Set idoc = Nothing

                            Set App = Nothing

                        End Sub

                        • 9. Re: VBscript how to select a custom preset
                          CarlosCanto Adobe Community Professional & MVP

                          what's that? C#? I wouldn't know how to declare or assign the object references.

                          • 10. Re: VBscript how to select a custom preset
                            clutch-cargo Level 1

                            Oh-oh.  It's supposed to be VBscript!  I know I am new at scripting but is it that bad?  You said yours is in VBA.  Am I just supposed to run it as is?  I couldn't.

                            • 11. Re: VBscript how to select a custom preset
                              CarlosCanto Adobe Community Professional & MVP

                              to run VBA you copy the code I posted, open Excel/Word/Access/Outlook, create a Module, paste the code...add a reference to Illustrator...run the code as is.

                               

                              VBS, needs a little tweaking, vbs does not support "dim" and other declarations

                              • 12. Re: VBscript how to select a custom preset
                                clutch-cargo Level 1

                                Hi Carlos, it's been about a year since I last addressed this post (hopefully you will see this).  Back then I gave up as not fully understanding what needed to be done.  But now it is becoming crucial I solve this as I have to perform 100's of custom presets making manual selections no longer a viable option.

                                 

                                So I am taking my time, re-reading all above.  It sounds like the answer is there but I am just not there on how to implement it?

                                 

                                1. You suggest creating a VBS module and link to the tif image.  Does that mean I have to run the module outside of my VBscript or the module is somehow placed inside the VBscript?  Goal is to run entire process once started on its own without interaction.

                                2. You mentioned the vbs worked for you but then you say "vbs does not support "dim" and other declarations".  But you have it in the code above so I am a bit lost on this?  The code works as is above or not?

                                3.  So if I am reading the process correctly:

                                     A. Start Illustrator and load image

                                     B. Get a presets list

                                     C. Let Illustrator perform a "default" trace

                                     D. declare a presets list

                                     E. Apply my preset based on the list's number I want.

                                 

                                Here is what I have for my code so far.  The App.DoScript simply uses AI Actions to load the image and apply the default trace.

                                 

                                Set App = CreateObject("Illustrator.Application")

                                Set FSO = CreateObject("Scripting.FileSystemObject")

                                Set SourceFolder = FSO.GetFolder("S:\SOCAL\Section_31\Land Cover")

                                Set TIFFfile = SourceFolder.Files

                                 

                                Dim FileRef

                                For Each FileRef In SourceFolder.Files

                                    Set AutoCADOpenOptions = App.Preferences.AutoCADFileOptions

                                        AutoCADOpenOptions.MergeLayers = false

                                        CurrentInteractionLevel = App.UserInteractionLevel

                                        App.UserInteractionLevel = -1 ' aiDontDisplayAlerts

                                        Set myDoc = App.Open(FileRef.Path,2)

                                        App.UserInteractionLevel = CurrentInteractionLevel

                                       

                                        ubound(App.TracingPresetsList)

                                        App.DoScript "LandCover-1", "Land Cover Auto"

                                        presets = App.TracingPresetsList