Skip to main content
wolfgangappel
New Participant
August 27, 2014
Answered

Change Color in CellOverrideShading

  • August 27, 2014
  • 1 reply
  • 1596 views

Hi all,

I tried to change the color in CellOverrideShading but I didn't get it.

My attempts were the following:

First I tried to get the index of the color property via GetPropIndex:

var testProp = cell.CellOverrideShading.GetProps();

var testPropIndex = GetPropIndex(testProp, Constants.FP_Color);

But the result is "-4", so it seems that CellOverrideShading has no FP_Color property.

Second: I tried to change the color via the PropVal object:

     testProp[1].propVal.sval = 'Olive';


When I print the properties to the Console the color name seems to be updated to 'Olive'

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

{

            propText = propText + ' \n' + i + ': ' + testProp.propIdent.name + ' - ' + testProp.propIdent.num + ' - ' + testProp.propVal.sval;

}

1:  - 20 - Olive

Then I assin the properties to the cell.

cell.CellOverrideShading.SetProps(testProp);

But the color in the Frame document remains unchanged. When I print the color name to the Console [Console('FARBE: ' + cell.CellOverrideShading.Name);]

I still receive FARBE: Königsblau

What's my mistake? Any ideas?

Yours Wolfgang

This topic has been closed for replies.
Correct answer frameexpert

Hi Tracey, This works for me. I used 0 instead of 15. Make sure you refresh the screen after you run the code.

#target framemaker

var doc = app.ActiveDoc;

var pgf = doc.TextSelection.beg.obj;

var cell = pgf.InTextObj;

// Get the Red color object.

var color = doc.GetNamedColor ("Red");

  

// Set the cell's properties to 100% Red.

cell.CellOverrideShading = color;

cell.CellUseOverrideShading = true;

cell.CellOverrideFill = 0;

cell.CellUseOverrideFill = true;

Rick

1 reply

Inspiring
August 27, 2014

Hi Wolfgang,

I think you have a misunderstanding of GetProps() and SetProps(), which is the foundation of your trouble. When you do this:

var testProp = cell.CellOverrideShading.GetProps()

... you are getting the properties of the color object assigned to the CellOverrideShading property, not the cell. And, in this case, the CellOverrideShading property just happens to be an object, otherwise the GetProps() method would not be valid at all. Anyway, a color object has no FP_Color property, hence the reason that you can't find it in the PropVals array.

You could do it with the cell properties directly, maybe something like this (note - I didn't test this!):

var testProps = cell.GetProps();

var testPropIndex = GetPropIndex(testProps, Constants.FP_CellOverrideShading);

...then more code to manipulate the array and reset the properties. However, I would recommend this direct approach instead (again, I didn't test this!):

var colorObj = doc.GetNamedColor("Olive");

if(colorObj.ObjectValid()) cell.CellOverrideShading = colorObj;

I hope this helps some.

Russ

Known Participant
August 29, 2014

Hi Russ, I'm trying to achieve the same thing but am having a little trouble.

Used>

// Get the table cell that contains the paragraph. 

var cell = pgf.InTextObj; (alert returns a cell  object)

cell.CellUseOverrideShading = true ;

cell.CellUseOverrideFill = true ;

cell.CellOverrideFill = 15 ;

var colorObj = doc.GetNamedColor("Red");

cell.CellOverrideShading = colorObj;

Expect to see red cells in my table but am not, any idea what I'm missing?

thanks,

Tracey

Known Participant
December 8, 2021

Hi Tracey, This works for me. I used 0 instead of 15. Make sure you refresh the screen after you run the code.

#target framemaker

var doc = app.ActiveDoc;

var pgf = doc.TextSelection.beg.obj;

var cell = pgf.InTextObj;

// Get the Red color object.

var color = doc.GetNamedColor ("Red");

  

// Set the cell's properties to 100% Red.

cell.CellOverrideShading = color;

cell.CellUseOverrideShading = true;

cell.CellOverrideFill = 0;

cell.CellUseOverrideFill = true;

Rick


@frameexpert Hello Rick,

 

For some reason your script doesn't change the cell color until  change from 0 to 100:

 

cell.CellOverrideFill = 100;

 Do you know why?

Thanks in advance.