Skip to main content
Participant
February 11, 2019
Answered

Changing Bevel/Emboss Setting for an Object via Script (help request)

  • February 11, 2019
  • 3 replies
  • 1360 views

I am a scripting novice in need of guidance.

I am laying out a rule and scenario books for an "old-fashioned wargame" that uses a printed map with a hex grid overlaid on the artwork, and cardboard tokens that represent military units such as tanks, infantry, artillery, and more. The scenario book missions need to show these counters in a manner that stands out from the map, and the game's inventor wants the tokens beveled, with shadow falling off them.

Each token "faces" one of six directions (i.e., 0 degrees, 60 degrees, 120 degrees, etc., one "side" of the hexagon it resides in). With global lighting there's no issue with where shadows fall, the light source is locked down. But the bevel/emboss settings are not locked down, and rotate with the object's rotation. A token rotated from its import orientation (0 degrees) to 120 degrees causes the bevel effect to appear "lit" from the 120 degree angle -- no matter what the shadow angle is set to. So you get conflicting lighting effects.

There are a LOT of tokens, at any of 6 directions, to adjust manually. I can see two approaches to a script to correct this, but it appears I'm too much a novice to make either work!

First Approach:

A script like the one below that affects the transparency of an object, that simply sets a value.

app.selection[0].transparencySettings.blendingSettings.opacity=10;

With 6 scripts I can cover the 6 possible facing settings for a token. However I cannot find the correct way to express the value I need to address. Variations on this script ( all resulted in an "Error 55 Object does not support property or method."

app.selection[0].BevelAndEmbossSetting.angle=270;

and

app.selection[0].transparencySettings.BevelAndEmbossSetting.angle=270;

Both of these failed, yet I could not locate any examples that provided clues as to what I am missing. I thought this would be simpler. How do I find out HOW to refer to the correct setting for such a script?

Second Approach:

This one's beyond my current abilities. A script that queries the values from InDesign for the objects Drop Shadow angle and its Rotation angle, calculates the appropriate "end result" for a matching bevel appearance, and sets that Shading angle for the bevel effect. While I can see a LOT of options making this more complex (offsets, distances, or other options), the specific need here is merely to make the bevel lighting "right" for the object's facing and the drop shadow angle.

Some years ago this script was posted to address a user's need to have the shadow rotate WITH an object. I thought perhaps I could reverse engineer some of this to fit my needs... in fact, this is what gave me the idea for the Second Approach. Alas, I can conceive of more ideas than I can code

    function main(){ 

      var sel = app.selection; 

      if(!sel){return} 

      if(sel.length==0){return} 

      var d=app.dialogs.add({name:"Change Angle With Drop Shadow"}); 

      d.dialogColumns.add().staticTexts.add({staticLabel:"Rotation Angle:"}); 

      var angleBox = d.dialogColumns.add().angleEditboxes.add({editValue:0,smallNudge:1,largeNudge:15}); 

      var result = d.show(); 

      if(!result){d.destroy();return} 

      var angle = angleBox.editValue; 

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

        var rotation = sel.rotationAngle; 

        rotation=rotation+angle; 

        if(rotation>=360){rotation=rotation-360} 

        sel.rotationAngle = rotation; 

        var dropAngle = sel.transparencySettings.dropShadowSettings.angle; 

        dropAngle = dropAngle+angle; 

        if(dropAngle>=360){dropAngle=dropAngle-360} 

        sel.transparencySettings.dropShadowSettings.angle = dropAngle; 

      } 

    } 

    main(); 

Can anyone offer any guidance, or referrals to consult?

Thank you,

James

This topic has been closed for replies.
Correct answer TᴀW

So close!

Try:

myObject.transparencySettings.bevelAndEmbossSettings.angle = 99;

... all I've changed is the lowercase b for bevel, and a plural s for bevelAndEmbossSettings.

Note that the angle must be express as a value between -180 and 180 degrees.

Also, if needed, there's the property

contentTransparencySettings

... if you want to apply bevel to the content itself.

HTH,

Ariel

3 replies

Participant
February 13, 2019

Ariel and Uwe, thank you very much for sharing your knowledge with me here.

I have learned much about InDesign's settings that I never needed to know in the past, but they matter now. Your replies opened up my limited understanding and whetted the desire for more.

If you don't mind plumbing the depths of ID knowledge a bit further, I'd like to ask them below in this same thread... I hope that's okay. If not, let me know.

Also, I am new here and am not sure of the etiquette for indicating "the answer" was provided. Ariel solved my immediate need, and Uwe showed me "more exists". (grin) You're both at fault! I've no wish to disrespect anyone, so how's that feature work here?

Respectfully,

James

Participant
February 13, 2019

And here I demonstrate to the community why answering a person's question can be dangerous.

Because, more questions.

a. I am curious why...

app.selection[0].transparencySettings.blendingSettings.opacity=10;

...worked, and why...

myObject.transparencySettings.bevelAndEmbossSettings.angle = 99;

...also worked, when the two instructions have different "prefixes." I have found nothing that explains to me what the proper form of that portion should be, nor how/why these differences may apply. (Is there Real Beginners Site on this where can I learn that?)

b. Further, if I wish to apply a number of these preferences at once, can I merely enter them line by line, with their values, in the Editor and save them as a new script? I realized today, after creating the bevel settings scripts I needed, that there may be a few additional scripts such as resetting the bevel to 0 (i.e., turning it off entirely).

c. This may sound dumb, because I have "understood" this aspect but did not apply that knowledge to scripting: this script will only "set the angle" for the bevel, surgically as it were, but it will not turn the bevel ON or givie it a direction without other preferences being set. Boing! (That's my head hitting the keyboard). So here's the scenario I have realized that I follow for each graphic, given I am working with both pre-existing material and new material:

c1 load a new graphic (or select an existing graphic) [Manual step, either load or select first]

c2 center the graphic in the current active box (necessary for pre-existing graphics, they are wildly oversized)

c3 fit the frame to the graphic (these graphics are all at a consistent size)

c4 round the 4 corners (to a value that matches the counter die cut)

c4 rotate the graphic around its center to the desired "facing" angle

c5 turn on the drop shadow effect (use its default settings—the client likes them as they are)

c6 turn on bevel and set the size, angle, altitude

Making an all-in-one script like this is akin to "hard-coding" from what little I have heard (and a thing to avoid). Perhaps a set of purpose-built, smaller scripts might be a simpler and more flexible approach, only combining effects that occur together (like Center+Fit Frame; Round Corners, Add Shadow, the 6 Rotate+Bevel scripts, and Bevel Off, for a total of 10). More than enough for my brain at this point!

d. This is a part-coder/part-designer question, but what design need goes into setting the object, fill, stroke, or content transparency to different values? For example, some pre-existing work in my current project has a drop shadow set to the Fill of the object.

Does placing it at that level appear differently than placing it at the object level? I realize these fine-tuning controls exist, but I have not yet encountered a situation where using one or the other is a clear choice. Uwe's note made me curious, and I wish to understand the reasoning that lends itself to "when to use" these distinct settings.

Thank you again for your answers!

P.S. If this becomes burdensome, please know you can point me in the direction of resources on "learning to script when you know what you need but not how to get there." I've no wish to take your knowledge for granted.

Respectfully,

James

Participant
February 13, 2019

And this note is merely to show I *can* write a short post. Honest.

;-)

James

Community Expert
February 12, 2019

Hi James,

also note that there are four settings regarding transparency of an object on the page:

 

transparencySetting

https://www.indesignjs.de/extendscriptAPI/indesign8/#TransparencySetting.html

 

contentTransparencySetting

https://www.indesignjs.de/extendscriptAPI/indesign8/#ContentTransparencySetting.html

 

fillTransparencySetting

https://www.indesignjs.de/extendscriptAPI/indesign8/#FillTransparencySetting.html

 

strokeTransparencySetting

https://www.indesignjs.de/extendscriptAPI/indesign8/#StrokeTransparencySetting.html

 

Regards,
Uwe Laubender

 

EDITED: Links were dead.

TᴀW
TᴀWCorrect answer
Legend
February 12, 2019

So close!

Try:

myObject.transparencySettings.bevelAndEmbossSettings.angle = 99;

... all I've changed is the lowercase b for bevel, and a plural s for bevelAndEmbossSettings.

Note that the angle must be express as a value between -180 and 180 degrees.

Also, if needed, there's the property

contentTransparencySettings

... if you want to apply bevel to the content itself.

HTH,

Ariel

Visit www.id-extras.com for powerful InDesign scripts that save hours of work — automation, batch tools, and workflow boosters for serious designers.