(LUA) swap patch function

Open Source software contributions and discussions that supplement or extend the Palette / Light Palette software
Post Reply
tom
Posts: 224
Joined: Thu Jun 26, 2008 5:30 am
Location: The Netherlands

(LUA) swap patch function

Post by tom » Wed Dec 16, 2009 1:47 pm

This is a simple piece of code that will swap out dimmer numbers bewteen two channels. A quick way of correcting small convention patch mistakes.

Select two channels and run the script. I have mine on a bump button.

Right now it only works on channels with one dimmer attached. It might do something with channels that have more than one dimmer but it wont be what you expect. So be careful with this. Two channels and 2 dimmers, thats all.

***code supporting multiple dimmers posted below

Code: Select all

function trim(s)
local a1 = (string.gsub(s, "Dimr:", ""))
local a2 = (string.gsub(a1, ",Addr2:", ""))
local a3 = (string.gsub(a2, ",Addr3:", ""))
local a4 = (string.gsub(a3, ",Addr4:", ""))
return(a4) 
end

function patch(cnh1,addr1,cnh2,addr2)
HC.PatchFixture(cnh1,addr2)
HC.PatchFixture(cnh2,addr1)
end

local s = HC.GetCurrentSelectionSet(',')
local a = 0
local c = {}
for fixture in string.gmatch(s,"%d+") do
  c[a] = fixture
  a = a + 1  
end

if a==2 then 
local d0=HC.GetProperty('fixture','#'..c[0],'patch')
local d1=HC.GetProperty('fixture','#'..c[1],'patch')
--print(c[0].." - "..trim(d0).."  "..c[1].." - "..trim(d1))
patch(c[0],trim(d0),c[1],trim(d1))
c[0] =nil
c[1] =nil
d0 =nil
d1 =nil
else
HC.MessageBox('Select 2 fixtures only','Patch swap script')
end
Last edited by tom on Fri Dec 18, 2009 9:07 am, edited 2 times in total.
Light palette : classic
Nederlands Dans Theater.

"Come forth and thy shalt win eternal happiness", but he came fifth, so he won an electric toaster.

User avatar
RobertBell
Posts: 2421
Joined: Fri Oct 12, 2007 1:11 pm
Primary Venue / Use: Other
Where I Am: Horizon Control Inc
Location: On the dark side just north of Toronto
Contact:

Re: LUA - Simple swap patch function

Post by RobertBell » Wed Dec 16, 2009 6:59 pm

I LOVE IT I LOVE IT
I've been thinking of adding this to the main code. I asked Flying Pig for this about 15 years ago. Nobody ever thought it was a good idea. SOOOOOooooo often, the guys in the rig mis patch two things.
Very clever Tom.
Everyone should have this one.
Robert Bell - Product Manager - Horizon Control Inc.

User avatar
gooze
Posts: 1760
Joined: Tue Dec 18, 2007 12:42 pm
Location: Amsterdam, The Netherlands
Contact:

Re: LUA - Simple swap patch function

Post by gooze » Thu Dec 17, 2009 3:45 am

Completely agree! Great function! Thank you!
Floriaan Ganzevoort - Lighting designer
THEATERMACHINE design. production. operations.

User avatar
JohnGrimshaw
Posts: 1233
Joined: Tue Oct 16, 2007 12:51 pm
Primary Venue / Use: Other
Where I Am: International Man of Mystery
Location: Sydney, Australia
Contact:

Re: LUA - Simple swap patch function

Post by JohnGrimshaw » Fri Dec 18, 2009 12:06 am

...should be called a "Tom Swap"
...and for more entertainment industry trivia and useless facts, just ask:
John Grimshaw
Managing Director
Stage Fast Pty Ltd

tom
Posts: 224
Joined: Thu Jun 26, 2008 5:30 am
Location: The Netherlands

Re: LUA - Simple swap patch function

Post by tom » Fri Dec 18, 2009 9:01 am

:)

Heres a round two, supports more than one dimmer on a channel.

Code: Select all

--[[Swap patch function
Takes assigned dimmers from one channel and swaps them with another
provided two channels are selected and the script is run,
Current version supports multiple dimmers per channel. 
Does not support moving lights.
--]]

function trim(s) 
local a1 = (string.gsub(s, "Dimr:", ""))
local a2 = (string.gsub(a1, ",Addr2:", ""))
local a3 = (string.gsub(a2, ",Addr3:", ""))
local a4 = (string.gsub(a3, ",Addr4:", ""))
return(a4) 
end

local s = HC.GetCurrentSelectionSet(',')
local a = 0
local c = {}
for fixture in string.gmatch(s,"%d+") do
  c[a] = fixture
  a = a + 1  
end
 
if a==2 then 
local d0=HC.GetProperty('fixture','#'..c[0],'patch')
local d1=HC.GetProperty('fixture','#'..c[1],'patch')
--print(c[0].." - "..trim(d0).."  "..c[1].." - "..trim(d1))
--swappatch(c[0],trim(d0),c[1],trim(d1))

local dims0 = {}
local n = 0
for dimmer in string.gmatch(trim(d0),"%d+") do
dims0[n] = dimmer
n=n+1
end 

local dims1 = {}
local m = 0
for dimmer in string.gmatch(trim(d1),"%d+") do
dims1[m] = dimmer
m=m+1
end 

while m>0 do
HC.PatchFixture(c[0],dims1[m-1])
m = m - 1
end
while n>0 do
HC.PatchFixture(c[1],dims0[n-1])
n = n - 1
end

else
HC.MessageBox('Select 2 fixtures only','Patch swap script')
end
Light palette : classic
Nederlands Dans Theater.

"Come forth and thy shalt win eternal happiness", but he came fifth, so he won an electric toaster.

Post Reply