Re: regular expressions and variables in JScript

Date : Fri, 26 May 2006 10:03:45 -0700
To : XSI(at)Softimage.COM
From : "Steven Caron" <carons(at)gmail.com>
Subject : Re: regular expressions and variables in JScript
indeed.. sorry wrote that without referencing how the scntoc is setup. but yes the XMLDom is handy

On 5/26/06, Sascha Robitzki < s.robitzki(at)trixter.de> wrote:
I had some trouble to find out the reference model name is an attribute
and not and not something else like a node name or value. But at the end
the DOM model works very good:

var scnToc = new ActiveXObject("Msxml2.DOMDocument.3.0");
scnToc.load("x:\\xxx.scntoc"); // path to scntoc
var modelElem = scnToc.getElementsByTagName("Model");

for(var j = 0; j < modelElem.length; j++)
{
    if(modelElem.item(j).attributes(0).value == "xxx") // name of refmodel
    {
        logmessage(modelElem.item(j).attributes(0).value);
        logmessage(modelElem.item(j).childNodes(0).text);

        modelElem.item(j).childNodes(0).text = 2; // refmode

        logmessage(modelElem.item (j).childNodes(0).text);
    }
}

scnToc.save(path);

Cheers,
Sascha

Steven Caron wrote:
> sounds like a job for xmldom...
>
> var low = 1;
> var med = 2;
> var high = 3;
> var path = "" //path to scntoc
> var modelName = "" //name of refmodel
>
> var scnToc = new ActiveXObject("Microsoft.XMLDOM");
>     scnToc.load(path);
> var modelElem = scnToc.getElementsByTagName("modelName");
>     modelElem.childnodes(0).text = low;  //put the resolution you
> want to change it to here
>
>     scnToc.save(path);
>
> maybe that will give you some ideas.
>
> On 5/4/06, Sascha Robitzki <s.robitzki(at)trixter.de> wrote:
>> Thanks, \r\n does work, so I need both a return and a new line.
>> I just wanted to switch the resolutions in a .toc file. This is my
>> current pattern which does the job:
>>
>>             var regEx = new RegExp(
>>             "      <Model name=\"ModelSource_" + model + "\">\r\n"
>>             +
>>             "         <active_resolution>" + "[0-3]" +
>> "</active_resolution>"
>>             ,
>>             "gm");
>>
>> Maybe it's smarter to parse the .toc file over the DOM object but I had
>> not enough time to get into it.
>>
>> Thanks,
>> Sascha
>>
>> Andy Nicholas wrote:
>> > Hi Sascha,
>> >
>> > This _expression_ will match a section of multiple newlines/carriage
>> returns
>> > followed by a section of white space:
>> >
>> > [\r\n]+\s+
>> >
>> > If you could be a little more specific about what you're trying to
>> do, I
>> > might be able to help further.
>> >
>> > Cheers
>> >
>> > Andy
>> >
>> >
>> >
>> > I think you'd need something like this for the string you said
>> >
>> >> Thanks Guillaume.
>> >> What would be a pattern for a carriage return followed by an
>> undefined
>> >> number of space characters? Just [\r\s+] seems not do what I'm
>> looking
>> >> for because it does not work. For example I have this string from
>> a file
>> >> with some return characters but without tabs:
>> >>
>> >>       aaa
>> >>       bbb
>> >>          ccc
>> >>          ddd
>> >>
>> >> Now how can I compose a pattern which does match with:
>> >>       bbb
>> >>          ccc
>> >>
>> >> Thanks,
>> >> Sascha
>> >>
>> >> guillaume laforge wrote:
>> >>
>> >>> I'm not very friendly with regex but I use something like this in a
>> >>> script to change image file path :
>> >>>
>> >>> >>> >>>
>> >>> var reg=new RegExp("[\\\\]+", "g");
>> >>> var Slct = new String(oName);
>> >>> tmp = Slct.split(reg);
>> >>> TheName = tmp[tmp.length-1];
>> >>> NewName = "F:\\_MAPS_FF\\"+TheName;
>> >>>
>> >>> LogMessage(NewName);
>> >>>
>> >>> Does it help ?
>> >>>
>> >>> Cheers.
>> >>>
>> >>> --
>> >>> Guillaume Laforge
>> >>> freelance TD | cg Artist
>> >>>
>> >>>
>> >>> On 5/4/06, *Sascha Robitzki* <s.robitzki(at)trixter.de
>> >>> <mailto:s.robitzki(at)trixter.de>> wrote:
>> >>>
>> >>>     How can I put a variable into a regular _expression_ in JScript?
>> >>>
>> >>>     Thanks,
>> >>>     Sascha
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>
>> >
>> > ---
>> > Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text
>> in body:
>> > unsubscribe xsi
>> >
>>
>>
>>
>>
>
> ---
> Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in
> body:
> unsubscribe xsi


--
Sascha Robitzki
TD (at) www.trixter.de

---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.