2012-03-27 31 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