Welcome! Log In Create A New Profile

Advanced
correct-rotation-script not working properly
May 18, 2021 08:28PM
hi there!

i am trying to write a script that corrects the x/y/z-rotation in the patch based on the fixture name (i added ID**** to my fixture names)
background: Some fixtures are looking in the wrong direction in my visualizer software.


It works in general but in some cases it shows strange behaviour: X/Z-rotation works perfect but as soon as I put 90, 180 or 270 into modRotY (and only Y) it touches all fixtures and writes weird values in their rotaition data.


function correctRotation()

local FirstFixture = 001                 -- first fixture to modify
local LastFixture  = 199                 -- last fixture to mofify

local cmd    =  gma.cmd 
local sleep   =  gma.sleep
local fixId
local rotX
local rotY
local rotZ
local newRotX
local newRotY
local newRotZ
local nodRotX
local modRotY
local modRotZ
local found


for fixId = FirstFixture, LastFixture do
gma.feedback("reading fixture " .. fixId)
if(gma.show.getobj.handle("Fixture " .. fixId .. ".1"))then
sleep(0.1)
local handle  =  gma.show.getobj.handle("Fixture " .. fixId .. ".1")
sleep(0.1)
local fixName = gma.show.property.get(handle,3)
gma.feedback('FixtureType is ' .. fixName)
found = 1
if string.match(fixName, "ID0001") then
   modRotX = 0
   modRotY = 0
   modRotZ = 0
     
  --copy these lines and change for your needs--
elseif string.match(fixName, "ID0002") then
   modRotX = 0
   modRotY = 45
   modRotZ = 0  
  
  --copy these lines and change for your needs--
elseif string.match(fixName, "ID0003") then
   modRotX = 0
   modRotY = 0
   modRotZ = 180  
  
  --copy these lines and change for your needs--
elseif string.match(fixName, "ID0004") then
   modRotX = 90
   modRotY = -45
   modRotZ = 0


else
  found = 0
  gma.feedback("NO MATCH")
end
if found == 1 then
  
  sleep(0.1)
  gma.feedback("MATCH")  
  sleep(0.1)
  rotX = gma.show.property.get(handle,'RotX')
  sleep(0.1)
  rotY = gma.show.property.get(handle,'RotY')
  sleep(0.1)
  rotZ = gma.show.property.get(handle,'RotZ')  
  sleep(0.1)
  gma.feedback("old X: " .. rotX .. " Y: " .. rotY .. " Z: " .. rotZ)
  newRotX = rotX + modRotX
  newRotY = rotY + modRotY
  newRotZ = rotZ + modRotZ
  gma.feedback("mod X: " .. modRotX .. " Y: " .. modRotY .. " Z: " .. modRotZ)
  gma.feedback("new X: " .. newRotX .. " Y: " .. newRotY .. " Z: " .. newRotZ)
  
  if newRotX > 180 then
    newRotX = newRotX - 360
  elseif newRotX < -180 then
    newRotX = newRotX + 360
  end  
  if newRotY > 180 then
    newRotY = newRotY - 360
  elseif newRotY < -180 then
    newRotY = newRotY + 360
  end  
  if newRotZ > 180 then
    newRotZ = newRotZ - 360
  elseif newRotZ < -180 then
    newRotZ = newRotZ + 360
  end    
  
  gma.feedback("cor X: " .. newRotX .. " Y: " .. newRotY .. " Z: " .. newRotZ)
  cmd('Clear All')
  sleep(0.1)
  cmd('Fixture ' .. fixId)
  sleep(0.1)
  cmd('Rotate3D At ' .. newRotX .. ' ' .. newRotY .. ' ' .. newRotZ)
  sleep(0.1)
  cmd('Clear All')
  sleep(0.1)

end

else
gma.feedback("no fixture")
end

end

end
return correctRotation;


I have to admit I am not a lua programmer, I know some Python and C stuff and basically googled most of the script together.

Also I noticed that sometimes the gma.show.property.get(handle,'RotX') returns inaccurate values, like 90.02 instead of 90. its not that important but would be good to know why it is like that. This happens on different fixtures, not really reproducible but every 10th fixture or so is affected
edit:and this happens more often if modRotY is 90,180 or 270 (not really sure about that)


I really appreciate every hint that points me in the right direction.

Thanks a lot and stay healty boyz n girlz!
Martin



Edited 1 time(s). Last edit at 05/18/2021 08:31PM by m0dbot.
Subject Author Views Posted
correct-rotation-script not working properly m0dbot 555 May 18, 2021 08:28PM
Re: correct-rotation-script not working properly m0dbot 266 May 20, 2021 03:01PM



Sorry, only registered users may post in this forum.

Click here to login