Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how make an object's K value its opacity?

New Here ,
Feb 05, 2010 Feb 05, 2010

hi all -

so i think this is really easy, but i unfortunately have just started a computer programming class for vb so i don't know enough yet to delve into the code.

Basically, i have ~20 objects each of a different stroke color. I was wondering if there was a simple way to select all of them and make each of the objects' opacity level (currently at 100) equal to their K value?

I really appreciate the time and help. hopefully by the end of this semester i'll be able to write stuff like this myself!

TOPICS
Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Feb 08, 2010 Feb 08, 2010

This would look for the K (black) value in your stroked path items. Set it to 100 then adjust opacity…

#target illustrator

// Set reference to target object

var docRef = app.activeDocument;

// Work with target object

with (docRef) {

// Loop thru objects in path items Array

for (var i = 0; i < pathItems.length; i++) {

// Test for condition stroked

if (pathItems.stroked == true) {

// Test for condition CMYK color

if (pathItems.strokeColor instanceof CMYKColor) {

// Store reference of value in K

var thi

...
Translate
Adobe
Guru ,
Feb 07, 2010 Feb 07, 2010

I don't do VB but this is JavaScript and should be close to what you want to do. It may provide you with a few pointers that you could look up in the scripting guides to get you off in the right direction. This example is only for path items. In script you don't need to select items as you do in the GUI just target them and change there property values.

#target illustrator

// Set reference to target object

var docRef = app.activeDocument;

// Work with target object

with (docRef) {

// Loop thru objects in path items Array

for (var i = 0; i < pathItems.length; i++) {

// Test for condition stroked

if (pathItems.stroked == true) {

// Test for condition gray color

if (pathItems.strokeColor instanceof GrayColor) {

// Store reference of value

var thisGray = Math.round(pathItems.strokeColor.gray);

// Set object property value

pathItems.strokeColor.gray = 100;

// Set object property value

pathItems.opacity = thisGray;

}

}

}

// See what we've done…

redraw();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 07, 2010 Feb 07, 2010

mark thanks for the help, i'm seeming to have some issues though. java looks a whole lot simpler than vb so i'll try and walk through the script.. the script works in the current document, and then loops through the objects which are selected. for each one it tests, the script makes sure it has a stroke and then reads and stores the "GrayColor" (which I assume is the K value). The script then sets the line to black (K=100) and sets its opacity to the original K value.

This sounds like it should work, assuming I read the pseudocode correctly. But, when I try to run the script with any amount of items selected (all of them have strokes and no fill), nothing happens. I don't understand what you mean that I "don't need to select items as you do in the GUI just target them and change their property values". Is the problem I'm having with the way I select items?

EDIT: So the problem is definitely in the item selection process. I tried inserting some other code i have from another script at the beginning to make it use the objects that I have selected but it seems the first line docRef as opposed to doc is the place where i start to splice and mess up.

I put in

var doc = app.activeDocument;

var sel = (doc.selection.length > 0) ? doc.selection : doc.pathItems;

at the top and it says that pathItems is undefined... though I thought i just set pathItems to be equal to those objects that are selected?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 08, 2010 Feb 08, 2010

When you said 'K value' I was guessing that your strokes would be using color values from the grayscale slider is this the case? or are you wanting the to use the black value of a CMYK color? The posted script worked just fine for me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2010 Feb 08, 2010

i'm looking to use the CMYK K value: the lines, from how i exported them i believe, have C, M, Y, and K all equal to the same number. I don't know if there is a setting / script already made that can get rid of each of the CMY values, or is there a term to read just the K value (or technically, C, M, or Y?)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 08, 2010 Feb 08, 2010

This would look for the K (black) value in your stroked path items. Set it to 100 then adjust opacity…

#target illustrator

// Set reference to target object

var docRef = app.activeDocument;

// Work with target object

with (docRef) {

// Loop thru objects in path items Array

for (var i = 0; i < pathItems.length; i++) {

// Test for condition stroked

if (pathItems.stroked == true) {

// Test for condition CMYK color

if (pathItems.strokeColor instanceof CMYKColor) {

// Store reference of value in K

var thisGray = Math.round(pathItems.strokeColor.black);

// Set object property value

pathItems.strokeColor.black = 100;

// Set object property value

pathItems.opacity = thisGray;

}

}

}

// See what we've done…

redraw();

}

You just needed to check a different value from a different object

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2010 Feb 08, 2010
LATEST

this is perfect, thank you so much!! i knew the fix was simple, i just didn't know how to find out what the new value was and if it was the exact same way of extracting the data

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines