我有一个函数,用来画线然后描边路径。
export const getSolidColor = (hex) => {
const color = new SolidColor()
color.rgb.hexValue = hex
return color
}
export const drawLines = (doc, coordinates, title) => {
const lines = []
for (i = 0; i < coordinates.length; i++) {
const { anchor, kind, ldr, rdr } = coordinates[i]
const point = [anchor.x, anchor.y]
const line = new PathPointInfo()
line.kind = kind
line.anchor = point
line.leftDirection = ldr ? [ldr.x, ldr.y] : point
line.rightDirection = rdr ? [rdr.x, rdr.y] : point
lines.push(line)
}
const subPath = new SubPathInfo()
subPath.closed = true
subPath.entireSubPath = lines
subPath.operation = ShapeOperation.SHAPEXOR
const item = doc.pathItems.add(title, [subPath])
item.deselect()
return item
}
当我将此函数调用到
strokePath
时,它工作正常。
// Create a new document
const width = 1920
const height = 1080
const ppi = 72
const title = "Character 1"
const mode = NewDocumentMode.RGB
const newDoc = app.documents.add(width, height, ppi, title, mode)
const brush = ToolType.BRUSH
drawLines(newDoc, coords, "Line 1").strokePath(brush)
但是,当我尝试使用
fillPath
方法填充路径时,该图层只是显示为空。
export const convertPoints = (points) => {
const newPoints = []
for (i = 0; i < points.length; i++) {
newPoints.push({
kind: PointKind.CORNERPOINT,
anchor: {
x: points[i][0],
y: points[i][1]
},
ldr: null,
rdr: null
})
}
return newPoints
}
const newPoints = convertPoints([
[width * 0.33, height * 0],
[width * 0.33, height * 1],
[width * 0.5, height * 1],
[width * 0.5, height * 0]
])
const fillColor = getSolidColor("0080ff")
const opacity = 90
const fillMode = ColorBlendMode.NORMAL
const preserveTransparency = true
const feather = 0
const wholePath = true
const antiAlias = true
drawLines(newDoc, newPoints, "Line 2").fillPath(
fillColor,
fillMode,
opacity,
preserveTransparency,
feather,
wholePath,
antiAlias
)
形状与锚点一起出现在 Photoshop 文档上,但内部未着色或填充。有谁知道如何使用 ExtendScript 吗?
谢谢!
您可以使用前景色填充路径(一旦选择):
var idFl = charIDToTypeID( "Fl " );
var desc43 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref8 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref8.putEnumerated( idPath, idOrdn, idTrgt );
desc43.putReference( idnull, ref8 );
var idWhPt = charIDToTypeID( "WhPt" );
desc43.putBoolean( idWhPt, true );
executeAction( idFl, desc43, DialogModes.NO );