# Swapping every first and third channel or swap by name

Hi,
In the attached image I have what I think is a very easy problem to solve but one that I can not solve.

I have a list of channels that go “B G R” (I believe the reorder’s numeric suffix sort also reorders things alphabetically" and I want to swap it so the Red channel comes first (ideally with the correct label (of R) as well).

Please let me know if this is possible.

You could select CHOP out each chunk, example: r* , g*, b* and merge the 3 select CHOPs back together.

Or you could create a constant CHOP with the order you need: r[0-9], g[0-9], b[0-9]
and then use that as reference input to the Reorder CHOP, or even input to a Replace CHOP.

Cheers
Rob

Sorry Rob, I was unclear with my question and that photo scrolls to a position that is not illustrative. What I have is something like
b0
g0
r0
b1
g1
r1
b2
g2
r2

And what I want is to flip the first and third channel positions so that I have:
r0
g0
b0
r1
g1
b1
r2
g2
b2

In otherwise flip the first and third channels, every three channels. Is there a way to do that?

Try this Python expression for the character pattern in the Reorder CHOP:

``['r'+str(x) + ' g'+str(x) + ' b'+str(x) for x in range(0,int(me.inputs[0].numChans/3))]``

Should generate: r0 g0 b0 r1 g1 b1 r2 g2 b2…

Hi Selina,
Unfortuantely that seems to only work for the channels that start at r10.

It also has the unwanted side effect of shifting all the channels that start with a zero to the last channels.

So what I am now left with is this image (note the location and order of channels starting with zero such as b00, g00, r00.

Thanks for your help

``['r'+str(x).zfill(2) + ' g'+str(x).zfill(2) + ' b'+str(x).zfill(2) for x in range(0,int(me.inputs[0].numChans/3))]``

You can pad the integer string with zfill. That should give you a string like: r00 g00 b00 r01 g01 b01 r02 g02 b02… If you don’t know how many channels you will have, assuming that you’ll have r, g, b for each, you can replace the 2 with

``len(str(int(me.inputs[0].numChans/3)))``

You can use the reorder chop, using numeric suffix sort. The thing is that it sorts the basename of the channel alphabetically, so you will end up with
b0
g0
r0
.
.
.
Unless you simply rename the channels to r=a, g=b, b=c (or x,y,z or whatever) before reordering. So you simply make sure your desired order works for alphabetic ordering. You can then rename the channels back to r,g,b if needed.

Hey,

for your example use 2 Shuffle CHOPs:

• first Shuffle CHOP select Method: “Sequence Channels by Name”
This will give you 3 channels called r, g and b

• Next append a Shuffle CHOP and choose Method: “Sequence all Samples”
This will give you 1 channel with the samples from r, g and b appended to each other in the order you like…

Cheers
Markus

Hi all,
I reply now because in TD099 the code celina posted seems to work in a different way: it outputs ‘r0 g0 b0’ ‘r1 b1 b2’ etc…any idea on how to make it work?