2012-03-27 68 views
3

有什么办法可以用javascript访问pathItem的填充不透明度?我可以访问整体不透明度,但我想降低填充的不透明度,同时保持笔画完全不透明。Illustrator ExtendScript设置FILL不透明度的选择

我在文档中找不到任何东西,我也找不到其他人提出这个问题。

我可以设置不透明度整体像这样:

var selection = app.activeDocument.selection; 
selection[0].opacity = 50; 

我试过的 “fillOpacity” 每一个变种,我能想到的,就像这样:

var selection = app.activeDocument.selection; 
selection[0].fillOpacity = 50; 
selection[0].FillOpacity = 50; 
selection[0].fill.opacity = 50; 

...但它不起作用。

我是否在谈论这个错误,或者这是不可能的?

回答

4

您无法访问它,因为即使在插图画家中也无法正常访问它。这是一个Photoshop属性。我检查了文档以确保。你可以做的是这样的,虽然,它会完成同样的事情:

doc = app.activeDocument; 
i = 0 
var selection = doc.selection[i]; 
var storedColor = doc.selection[i].fillColor; 

//new object with only fill, we send it to back so it doesn't overlap stroke, if there is one 
var newObject = app.selection[i].duplicate(doc, ElementPlacement.PLACEATEND); 
//turn off fill for first object 
doc.selection[i].filled = false; 
i = i + 1; 
newObject.stroked = false; 
//apply stored color from earlier to new shape 
newObject.fillColor = storedColor; 
newObject.opacity = 50; 
newObject.name = "50p fill"; 
+0

请考虑对象如果这是足够的答案,则表决或接受此答案。 – Lukasz 2012-05-07 17:38:04

+0

这实际上是我最终做的。虽然这比应用其他答案的彩色专色更“混乱”,但着色可以做出奇怪的事情,我特别想改变不透明度。谢谢! – cr0ybot 2013-05-02 13:20:25

2

我做了什么来解决这个问题是一个spotcolor适用于那些我使用的色彩属性

var docRef = app.activeDocument; 
var selectedObjects = docRef.selection; 
var theTint; 
var fillwithSwatch = function (pathItems, sname){ 

for (var i=0;i< pathItems.length; i++){ 
pathItems[i].fill = true; 
theTint = pathItems[i].fillColor.gray; 
pathItems[i].fillColor = docRef.swatches.getByName (sname).color ; 
pathItems[i].fillColor.tint = theTint; 
} 
} 
theTint = fillTint(selectedObjects); 
// the spotcolor should be in the swatchpallet already 
fillwithSwatch (selectedObjects, "myBlue"); 
+0

感谢您的替代方法。它比复制对象更“干净”,但我特别需要更改不透明度。不过,如果我再次遇到类似的情况,我一定会记住这一点。 – cr0ybot 2013-05-02 13:21:43