Copy link to clipboard
Copied
So, maybe I'm missing something obvious, but I have a script that draws simple stroked rectangles based on the users selection. If the user happens to have an item selected (or was the last item selected) where the appearance panel has the stroke visibility (eyeball) turned off, any new path the script creates will also have the stroked turned off.
// create new path
var rect = app.activeDocument.pathItems.rectangle(circle.top - 36, circle.left, 36, 36);
rect.stroked = true;
I have tried changing/resetting the `defaultStroked` variables but that didn't help. The only real solution I could come up with is to create a temporaty shape, expand it's appearance, and then go on creating the shapes I need withing my script.
// create temp shape to reset appearance panel
var temp = app.activeDocument.pathItems.rectangle(0, 0, 36, 36);
app.executeMenuCommand("expandStyle");
temp.remove();
// go on creating required script shapes with appearance settings reset
var rect = app.activeDocument.pathItems.rectangle(circle.top - 36, circle.left, 36, 36);
rect.stroked = true;
Am I losing my ming and missing something obvious??? I also, ran into a similar issue when the selected object had multiple strokes and fill that were not in the standard order.
This script needs to run on unknown systems and setups so I want to ensure the shapes will be drawn correctly no matter who runs the script.
Thanks in advance for your help!
2 Correct answers
I don't know if this will help you, but applying the default graphic style will give the rectangle a visible stroke.
app.activeDocument.graphicStyles[0].applyTo(rect);
might not be ideal, but this was able to produce the results. i dont think i've ever seen someone turn off the visibility in the appearance before.
var circle = app.activeDocument.selection[0]
app.executeMenuCommand('deselectall')
var rect = app.activeDocument.pathItems.rectangle(circle.top - 36, circle.left, 36, 36);
rect.selected=true
app.executeMenuCommand('Adobe New Stroke Shortcut')
app.redraw()
rect.stroked = true;
rect.strokeWidth = 3
Explore related tutorials & articles
Copy link to clipboard
Copied
I don't know if this will help you, but applying the default graphic style will give the rectangle a visible stroke.
app.activeDocument.graphicStyles[0].applyTo(rect);
Copy link to clipboard
Copied
@femkeblanco, yes that was my first thougt too (sorry I should have mentioned that). I was just concerned that someone may have a custom document profile with a different default graphic style. I'm sure that is a very small chance but I was just tryig to cover all possible scenerios. Thanks as always for your help!
Copy link to clipboard
Copied
might not be ideal, but this was able to produce the results. i dont think i've ever seen someone turn off the visibility in the appearance before.
var circle = app.activeDocument.selection[0]
app.executeMenuCommand('deselectall')
var rect = app.activeDocument.pathItems.rectangle(circle.top - 36, circle.left, 36, 36);
rect.selected=true
app.executeMenuCommand('Adobe New Stroke Shortcut')
app.redraw()
rect.stroked = true;
rect.strokeWidth = 3
Copy link to clipboard
Copied
@RobOctopus, yep this works but still leaves a hidden extra stroke in the appearance panel that bugs me. I was hoping for a native way to accomplish this but I'm beginning to think there isn't one.
As for turning off the visibility in the actual appearance, it is something I have seen on occasion and something I do from time to time, especially with prebuilt styles. For example, in the attached image I have a prebuilt style for the name (top object), but I can easily turn off the pink accents and inner gradient to quickly achieve an alternate look without having to keep two separate styles in sync.
 
Thanks for thr suggestion!

