<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Help! Automation image painting in panel]]></title><description><![CDATA[<pre><code>const var instimg_pnl1 = Content.getComponent ("instimg_pnl1");
instimg_pnl1.loadImage("{PROJECT_FOLDER}instimg_pnl1.png", "instimg_pnl1");
instimg_pnl1.setPaintRoutine(function(g)
{
var a = this.getLocalBounds(0);
g.drawImage ("instimg_pnl1", a, 0, 0);
});

const var instimg_pnl2 = Content.getComponent ("instimg_pnl2");
instimg_pnl2.loadImage("{PROJECT_FOLDER}instimg_pnl2.png", "instimg_pnl2");
instimg_pnl2.setPaintRoutine(function(g)
{
var a = this.getLocalBounds(0);
g.drawImage ("instimg_pnl2", a, 0, 0);
});

const var instimg_pnl3 = Content.getComponent ("instimg_pnl3");
instimg_pnl3.loadImage("{PROJECT_FOLDER}instimg_pnl3.png", "instimg_pnl3");
instimg_pnl3.setPaintRoutine(function(g)
{
var a = this.getLocalBounds(0);
g.drawImage ("instimg_pnl3", a, 0, 0);
});

const var instimg_pnl4 = Content.getComponent ("instimg_pnl4");
instimg_pnl4.loadImage("{PROJECT_FOLDER}instimg_pnl4.png", "instimg_pnl4");
instimg_pnl4.setPaintRoutine(function(g)
{
var a = this.getLocalBounds(0);
g.drawImage ("instimg_pnl4", a, 0, 0);
});

const var instimg_pnl5 = Content.getComponent ("instimg_pnl5");
instimg_pnl5.loadImage("{PROJECT_FOLDER}instimg_pnl5.png", "instimg_pnl5");
instimg_pnl5.setPaintRoutine(function(g)
{
var a = this.getLocalBounds(0);
g.drawImage ("instimg_pnl5", a, 0, 0);
});
</code></pre>
<p dir="auto">i have writen code that paints image for each panel separately how do i write a loop that minimize the amount of code</p>
]]></description><link>https://forum.hise.audio/topic/14369/help-automation-image-painting-in-panel</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 11:53:54 GMT</lastBuildDate><atom:link href="https://forum.hise.audio/topic/14369.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 07 Feb 2026 12:59:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Help! Automation image painting in panel on Sat, 07 Feb 2026 19:15:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.hise.audio/uid/12">@David-Healey</a> Yeah, me too. But I thought for someone learning how to do the basics of optimising repetitive code into loops, I would just show the basic method.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.hise.audio/uid/3304">@goldee</a> What David means, if we're talking about the same thing, is that you can get an array of components and loop through them directly, instead of fetching each one by name.</p>
<pre><code>const panels = Content.getAllComponents("instimg_pnl\\d+");

for (panel in panels)
{
  panel.loadImage("{PROJECT_FOLDER}" + panel.getId() + ".png", "img");
  panel.setPaintRoutine(function(g)
  {
    var a = this.getLocalBounds(0);
    g.drawImage("img", a, 0, 0);
  });
}
</code></pre>
]]></description><link>https://forum.hise.audio/post/117558</link><guid isPermaLink="true">https://forum.hise.audio/post/117558</guid><dc:creator><![CDATA[dannytaurus]]></dc:creator><pubDate>Sat, 07 Feb 2026 19:15:16 GMT</pubDate></item><item><title><![CDATA[Reply to Help! Automation image painting in panel on Sat, 07 Feb 2026 18:19:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.hise.audio/uid/3304">@goldee</a> thank you so much</p>
]]></description><link>https://forum.hise.audio/post/117555</link><guid isPermaLink="true">https://forum.hise.audio/post/117555</guid><dc:creator><![CDATA[goldee]]></dc:creator><pubDate>Sat, 07 Feb 2026 18:19:26 GMT</pubDate></item><item><title><![CDATA[Reply to Help! Automation image painting in panel on Sat, 07 Feb 2026 15:47:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.hise.audio/uid/357">@dannytaurus</a> I'd turn panels into an array of references instead of ids</p>
]]></description><link>https://forum.hise.audio/post/117554</link><guid isPermaLink="true">https://forum.hise.audio/post/117554</guid><dc:creator><![CDATA[David Healey]]></dc:creator><pubDate>Sat, 07 Feb 2026 15:47:10 GMT</pubDate></item><item><title><![CDATA[Reply to Help! Automation image painting in panel on Sat, 07 Feb 2026 14:56:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.hise.audio/uid/3304">@goldee</a> To put this in a loop, I would grab the block that is repeated each time:</p>
<pre><code>const var instimg_pnl1 = Content.getComponent ("instimg_pnl1");
instimg_pnl1.loadImage("{PROJECT_FOLDER}instimg_pnl1.png", "instimg_pnl1");
instimg_pnl1.setPaintRoutine(function(g)
{
  var a = this.getLocalBounds(0);
 g.drawImage ("instimg_pnl1", a, 0, 0);
});
</code></pre>
<p dir="auto">And put it in a loop structure:</p>
<pre><code>for (panel in panels) // we'll make the panels list later
{
  const var instimg_pnl1 = Content.getComponent ("instimg_pnl1");
  instimg_pnl1.loadImage("{PROJECT_FOLDER}instimg_pnl1.png", "instimg_pnl1");
  instimg_pnl1.setPaintRoutine(function(g)
  {
    var a = this.getLocalBounds(0);
    g.drawImage ("instimg_pnl1", a, 0, 0);
  });
}
</code></pre>
<p dir="auto">Then change the <code>instimg_pnl1 </code> var name to something generic and reusable, <code>p</code>:</p>
<pre><code>for (panel in panels)
{
  const var p = Content.getComponent ("instimg_pnl1"); // 👈 p
  p.loadImage("{PROJECT_FOLDER}instimg_pnl1.png", "instimg_pnl1"); // 👈 p
  p.setPaintRoutine(function(g) // 👈 p
  {
    var a = this.getLocalBounds(0);
    g.drawImage ("instimg_pnl1", a, 0, 0);
  });
}
</code></pre>
<p dir="auto">Then identify the parts of the block that change each time. In this case it's the <code>instimg_pnl1</code> string used 4 times in the block. Change that to the <code>panel</code> string we're passing in from the <code>for</code> loop:</p>
<pre><code>for (panel in panels)
{
  const var p = Content.getComponent (panel); // 👈 panel
  p.loadImage("{PROJECT_FOLDER}" + panel + ".png", panel); // 👈 panel, panel
  p.setPaintRoutine(function(g)
  {
    var a = this.getLocalBounds(0);
    g.drawImage (panel, a, 0, 0); // 👈 panel
  });
}
</code></pre>
<p dir="auto">Now build the list of panels from your original code. There are a few ways to do this but let's use the full names:</p>
<pre><code>const panels = ["instimg_pnl1","instimg_pnl2","instimg_pnl3","instimg_pnl4","instimg_pnl5"]
</code></pre>
<p dir="auto">Add this to the loop and we're done:</p>
<pre><code>const panels = ["instimg_pnl1","instimg_pnl2","instimg_pnl3","instimg_pnl4","instimg_pnl5"]

for (panel in panels)
{
  const var p = Content.getComponent (panel); 👈 panel
  p.loadImage("{PROJECT_FOLDER}" + panel + ".png", panel); 👈 panel, panel
  p.setPaintRoutine(function(g)
  {
    var a = this.getLocalBounds(0);
    g.drawImage (panel, a, 0, 0); 👈 panel
  });
}
</code></pre>
]]></description><link>https://forum.hise.audio/post/117553</link><guid isPermaLink="true">https://forum.hise.audio/post/117553</guid><dc:creator><![CDATA[dannytaurus]]></dc:creator><pubDate>Sat, 07 Feb 2026 14:56:37 GMT</pubDate></item></channel></rss>