Page 1 of 1

(LUA) swap patch function

Posted: Wed Dec 16, 2009 1:47 pm
by tom
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

Re: LUA - Simple swap patch function

Posted: Wed Dec 16, 2009 6:59 pm
by RobertBell
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.

Re: LUA - Simple swap patch function

Posted: Thu Dec 17, 2009 3:45 am
by gooze
Completely agree! Great function! Thank you!

Re: LUA - Simple swap patch function

Posted: Fri Dec 18, 2009 12:06 am
by JohnGrimshaw
...should be called a "Tom Swap"

Re: LUA - Simple swap patch function

Posted: Fri Dec 18, 2009 9:01 am
by tom
:)

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