PDA

View Full Version : isMacro script installed?


PEN
09-27-2007, 06: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.

Bobo
09-27-2007, 07:00 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.


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

Bobo
09-27-2007, 07:05 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

PEN
09-27-2007, 10:16 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.

Light
09-28-2007, 12:11 AM
I also wrote a function for this similar to Bobo's which is at orionflame.com (http://www.orionflame.com) > Light > Production Tools > C4




Light

PEN
09-28-2007, 11:02 AM
Thanks Light, I already have one of my own going and doing what I need.

CGTalk Moderation
09-28-2007, 11:02 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.