Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Subtracting Percentage from Pricing Script

Return to Member Forum

  • Author
    Posts
    • #95244
      Scott Irwin
      Member

      Hello everyone,

      I’ve been using the Number Adjuster script for a long time now. It’s a real time saver. I can add/subtract a dollar amount to my sale pricing (Character style) in my catalog. But one thing I can’t do is adjust the price when I need to subtract a percent off. I have to do it manually via a % calculator online and then type the correct price in.

      If my pricing is $49.99 and it’s 50% off, the sale price would be $24.99, 25% off would be $37.49, etc.

      Is there a script similar to the number adjuster or price adjuster script that will basically subtract the % off from the price (or character style)?

      Thanks
      Scott

    • #95248

      Hi,

      Do you treat it manually, price per price?! …

      More funny if you want to add 15% to all the catalogue with several thousands of prices!!! =D

      (^/)

    • #95250
      Scott Irwin
      Member

      Add 15% to all items and make more money, I’m down with that!

      Each copy block can have anywhere from one or more price lines. The general look for one copy block is:

      Item description
      Body Copy
      Size / price line $49.99
      Size / price line $49.99
      Size / price line $56.99

      Each of those items is its own paragraph (with the appropriate paragraph / character styles added)

      That is really the whole thing, only sometimes there is just one price line. But each copy block is always the same discount. So if those prices are Save $5, they are all $5 off, if they are 20% off, all of them would be reduced 20%.

      That’s why the number adjuster script works so well. I just select all the copy blocks on a page and tell the script to subtract $10 or whatever from the Sale Price character style, and all of them are done.

    • #95252
      David Blatner
      Keymaster

      Scott: I think I know the problem, but I want to be sure: NumberAdjuster will let you multiply by 0.5, but $49.99 would become $24.98… right? And you want it $24.99?

    • #95255
      Scott Irwin
      Member

      David,

      50% of 49.99 = 24.995, so I use 24.99.
      50% of 56.99 = 28.495, so I use 28.49.

      Using those 2 prices as an example for number adjuster and multiplying by 0.5, rounding to 2 decimal places, I get the following:

      0.5 X 49.99 = 25
      0.5 X 56.99 = 28.5

      Rounding to 3 decimal places yields me the same results as the calculator, but would require me to manually remove the 3rd decimal place number.

      Hope that makes sense.

    • #95268
      Peter Kahrel
      Participant

      Scott,

      To subtract a percentage, multiply the number by 100 minus the percentage. So to subtract 25% off prices, multiply by 0.75. I can’t remember if NumberAdjuster lets you set the number of decimals — if it can, use that. If it can’t, use this script:
      https://www.kahrel.plus.com/indesign/price_adjuster.html
      (which is a merge of NumberAdjuster and Olav Kvern’s PriceUpdateByString script). Indicate that you want two decimals. If that doesn’t give you the desired rounding (can’t remember now what the script does), then run it and use three or even four decimals.

      To get rid of the third and maybe the forth decimal, use this GREP query:

      Find what: [$\d,]+\.\d\d\K\d+
      Change to

      This query says ‘match any digits that are preceded by a dollar symbol followed by any digits and commas followed by a dot and two digits and delete them’. So it chops the third and any following digits off your prices.

      Peter

    • #95271
      Scott Irwin
      Member

      Peter,

      I’ve got both Number Adjuster and Price Adjuster scripts now. I’ve ran tests with both of them, and each one yields almost exact results. I believe the problem stems from the fact that both scripts round UP to the next number, hence changing the final price.

      Number Adjuster has a section that is says “how many decimals to round to?” while Price Adjuster call that “Number of Decimals” but they both do the same thing.

      Both of the scripts set to 2 decimal places give me this:

      Number Adjuster – 70% of 79.99 = 24
      Price Adjuster – 70% of 79.99 = 24.00 (I like this format better)
      What I need is 23.99

      Doing the same thing with each script set to 3 decimal places:

      Number – 70% of 79.99 = 23.997
      Price – 70% of 79.99 = 23.997

      So it seems that the 3rd decimal number is being rounded up, and skewing the final result. Is there a way to prevent that from happening? So it just doesn’t round the number at all, and leaves the 2 decimal places alone?

      or should I leave one of the scripts set to 3 decimal places and use the GREP find/change to remove the 3rd number. I can do that, and I’ve tested it and it works so far, but it’s still another step (albeit faster than doing the pricing by hand).

    • #95275
      Peter Kahrel
      Participant

      > or should I leave one of the scripts set to 3 decimal places and use the GREP find/change to remove the 3rd number.

      That’s the only way to go about it as far as i can see.

      > I can do that, and I’ve tested it and it works so far, but it’s still another step (albeit faster than doing the pricing by hand).

      It’s only a small step. You can save the GREP query (in the Find/Change window) for future use, or you can put it in a separate script:

      app.findGrepPreferences = app.changeGrepPreferences = null;
      app.findGrepPreferences = ‘[$d,]+.ddKd+’;
      app.documents[0].changeGrep();

      There are many ways in which numbers can be finished. I’ve had requests for rounding everything up, rounding everything down, rounding up or down to the next 5 cents, not rounding. And your requirement is a bit different again. It’s not really possible to build all that into the script. Almost all these things can be handled by either a GREP query or a simple script.

      P.

    • #95277

      Hi Scott, David and Peter,

      Maybe something like this [ for free! ]:

      Just select something (text or text frame), launch the script and enter the %!
      The script will adjust the price on the previous second decimal
      Of course, possible Undo!

      Add-Substract Percentage On Selection! …  (^/)  ;-)

      https://www.dropbox.com/s/yuo0jbwgagvxz6b/0174_Add-SubstractPercentageOnSelection_MichelAllio.jsxbin.zip?dl=0

      At your own risk!

      … Well, sometimes, I can be cool! ;-)

      (^/)

    • #95317
      Scott Irwin
      Member

      @ Peter – Thanks for your help! I saved your GREP query when I was testing this a few days ago. As far as your script to automate that, I don’t know where I’m suppose to type that script into, to make it a script? I tried Script Editor, but it comes up with an error. Is there some other place / program I need to use to make it a script I can use in Indesign?

      @ Obi-wan – That’s pretty cool! and does indeed give me the correct price with the correct number of decimal places. The only issue with it is that it will only change the first set of numbers in my price line, and not the actual sale pricing. lol. If there was a way to have it give you the option to select a specific character style (which I use for sale pricing) and have it only change that price, that would save a lot of time. As of right now I’d have to highlight each price and use the script. Is that an easy addition?

    • #95318
      Peter Kahrel
      Participant
    • #95322

      Hi Scott,

      Could you show us a “real” page? [mode preview with invisible chars]

      (^/)

    • #95324
      Scott Irwin
      Member

      @ Obi-wan – here is a sample sale copy block. The NOW prices are in red and are the ones that are changed to reflect the sale pricing. Those are the ones that have the % off.

      Example Sale Copy Block

      @ Peter – thanks for the link. I’ve done everything correctly but the script gives me errors. Here are two screen shots. One is the script in the ExtendScript toolkit and the second is the error the script gives me

      View post on imgur.com

      • #95326
        Masood Ahmad
        Participant

        Regarding the error, I think you have to change the single quote signs with Straight Quote signs '

    • #95327
      Scott Irwin
      Member

      I changed both of those quotes to the single quote, but it still didn’t work. Though it did give me a different error.

      View post on imgur.com

      The GREP string in the script is different than the on I used in Find/Change, but I figured it had something to do with scripting.

    • #95328

      Scott, Something I don’t truly understand: How you do play your changes?
      Does the char style applied define the percentage you want to add/substract?
      Have you systematically single text boxes as here, placed on the pages?
      Have you systematically on the first line [in Red] the added/substracted %?

      (^/)

    • #95330
      Peter Kahrel
      Participant

      Scott — How is that for multi-tasking, with two approaches assailing you?

      Sorry, the second line in the script should be

      app.findGrepPreferences.findWhat = ‘[$d,]+.ddKd+’;

      (and if you copy this line. mind the quotes).

      P.

      • #95338
        Scott Irwin
        Member

        Yes, but the Sale discount is always in the first paragraph of the copy block, BUT I have to manually type that in. So when I do my find change to insert the sale pricing it will put a SAVE $0 in the first paragraph, and I then go through and either change it by hand, or use the price adjuster to add the correct amount of money. But when it comes to adding the % amount to that first paragraph I always type it in by hand.

        @ Peter – Thanks for the correction. The script works great! I now have Price Adjuster (set to 3 decimal places for my percents) and Number adjuster (set to two for dollars), and the GREP script setup on their own keyboard shortcuts, so it’s just the press of 2 or 3 buttons now to format a page of sale prices!! Very fast, and very efficient.

        EDIT – sorry, I replied to the post, instead of putting this in it’s own at the bottom.

    • #95332
      Scott Irwin
      Member

      Obi – I made a character style called “SALE” which is basically nothing more than a RED version of the normal font. But because it’s its own style I can then use the Number Adjuster or Price Adjuster script to change the price of any number with just that character style. So I just shift-click all the copy blocks that are going to have the same sale pricing and use the script. It works fantastic when I have to add or subtract amounts.

      The copy block that I used in the pictures is just one of many on a spread. usually anywhere from 1 to 12 copy block are on a spread. Not all items will be on sale, which is why I use Shift-Click to select only the copy blocks I need to change the pricing.

      You’ll notice in the screenshot that there is an area in the script that allows me to select what style I want to apply the math too.

      View post on imgur.com

      The result ends up looking like this:

      View post on imgur.com

      Then I would use Peter’s GREP query to remove the 3rd decimal place number and end up with the correct pricing.

      Using your script – before:

      View post on imgur.com

      After (you can see it changes the first number and not the sale price)

      View post on imgur.com

      Also, if you cancel the script, it changes the first price to $0.00

      View post on imgur.com

    • #95335

      Do you mean that the “%” is written on the first line for each text frame?

      • #95340
        Scott Irwin
        Member

        Yes, but the Sale discount is always in the first paragraph of the copy block, BUT I have to manually type that in. So when I do my find change to insert the sale pricing it will put a SAVE $0 in the first paragraph, and I then go through and either change it by hand, or use the price adjuster to add the correct amount of money. But when it comes to adding the % amount to that first paragraph I always type it in by hand.

    • #95343

      Just to finish:

      Have you a “database” or excel file with all the product references (apparently in blue in the screenshot, the current price (barred in red) and the % defined (in the first line (==> of course, the final prix (in red in the screenshot)?

      (^/)

    • #95344
      Scott Irwin
      Member

      We don’t put any of the sale pricing information into the database because it constantly changes from book to book. So when the initial copy block is pushed onto the page it comes in with just the regular price (which is NOT barred).

      When the item goes on sale I then use find/change queries to “add” all that information to the copy block as you’ve seen in previous screenshots. Once the copy block has the Red Save $0 in the first paragraph, and the Sale Price in RED in the other paragaraphs, I use the scripts to change the pricing.

      So the database doesn’t contain anything but the basic information and regular price. Everything after that is added in Indesign on the fly when it needs to change.

    • #95345

      OK!

      If I had to do it simply, I would use a simple Excel file based on the product reference.

      My script is based on Grep, So from the product reference and accessory details:
      1/ the % would be automatically inserted (line 1)
      2/ the new prices too (with the +/- %) (last lines)
      3. the old prices automatically barred (anchored stroke) or not (last lines)

      So, one Excel file, one click in ID (to launch the script that does all in one time).

      (^/) ;-)

      PS: Just one code line to add to insert a char style feature in my script!

    • #95357
      Scott Irwin
      Member

      I’m pretty sure having to make a separate excel file would be way to time consuming, when I can just change the numbers manually. But if you can make the script allow the user to select what character style to apply the change too, that would be the better solution. I would also request that if you start the script and then click cancel that it doesn’t zero out the pricing, but instead just leaves it as-is.

      I’d also like to thank everyone for all the help and fast response to my initial question. You guys are awesome!

    • #95358

      This night I thought about a cool way to play this game!

      I suppose your layout is a puzzle of text frames! for each, there is (are) product(s) and a “%” +/- change.

      So, 2 types of scripts:

      1/ For defining what kind of % you apply: with the “black-arrow” tool, you select a text frame and play this script:
      => its fill-color (actually “none”) becomes Red30% (or Red50% or Red70% …). That means you’ll apply a -30% (or -50% or -70% …) to all the prices into it.
      => its fill-color (actually “none”) becomes Green5%. That means you’ll apply a +5% to all the prices into it …
      a one-code-line script per color (duplications).
      So, you can do this very quickly as a cool game: click-click-click…! Nothing to type!

      2/ When all is done, just launch the “big” script:
      It will loop on the text frames: if a fill-color == “Red30%”, it will change the color to “none”, insert “”SAVE 30%. ” text (in red) in the first line, barres the prices and adds new prices with +/– %.

      That’s all!

      When time, I’ write it! Just for fun!

      (^/)

Viewing 22 reply threads
  • You must be logged in to reply to this topic.
Forum Ads