Notifications
Clear all
[Closed] isMacro script installed?
Sep 27, 2007 7:19 pm
I’m adding macros to a menu, how ever I don’t see a way to know if the macro exists in the first place. There is a macros.list(), and this just spams the listener. But is there a way to ask if a macor exists… isMacro … … That sort of thing? I could use a try catch but I just don’t like doing that.
5 Replies
1 Reply
Quick and dirty solution:
fn macroExists theMacroName =
(
local result = false --init. return result to false
local ss = stringstream "" --define a stringstream
macros.list to:ss --dump the list to the stream
seek ss 0 --move to the beginning of the stream
while not eof ss do --loop through the stream
(
theLine = readline ss --read a line from it
if matchpattern theLine pattern:("*"+theMacroName+"*") do --if the string is found
(
result = true --set the flag to true
exit --and exit the loop
)
)--end while
result --return the result
)
macroExists "Reactor_R"
true
macroExists "Reactor_A"
false
Sep 27, 2007 7:19 pm
Slightly improved version:
fn macroExists theMacroName category: =
(
local result = false --init. return result to false
local ss = stringstream "" --define a stringstream
macros.list to:ss --dump the list to the stream
seek ss 0 --move to the beginning of the stream
while not eof ss do --loop through the stream
(
theLine = readline ss --read a line from it
if matchpattern theLine pattern:("*"+theMacroName+"*") do --if the string is found
(
if category == unsupplied then --if no category supplied, return true
(
result = true --set the flag to true
exit --and exit the loop
)
else --if category was supplied, check the 3rd element of the definition
(
if (filterString theLine " ")[3] == "\"" + category + "\"" do --and compare
(
result = true --return true if the category matches
exit
)
)
)
)--end while
result --return the result
)
macroExists "Reactor_R"
true
macroExists "Reactor_R" category:"Controllers"
true
macroExists "Reactor_R" category:"Bobo"
false
Sep 27, 2007 7:19 pm
Thanks bobo, I forgot that you can use to: and dump thinks like that to a string stream instead of just the listener. There is no mention of that in the help. I’ll go this root then.
Sep 27, 2007 7:19 pm
I also wrote a function for this similar to Bobo’s which is at orionflame.com > Light > Production Tools > C4
Light