-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMath-It.lua
More file actions
82 lines (65 loc) · 2.95 KB
/
Math-It.lua
File metadata and controls
82 lines (65 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--Math-it v0.1
-- Choose a group and world number here that will be way clear of anything you use in your programming, it will be overwritten and deleted after this runs
local tempGroup = 2999
local tempWorld = 999
------
local text = gma.textinput
local feed = gma.feedback
local cmd = gma.cmd
local o = gma.show.getobj.handle
local a = gma.show.getobj
local property = gma.show.property.get
local sub = string.sub
local print = feed
local getHandle = gma.show.getobj.handle
local getClass = gma.show.getobj.class
local unpack = table.unpack
-------
function GetGroup(grpNum)
gma.cmd('SelectDrive 1') -- select the internal drive
local file = {}
file.name = 'tempfile.xml'
file.directory = gma.show.getvar('PATH') .. '/' .. 'importexport' .. '/'
file.fullpath = file.directory .. file.name
gma.cmd('Export Group ' .. grpNum .. ' \"' .. file.name .. '\" /o') -- create temporary file
local t = {} -- convert XML file into a table
for line in io.lines(file.fullpath) do
t[#t + 1] = line
end
os.remove(file.fullpath) -- delete temporary file
local groupList = {} -- declare groupList
for i = 1, #t do
if t[i]:find('Subfixture ') then
local indices = {t[i]:find('\"%d+\"')} -- find points of quotation marks
indices[1], indices[2] = indices[1] + 1, indices[2] - 1 -- move reference points to first an last characters inside those marks
-- label based on status as a fixture or as a channel
local fixture
if t[i]:find('fix_id') then
fixture = 'Fixture ' .. tostring(t[i]:sub(indices[1], indices[2])) -- extract the number as the fixture number
elseif t[i]:find('cha_id') then
fixture = 'Channel ' .. tostring(t[i]:sub(indices[1], indices[2]))
end -- extract the number as the fixture number
-- if the object contains a subfixture...
if t[i]:find('sub_index') then
local indices = {t[i]:find('\"%d+\"', indices[2] + 2)}
indices[1], indices[2] = indices[1] + 1, indices[2] - 1
fixture = fixture .. '.' .. tostring(t[i]:sub(unpack(indices)))
end
-- append to list
groupList[#groupList + 1] = fixture -- extract the number to the group list
end
end
return groupList
end
return function()
local divisor = text("Divide Rig By x", 2)
cmd("Delete World " .. tempWorld .. "; Store World " .. tempWorld .. ";BlindEdit On; Fixture Thru")
cmd("Store Group " .. tempGroup .. " /o /nc")
local groupFixtures = GetGroup(tempGroup)
cmd("World 1; Delete World " .. tempWorld .. "; Delete Group " .. tempGroup .. "; BlindEdit Off" )
local fixCount = #groupFixtures
local halfFix = math.floor(fixCount/tonumber(divisor))
feed("Math Result: " .. halfFix)
cmd("MaTricksBlocks " .. halfFix)
cmd('Next')
end