Jump to content

Dynamic Background Fill


Recommended Posts

Hello! I'm trying to work out the code to allow for a field selection to determine the fill color of a text box. I have 20 fields named Color1-20  with the selection of either Blue or Gray. My text boxes are named Box1-20. Blue = Denim and Gray = Ash in my color palette.

Based on looking at the threads I pulled out this one because I thought it could work:

}
var colorName = Field("Color1") == "Blue" ? "Denim" : "Ash";
FindTextFrame("Box1").fillColorName = colorName;
}
 

I had it working but then I tried to duplicate it for all of my boxes and I can't get it to work past Box 1. Just a note if you look at the image it will say BoxA-E. I was testing whether it was my box names causing an issue. I'd like to keep it named Box 1-20. I know I could put in graphic boxes behind the text box but I was hoping to not make this page more complicated and figured I could do it with code. I hope that makes sense! 

Screenshot 2023-09-29 081422.png

Link to comment
Share on other sites

It's hard to know what you're trying to accomplish without more context.

You probably want to have a loop to go through all of the frames, something like:

for (var i = 1; i <= 20; i++)
{
    FindTextFrame("Box" + i).fillColorName = colorName;
}

Though I think there's a fundamentally different way that you can put this job together.  It seems like a lot of effort to line up all of those frames, which could be automated with a rule.  (As we like to say, the reason you have a computer in the first place is to automate repetitive tasks.)

There are a few things you could do: The simplest might be to create a table.  Another would be to create the frames programmatically, with calls to GetBodyPage(1).AddFrame() and setting the x, y, width, and height properties of the returned frame object, with a bit of math to space things out the way you want.

Again, more context of what output you're trying to make would make it easier to make more specific suggestions.

Link to comment
Share on other sites

Thanks for the feedback sorry I didn't provide enough information! Here is an output example that this page may create. 

The creator basically has up to 20 boxes to fill in on this page based on the diagram they are trying to display. They are filling in the fields for each box they are connecting together. Because of the nature of the flexibility, they want to include/exclude boxes a table didn't feel like it would work the way we wanted it to. 

Each box has:

  • A content field (multi line text) Rule already built to change font color based on fill color.
  • Box fill color (dropdown pick list) - this is where I'm trying to apply the rule in question
  • Graphic choices for the in between arrows connecting one box to another.

They are choosing the color for each box via a field for example:

Field "Color1" = Fill text frame "Box1"

Field "Color2" = Fill text frame "Box2"

 

Does this help at all? 

 

Screenshot 2023-10-02 132828.png

Link to comment
Share on other sites

Thanks for the picture.  This is an interesting job.

I think a table could work.  That double-wide box in your picture could be accomplished with an "hstraddle=3" attribute on the <cell> tag to merge multiple table cells together.  The fill color can be accomplished with the "shading" attribute.  You can also use the "minheight" attribute on your <row> tags to set the height of the boxes.  The arrows can just be inline graphics in their own smaller rows and columns.

If you're not using a table, then to accomplish the double-wide box in your picture, you would need to either have a separate frame, and suppress the other boxes you're not showing, or modify the width of that frame.  But the more I think about this, a table seems easier to line everything up.

Link to comment
Share on other sites

Thank you @Dan Korn I appreciate the suggestion for putting it into table and will definitely go back and set this up that way when I have the opportunity. Since I already have it built with the separate boxes, etc. Is there no code that will work that will allow for the background fill to change based on the choices I've set up?

Link to comment
Share on other sites

6 hours ago, heather-grzybowski said:

Thank you @Dan Korn I appreciate the suggestion for putting it into table and will definitely go back and set this up that way when I have the opportunity. Since I already have it built with the separate boxes, etc. Is there no code that will work that will allow for the background fill to change based on the choices I've set up?

I think this should work, but I can't verify it without your job files:

for (var i = 1; i <= 20; i++)
{
    var colorName = Field("Color" + i) == "Blue" ? "Denim" : "Ash";
    FindTextFrame("Box" + i).fillColorName = colorName;
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...