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

Can I make an objects width adjustable based on a number that is typed before it?

Contributor ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

I'm building a template for a report I'm trying to automate. I have a series of numbers that will be pulled in via data merge, and I'd like to automate a bar-type graph that is based off those numbers.

 

basically when the number 44% is pulled in it would adjust the width of the colored bar that is anchored next to it to 44 pixels or it would take a full size bar and reduce the width to 44%?

Screen Shot 2022-03-09 at 10.18.12 AM.png

I will have maybe hundreds of these instances so it would be great to be able to link them or maybe a script where the object style is depended on parapgraph style that appears before it?

 

I'm open to any ideas that I can play around with!

TOPICS
How to , Scripting

Views

276

Translate

Translate

Report

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 2 Correct answers

Community Expert , Mar 09, 2022 Mar 09, 2022

You can have every group named as like a library item. Something like: "bar-graph". You name stuff in the layers library. 

Then you could do something like: 

var gs = app.activeDocument.groups;
for (var i = 0; i < gs.length; i++) {
    if (gs[i].name == "bar-chart") { 
        var numFrame = gs[i].textFrames.itemByName("num1");
        var containingBar = numFrame.rectangles.itemByName("bar");
        rejiggerBar(numFrame, containingBar);      
    }
}

Your rejiggerBar function could parse the i

...

Votes

Translate

Translate
Contributor , Mar 10, 2022 Mar 10, 2022

it really is neat! i enjoy figuring out a challenge and making things super efficient.

 

In case someone shows up on this thred and wants to know more ... 

It includes 100 conditional character styles and 100 stroke styles 1-100 for each. my character styles are based off the first so if those have to change its only 1 style i'm adjusting.

 

All four of the entries below use the same 1 paragraph style with some nested and grep styles built in and. The bars are built into the style.

Screen Shot 2022-03-10 at 10.53.00 AM.png

  • All I have to do is
...

Votes

Translate

Translate
Community Expert ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

Definitely possible via script. Basically you could group each object, then for each group, reach the number value and adjust the rectangle value's bounds position. Not really a trivial task however. Have you ever scripted before?

Votes

Translate

Translate

Report

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
Contributor ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

I have but still pretty beginner, I've been able to write some and then study others to find answers but a lot of the time it still needs a lot of tweaking.

Votes

Translate

Translate

Report

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
Contributor ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

Within my main text frame I have as follows:

  1. subhead (p-style: subhead_1)
  2. anchored inline grouped items: (p-style: grouped_stat)
  • text frame with data percentage  (p-style: data_med_number)
  • value bar (ob-style: value_bar)

 

for the script, do I search for the object style? do i need an object style for the grouped items? sometimes the bar is in the 2nd or 3rd colomn of my text frame, and I want the pixel length to match the data its grouped. I can try and piece together some language but I'm not sure exactly which route to take it.

 

Screen Shot 2022-03-09 at 2.49.09 PM.png

Votes

Translate

Translate

Report

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
Community Expert ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

You can have every group named as like a library item. Something like: "bar-graph". You name stuff in the layers library. 

Then you could do something like: 

var gs = app.activeDocument.groups;
for (var i = 0; i < gs.length; i++) {
    if (gs[i].name == "bar-chart") { 
        var numFrame = gs[i].textFrames.itemByName("num1");
        var containingBar = numFrame.rectangles.itemByName("bar");
        rejiggerBar(numFrame, containingBar);      
    }
}

Your rejiggerBar function could parse the integer of the text frame and resize the containing bar to spec. But that's where the magic comes in. If your library has two bars, you could name the num1 and num2 and pass both sets to a rejiggerBar function. 

 

Lots of ways to slice it, and it's not trivial. Good luck!

Votes

Translate

Translate

Report

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
Contributor ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

Thank you so much! I will absolutely be trying this and putting it to good use!

 

I actually did figure out a way to accomplish what I needed using grep in my paragraph style with different stroke styles and character styles and it works automatically when the numbers are changed which will hopefully avoid issues since I'll have possibly a 100 entries.

Votes

Translate

Translate

Report

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
Community Expert ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

Sounds like a clever solution as well.

Votes

Translate

Translate

Report

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
Contributor ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

it really is neat! i enjoy figuring out a challenge and making things super efficient.

 

In case someone shows up on this thred and wants to know more ... 

It includes 100 conditional character styles and 100 stroke styles 1-100 for each. my character styles are based off the first so if those have to change its only 1 style i'm adjusting.

 

All four of the entries below use the same 1 paragraph style with some nested and grep styles built in and. The bars are built into the style.

Screen Shot 2022-03-10 at 10.53.00 AM.png

  • All I have to do is type:   [Percentage #]tabright indent tabsoft return[category specific text]
  • The gray base bar is set as a 'rule above' with a stroke style only 100pixels wide within the paragraph style
  • the colored value bars are character styles using underline, any point size for the height and then stroke styles 1-100 that have specific length dashes (10% bar has the first dash 10points wide and then 10" gap so the dash doesnt repeat)
  • built-in grep is used to shrink the category text, assigned to those specific words, using nested styles will mess up the other built in automation.
  • built-in grep is used to assign the color value bar character style to the right indent tab using 'lookbehind' for numbers 1-100. 
  • built-in grep is used to change colors on the percentage and bar using 'lookahed' for the specific category text

 

For example: the 10% activated the 10pt value bar and the color for both changed to red because ‘Female’ was typed; the 5% activated the 5pt value bar and the color for both changed to teal because ‘Male’ was typed.  

 

hope this helps someone!

 

Votes

Translate

Translate

Report

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
Contributor ,
Mar 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

LATEST

As I worked with this more ... I found it even more efficient to have 100 thin spaces with a character style I use to change the width of the bars. then use the below grep style to have a value bar character style assigning the length ... and then I dont need the 100 character styles or the 100 stroke styles 🙂 

 

(?<=^1%\t)~|{1}|(?<=^2%\t)~|{2}|(?<=^3%\t)~|{3}|(?<=^4%\t)~|{4}|(?<=^5%\t)~|{5}|(?<=^6%\t)~|{6}|(?<=^7%\t)~|{7}|(?<=^8%\t)~|{8}|(?<=^9%\t)~|{9}|(?<=^10%\t)~|{10}|(?<=11%\t)~|{11}|(?<=12%\t)~|{12}|(?<=13%\t)~|{13}|(?<=14%\t)~|{14}|(?<=15%\t)~|{15}|(?<=16%\t)~|{16}|(?<=17%\t)~|{17}|(?<=18%\t)~|{18}|(?<=19%\t)~|{19}|(?<=20%\t)~|{20}|(?<=21%\t)~|{21}|(?<=22%\t)~|{22}|(?<=23%\t)~|{23}|(?<=24%\t)~|{24}|(?<=25%\t)~|{25}|(?<=26%\t)~|{26}|(?<=27%\t)~|{27}|(?<=28%\t)~|{28}|(?<=29%\t)~|{29}|(?<=30%\t)~|{30}|(?<=31%\t)~|{31}|(?<=32%\t)~|{32}|(?<=33%\t)~|{33}|(?<=34%\t)~|{34}|(?<=35%\t)~|{35}|(?<=36%\t)~|{36}|(?<=37%\t)~|{37}|(?<=38%\t)~|{38}|(?<=39%\t)~|{39}|(?<=40%\t)~|{40}|(?<=41%\t)~|{41}|(?<=42%\t)~|{42}|(?<=43%\t)~|{43}|(?<=44%\t)~|{44}|(?<=45%\t)~|{45}|(?<=46%\t)~|{46}|(?<=47%\t)~|{47}|(?<=48%\t)~|{48}|(?<=49%\t)~|{49}|(?<=50%\t)~|{50}|(?<=51%\t)~|{51}|(?<=52%\t)~|{52}|(?<=53%\t)~|{53}|(?<=54%\t)~|{54}|(?<=55%\t)~|{55}|(?<=56%\t)~|{56}|(?<=57%\t)~|{57}|(?<=58%\t)~|{58}|(?<=59%\t)~|{59}|(?<=60%\t)~|{60}|(?<=61%\t)~|{61}|(?<=62%\t)~|{62}|(?<=3%\t)~|{63}|(?<=64%\t)~|{64}|(?<=65%\t)~|{65}|(?<=66%\t)~|{66}|(?<=67%\t)~|{67}|(?<=68%\t)~|{68}|(?<=69%\t)~|{69}|(?<=70%\t)~|{70}|(?<=71%\t)~|{71}|(?<=72%\t)~|{72}|(?<=73%\t)~|{73}|(?<=74%\t)~|{74}|(?<=75%\t)~|{75}|(?<=76%\t)~|{76}|(?<=77%\t)~|{77}|(?<=78%\t)~|{78}|(?<=79%\t)~|{79}|(?<=80%\t)~|{80}|(?<=81%\t)~|{81}|(?<=82%\t)~|{82}|(?<=83%\t)~|{83}|(?<=84%\t)~|{84}|(?<=85%\t)~|{85}|(?<=86%\t)~|{86}|(?<=87%\t)~|{87}|(?<=88%\t)~|{88}|(?<=89%\t)~|{89}|(?<=90%\t)~|{90}|(?<=91%\t)~|{91}|(?<=92%\t)~|{92}|(?<=93%\t)~|{93}|(?<=94%\t)~|{94}|(?<=95%\t)~|{95}|(?<=96%\t)~|{96}|(?<=97%\t)~|{97}|(?<=98%\t)~|{98}|(?<=99%\t)~|{99}|(?<=100%\t)~|{100}

Votes

Translate

Translate

Report

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