From 0d8be6185819d7c8acb873e921706ab8aa10dcab Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 29 Apr 2018 21:37:58 -0400 Subject: [PATCH] Fixed an error in dojs.vbs where arguments were being split. * Fixed SetText() to update bounds. --- ps.go | 2 +- scripts/dojs.vbs | 4 +++- scripts/test.jsx | 3 +-- structs.go | 17 +++++++++++++---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ps.go b/ps.go index 37d370f..c39854d 100644 --- a/ps.go +++ b/ps.go @@ -148,7 +148,7 @@ func run(name string, args ...string) ([]byte, error) { if strings.Contains(name, "dojs") { args = append([]string{opts, filepath.Join(pkgpath, "scripts", name)}, args[0], - fmt.Sprintf("%s", strings.Join(args[1:], ",")), + fmt.Sprintf("%s", strings.Join(args[1:], ",,")), ) } else { args = append([]string{opts, filepath.Join(pkgpath, "scripts", name)}, args...) diff --git a/scripts/dojs.vbs b/scripts/dojs.vbs index 997320b..9e2c0b8 100644 --- a/scripts/dojs.vbs +++ b/scripts/dojs.vbs @@ -4,9 +4,11 @@ Set appRef = CreateObject("Photoshop.Application") if wScript.Arguments.Count = 0 then wScript.Echo "Missing parameters" else + ' wScript.Echo wScript.Arguments(0) + ' wScript.Echo wScript.Arguments(1) path = wScript.Arguments(0) args = wScript.Arguments(1) - error = appRef.DoJavaScriptFile(path, Split(args, ",")) + error = appRef.DoJavaScriptFile(path, Split(args, ",,")) if Not error = "true" and Not error = "[ActionDescriptor]" and Not error = "undefined" Then Err.raise 1, "dojs.vbs", error end if diff --git a/scripts/test.jsx b/scripts/test.jsx index 05828f3..c0fe37f 100644 --- a/scripts/test.jsx +++ b/scripts/test.jsx @@ -1,10 +1,9 @@ #include lib.js // var saveFile = File(arguments[0]); -var arg = 'app.activeDocument.layerSets.getByName("Text").artLayers.getByName("short");'; +var arg = "app.activeDocument.layerSets.getByName('Text').artLayers.getByName('short').textItem.contents='When another sandman is discarded from a lane,';"; var set = eval(arg); // set.textItem.size=10; -alert(set.textItem.font) // var doc=app.activeDocument // doc.layerSets.getByName("ResolveGem").merge(); // alert(doc.artLayers.getByName("ResolveGem").bounds); diff --git a/structs.go b/structs.go index 55f0cd0..e9f2db8 100644 --- a/structs.go +++ b/structs.go @@ -753,11 +753,20 @@ func (t *TextItem) SetText(txt string) { return } lyr := strings.TrimRight(JSLayer(t.parent.Path()), ";") - js := fmt.Sprintf("%s.textItem.contents='%s';", lyr, txt) - _, err := DoJs("compilejs.jsx", js) - if err != nil { - t.contents = txt + bndtext := "[[' + lyr.bounds[0] + ',' + lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' + lyr.bounds[3] + ']]" + js := fmt.Sprintf(`%s.textItem.contents='%s';var lyr = %[1]s;stdout.writeln(('%[3]s').replace(/ px/g, ''));`, + lyr, txt, bndtext) + byt, err := DoJs("compilejs.jsx", js) + var bnds *[2][2]int + json.Unmarshal(byt, &bnds) + if err != nil || bnds == nil { + log.Println("text:", txt) + log.Println("js:", js) + fmt.Printf("byt: '%s'\n", string(byt)) + log.Panic(err) } + t.contents = txt + t.parent.bounds = *bnds } func (t *TextItem) SetSize(s float64) {