forked from cedricviaccoz/AeonASpaceContainersAddon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Helpers.lua
81 lines (71 loc) · 1.83 KB
/
Helpers.lua
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
-- Utility Functions
function makeRibbonVisible(ribbon, visibilitySetting)
--ribbon is of type AtlasSystems.Scripting.UI.ScriptRibbonPage
--visibilitySetting is a boolean value
--this should probably be switched to a "show only" that searches the parent
--and deactivates all but the specified ribbon within a particular group
ribbon.Page.Visible = visibilitySetting;
end
function findObjectTypeInCollection(obj, typestr)
local ctrlCount = getLength(obj);
local idx = 0;
local target = nil;
while idx < ctrlCount do
target = obj:get_Item(idx);
if string.startsWith(tostring(target), typestr) then
return target;
end
idx = idx + 1;
end
if idx == ctrlCount then
return nil;
end
end
-- cannot use '#' if the table is not numerically indexed in sequence.
function tableLength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function getLength(obj)
local idx = 0;
while true do
if pcall(function () local test = obj:get_Item(idx) end) then
idx = idx + 1;
else
break;
end
end
return idx;
end
function string.startsWith(original, test)
return string.sub(original, 1, string.len(test))==test;
end
function incomingStringCleaner(text)
text = string.gsub(text,"(Accession)","Accn");
return text
end
function isnumeric(val)
if (val == nil) then
return false;
end
-- make sure the string val is all numeric
return string.match(val, "^[0-9]+$") ~= nil;
end
function isOnlyWhitespace(str)
if str ~= nil then
return str:gsub("%s+", "") == ''
end
return true
end
-- source: https://stackoverflow.com/questions/1426954/split-string-in-lua
function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end