Page 1 of 1

%%v:varibaleName%% %%v:variableId%%

PostPosted: Fri Aug 26, 2016 6:49 pm
by kw123
the attached can be used to convert %%v .... %% using variable name or variable ID and you can add text before and after.

Code: Select all
    def convertVariableText(self,textIn):
        #  converts eg:
        #"abc%%v:VariName%%xyz"   to abcCONTENTSOFVARIABLExyz
        #"abc%%V:VariNumber%%xyz to abcCONTENTSOFVARIABLExyz
        try:
            start= textIn.find("%%v:")
        except:
            return textIn
       
        if start==-1:
            return textIn
        textOut= textIn[start+4:]
        end = textOut.find("%%")
        if end ==-1:
            return textIn
        var = textOut[:end]
        try:
            vText= indigo.variables[int(var)].value
        except:
            try:
                vText= indigo.variables[var].value
            except:
                return textIn

        try:
            if end+2 >= len(textOut)-1:
                textOut= textIn[:start]+vText
                return textOut
            textOut= textIn[:start]+vText+textOut[end+2:]
            return textOut
        except:
            return textIn
        return textIn

Re: %%v:varibaleName%% %%v:variableId%%

PostPosted: Sat Aug 27, 2016 8:42 am
by jay (support)
Or you can call the plugin base classes substitute() (does both), substituteVariable(), or substituteDeviceState() methods... ;)

Re: %%v:varibaleName%% %%v:variableId%%

PostPosted: Sat Aug 27, 2016 11:28 am
by kw123
My main question: Why don't I know about these?


Sent from my iPhone using Tapatalk

Re: %%v:varibaleName%% %%v:variableId%%

PostPosted: Sat Aug 27, 2016 4:01 pm
by jay (support)
kw123 wrote:
My main question: Why don't I know about these?


:D Don't know - it's in the plugin base class docs...