Jrepl

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
mogodan2008
Posts: 17
Joined: 25 Jun 2017 02:37

Jrepl

#1 Post by mogodan2008 » 25 Jun 2017 04:25

Hi Dave,

A big thanks for your good scripts!
I've been processing data and it occurred to me that jrepl would be useful to process a text file like this:

Code: Select all

<?xml version='1.0' encoding='UTF-8'?>

<pfml version="1.0">
<face>
<attribute name="translation-v-mm">-11.92</attribute>
<geometry>
<Rectangle x="256" y="216" width="132" height="158"/>
</geometry>
<eye>
<eye-bounds>
<attribute name="3d-position-z">724.04</attribute>
<attribute name="3d-position-y">-12.20</attribute>
<attribute name="3d-position-x">-35.30</attribute>
<attribute name="open-closed-state">open</attribute>
<geometry>
<Rectangle x="273" y="246" width="34" height="11"/>
</geometry>
</eye-bounds>
<lower-eyelid>
<geometry>
<Point x="289.98" y="252.91"/>
</geometry>
</lower-eyelid>
<upper-eyelid>
<geometry>
<Point x="289.98" y="242.48"/>
</geometry>
</upper-eyelid>
</eye>
<eye markedPos="1">
<eye-bounds>
<attribute name="3d-position-z">723.94</attribute>
<attribute name="3d-position-y">-11.26</attribute>
<attribute name="3d-position-x">30.69</attribute>
<attribute name="open-closed-state">open</attribute>
<geometry>
<Rectangle x="336" y="244" width="34" height="14"/>
</geometry>
</eye-bounds>
<lower-eyelid>
<geometry>
<Point x="352.91" y="253.31"/>
</geometry>
</lower-eyelid>
<upper-eyelid>
<geometry>
<Point x="352.51" y="242.28"/>
</geometry>
</upper-eyelid>
</eye>
<mouth>
<geometry>
<Rectangle x="294" y="313" width="53" height="14"/>
</geometry>
</mouth>
</face>
<person>
<attribute name="personName">Person1</attribute>
<geometry>
<Rectangle x="289.8" y="252.96" width="5.55" height="4.29"/>
</geometry>
</person>
<person>
<attribute name="personName">Person2</attribute>
<geometry>
<Rectangle x="289.98" y="242.58" width="5.55" height="4.29"/>
</geometry>
</person>
<person>
<attribute name="personName">Person3</attribute>
<geometry>
<Rectangle x="352.95" y="253.32" width="5.55" height="4.29"/>
</geometry>
</person>
<person>
<attribute name="personName">Person4</attribute>
<geometry>
<Rectangle x="352.59" y="242.23" width="5.55" height="4.29"/>
</geometry>
</person>
</pfml>
<orig-lastmodified>1497878193347</orig-lastmodified>
</image>


I need to compare the value "Rectangle x=" of first eye-bounds with the value "Rectangle x=" of second eye-bounds.
If first x < second x, then:
- replace the x value and y value of first lower-eyelid (<Point x="289.98" y="252.91"/>) with value of x and y of Person1;
- replace the x value and y value of first upper-eyelid (<Point x="289.98" y="242.48"/>) with value of x and y of Person2;
- replace the x value and y value of second lower-eyelid (<Point x="352.91" y="253.31"/>) with value of x and y of Person3;
- replace the x value and y value of second upper-eyelid (<Point x="352.51" y="242.28"/>) with value of x and y of Person4;

If first x > second x, then:
- replace the x value and y value of first lower-eyelid (<Point x="289.98" y="252.91"/>) with value of x and y of Person3;
- replace the x value and y value of first upper-eyelid (<Point x="289.98" y="242.48"/>) with value of x and y of Person4;
- replace the x value and y value of second lower-eyelid (<Point x="352.91" y="253.31"/>) with value of x and y of Person1;
- replace the x value and y value of second upper-eyelid (<Point x="352.51" y="242.28"/>) with value of x and y of Person2;

I need to replace just values, keeping the formatted text. Could you help me, please? Thank You!

Best regards,
Dan
Last edited by Aacini on 25 Jun 2017 19:37, edited 1 time in total.
Reason: Use code tags

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Jrepl

#2 Post by aGerman » 25 Jun 2017 16:49

Now that I had some free time I wrote a little hybrid script that should meet your requirements.

Code: Select all

@if (@a)==(@b) @end /*

:: Batch
@echo off &setlocal

set /a "start=21653196, stop=21653201"

for /l %%i in (%start% 1 %stop%) do (
  if exist "%%i.xml" (
    cscript //nologo //e:jscript "%~fs0" "%%i.xml"
  ) else (
    echo "%%i.xml" not found
  )
)

pause

:: JScript
exit /b&::*/ try {
  var xmlFileName = WScript.Arguments(0);
      oXmlDoc = new ActiveXObject('Microsoft.XMLDOM');

  oXmlDoc.load(xmlFileName);

  var colEyeNodes = oXmlDoc.documentElement.getElementsByTagName('eye'),
      colPersonNodes = oXmlDoc.documentElement.getElementsByTagName('person');

  if (colEyeNodes.length === 2 && colPersonNodes.length === 4) {
    var arrEyeBoundX = new Array(parseFloat(colEyeNodes.item(0).selectSingleNode('eye-bounds/geometry/Rectangle').getAttribute('x')),
                                 parseFloat(colEyeNodes.item(1).selectSingleNode('eye-bounds/geometry/Rectangle').getAttribute('x'))),
        person1x = colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person1y = colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person2x = colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person2y = colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person3x = colPersonNodes.item(2).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person3y = colPersonNodes.item(2).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person4x = colPersonNodes.item(3).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person4y = colPersonNodes.item(3).selectSingleNode('geometry/Rectangle').getAttribute('y');

    if (arrEyeBoundX[0] < arrEyeBoundX[1]) {
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person1x);
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person1y);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person2x);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person2y);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person3x);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person3y);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person4x);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person4y);
    } else {
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person3x);
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person3y);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person4x);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person4y);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person1x);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person1y);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person2x);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person2y);
    }

    oXmlDoc.save(xmlFileName);
    WScript.Quit(0);
  } else if (colEyeNodes.length === 2 && colPersonNodes.length === 2) {
    var lowerLid1 = colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point'),
        upperLid1 = colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point'),
        lowerLid2 = colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point'),
        upperLid2 = colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point');

    if (lowerLid1 !== null && upperLid1 !== null) {
      lowerLid1.setAttribute('x', colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('x'));
      lowerLid1.setAttribute('y', colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('y'));
      upperLid1.setAttribute('x', colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('x'));
      upperLid1.setAttribute('y', colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('y'));
    }

    if (lowerLid2 !== null && upperLid2 !== null) {
      lowerLid2.setAttribute('x', colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('x'));
      lowerLid2.setAttribute('y', colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('y'));
      upperLid2.setAttribute('x', colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('x'));
      upperLid2.setAttribute('y', colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('y'));
    }

    oXmlDoc.save(xmlFileName);
    WScript.Quit(0);
  } else {
    WScript.StdErr.WriteLine('Wrong number of either "eye" or "person" nodes.');
    WScript.Quit(1);
  }
}
catch(e) {
  WScript.StdErr.WriteLine(e.message);
  WScript.Quit(1);
}

Save it with extension .bat and customize variables start and stop in the Batch section.

FYI: I had to add <image> instead of your empty second line in order to get a well-formed XML text.
You may also wait for a reply from Dave but I strongly recomment you to use the DOM methods (as I did in the above code) instead of Regex to change XML documents.

Steffen
Last edited by aGerman on 02 Jul 2017 06:23, edited 3 times in total.

mogodan2008
Posts: 17
Joined: 25 Jun 2017 02:37

Re: Jrepl

#3 Post by mogodan2008 » 26 Jun 2017 03:24

Hi Steffen,

Thank you for your reply!
I had customize the xmlName in batch file and I try your code, but without success. The cmd window is clossing after I press any key, and nothing change in xml file.

Best regards,
Dan

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Jrepl

#4 Post by aGerman » 26 Jun 2017 04:29

Please post exactly the content of the XML file you tried.

Steffen

mogodan2008
Posts: 17
Joined: 25 Jun 2017 02:37

Re: Jrepl

#5 Post by mogodan2008 » 26 Jun 2017 14:44

Hi Steffen,

The content of xml file is:

<?xml version='1.0' encoding='UTF-8'?>

<image id="21653200" version="1.0" image-url="J:\23.06.2017 855 1-5\TagImage-DMS_NIR-Cam-Gen1_Phase2_John_Optitrack-Blink_20160218-150629_30.bw_640x48030fps\21653200.png" width="640" height="480" importedBy="fortune" modifiedBy="fortune" mime-type="image/png">
<creator>Ted</creator>
<rights>Copyright 2016</rights>
<filename>00000220.png</filename>
<created>1456161061808</created>
<lastmodified>1498467052421</lastmodified>
<tag name="DMS_NIR-Cam-Gen1_Phase2_Dan-East_Optitrack-Blink_20160218-150629_30.bw_640x480@30fps"/>
<pfml version="1.0">
<face>
<attribute name="translation-v-mm">-38.65</attribute>
<attribute name="face-roll-deg">-3.44</attribute>
<attribute name="3d-orientation-pitch">-12.46</attribute>
<attribute name="3d-orientation-qz">-0.0090924455</attribute>
<attribute name="3d-orientation-qy">-0.3367829621</attribute>
<attribute name="3d-orientation-qx">0.1121013835</attribute>
<attribute name="translation-h-mm">-87.71</attribute>
<attribute name="3d-orientation-qw">-0.9348411560</attribute>
<attribute name="face-pitch-deg">-16.87</attribute>
<attribute name="3d-orientation-roll">-3.44</attribute>
<attribute name="translation-z-mm">725.36</attribute>
<attribute name="face-yaw-deg">46.34</attribute>
<attribute name="3d-orientation-yaw">40.00</attribute>
<geometry>
<Rectangle x="297" y="234" width="135" height="155"/>
</geometry>
<eye>
<eye-bounds>
<attribute name="3d-position-z">755.18</attribute>
<attribute name="3d-position-y">-34.13</attribute>
<attribute name="3d-position-x">-105.69</attribute>
<attribute name="open-closed-state">closed</attribute>
<geometry>
<Rectangle x="361" y="272" width="25" height="11"/>
</geometry>
</eye-bounds>
<lower-eyelid>
<geometry>
<Point x="367" y="278"/>
</geometry>
</lower-eyelid>
<upper-eyelid>
<geometry>
<Point x="367.3" y="275.3"/>
</geometry>
</upper-eyelid>
</eye>
<eye markedPos="1">
<eye-bounds>
<attribute name="3d-position-z">713.49</attribute>
<attribute name="3d-position-y">-37.99</attribute>
<attribute name="3d-position-x">-54.67</attribute>
<attribute name="open-closed-state">closed</attribute>
<geometry>
<Rectangle x="406" y="265" width="22" height="12"/>
</geometry>
</eye-bounds>
<lower-eyelid>
<geometry>
<Point x="413" y="272"/>
</geometry>
</lower-eyelid>
<upper-eyelid>
<geometry>
<Point x="413" y="269"/>
</geometry>
</upper-eyelid>
</eye>
<mouth>
<geometry>
<Rectangle x="378" y="334" width="36" height="13"/>
</geometry>
</mouth>
</face>
<person>
<attribute name="personName">Person1</attribute>
<geometry>
<Rectangle x="368.27" y="277.82" width="2.72" height="2.59"/>
</geometry>
</person>
<person>
<attribute name="personName">Person2</attribute>
<geometry>
<Rectangle x="368.27" y="275.75" width="2.72" height="2.59"/>
</geometry>
</person>
<person>
<attribute name="personName">Person3</attribute>
<geometry>
<Rectangle x="414.72" y="272.25" width="2.72" height="2.59"/>
</geometry>
</person>
<person>
<attribute name="personName">Person4</attribute>
<geometry>
<Rectangle x="414.85" y="269.79" width="2.72" height="2.59"/>
</geometry>
</person>
</pfml>
<orig-lastmodified>1497878168897</orig-lastmodified>
</image>

and the name of xml file is: 21653200.xml
I put the file and the batch file with your code in the same folder and run. And also I try with the full path of the xml file in xmlName, but without success.
And also, I need to increment the xml file name and apply the code. Thank you!

Best regards,
Dan

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Jrepl

#6 Post by aGerman » 26 Jun 2017 15:19

My fault :oops: I think I must have done something wrong yesterday.
I corrected my code above. Please try again.

Steffen

mogodan2008
Posts: 17
Joined: 25 Jun 2017 02:37

Re: Jrepl

#7 Post by mogodan2008 » 29 Jun 2017 03:34

Hi Steffen,

I had tried with the xml, but it seems that the first condition is not applied. In fact, the first lower- lied x, y points whil get the x,y points of Person3 instead of Person1 points, and the first upper-lied x,y points the points of Person4 instead of Person2; I change the conditional character "less" with "more" ( sorry, I am on mobile phone writting), but with same effect. I had tried with another xml file, with x of second eye-bounds less than x of first eye-bounds and is working fine. Can you help me, please?
Thank you!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Jrepl

#8 Post by aGerman » 29 Jun 2017 04:53

I think I know what was going wrong. I corrected the code again.

Steffen

mogodan2008
Posts: 17
Joined: 25 Jun 2017 02:37

Re: Jrepl

#9 Post by mogodan2008 » 29 Jun 2017 23:47

Hi Steffen,

Your code is working super! Thank you a lot!

I need to apply the code to several xml files. So, I added some batch lines to your code, like:

" @if (@a)==(@b) @end /*

:: Batch
@echo off &setlocal

set myimage=21653
set x=196

:loop

set "xmlName=%myimage%%x%.xml"
cscript //nologo //e:jscript "%~fs0" "%xmlName%"
pause

:: JScript
exit /b&::*/ try {
  var xmlFileName = WScript.Arguments(0);
      oXmlDoc = new ActiveXObject('Microsoft.XMLDOM');

  oXmlDoc.load(xmlFileName);

  var colEyeNodes = oXmlDoc.documentElement.getElementsByTagName('eye'),
      colPersonNodes = oXmlDoc.documentElement.getElementsByTagName('person');

  if (colEyeNodes.length === 2 && colPersonNodes.length === 4) {
    var arrEyeBoundX = new Array(parseFloat(colEyeNodes.item(0).selectSingleNode('eye-bounds/geometry/Rectangle').getAttribute('x')),
                                 parseFloat(colEyeNodes.item(1).selectSingleNode('eye-bounds/geometry/Rectangle').getAttribute('x'))),
        person1x = colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person1y = colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person2x = colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person2y = colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person3x = colPersonNodes.item(2).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person3y = colPersonNodes.item(2).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person4x = colPersonNodes.item(3).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person4y = colPersonNodes.item(3).selectSingleNode('geometry/Rectangle').getAttribute('y');

    if (arrEyeBoundX[0] < arrEyeBoundX[1]) {
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person1x);
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person1y);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person2x);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person2y);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person3x);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person3y);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person4x);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person4y);
    } else {
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person3x);
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person3y);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person4x);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person4y);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person1x);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person1y);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person2x);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person2y);
    }

    oXmlDoc.save(xmlFileName);
    WScript.Quit(0);
  } else {
    WScript.StdErr.WriteLine('Wrong number of either "eye" or "person" nodes.');
    WScript.Quit(1);
  }
}
catch(e) {
  WScript.StdErr.WriteLine(e.message);
  WScript.Quit(1);
}

set /A x+=1

if %x% leq 201 goto loop else goto eof

:eof
exit "

But, when I run the code, the cmd window is showing the mesage: " C:\Users\yoga\Desktop\Test\JSRIP~3.BAT(69, 10) Microsoft JScript compilation error: Expected ';' Press any key to continue..." and nothig happen.

Thank you a lot for your time!

Dan

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Jrepl

#10 Post by aGerman » 30 Jun 2017 03:27

The script is a hybrid script that will be run twice. First as Batch and then called as JScript (using cscript.exe) out of the Batch code. To achieve that you need to follow a defined structure that is
- first line with valid code in Batch and JScript that is only there to initiate a multi line comment in JScript
- Batch code between /* and */ that will be considered as JScript comment. In this block cscript.exe will be called that runs the same script again as JScript. The batch execution will be quit after either GOTO :EOF of EXIT /B. Thus, the following JScript code was never seen by the command interpreter.
- JScript code following after */ parsed by cscript.exe.

As you can see the script has to be clearly clustered. You can't write any batch code in the JScript block or vice versa.

When I'm back home I'll try to implement your loop.

Steffen

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Jrepl

#11 Post by aGerman » 30 Jun 2017 10:29

Seems that your file names are numeric and you simply want to process them in a defined range.

Code: Select all

@if (@a)==(@b) @end /*

:: Batch
@echo off &setlocal

set /a "start=21653196, stop=21653201"

for /l %%i in (%start% 1 %stop%) do (
  if exist "%%i.xml" (
    cscript //nologo //e:jscript "%~fs0" "%%i.xml"
  ) else (
    echo "%%i.xml" not found
  )
)

pause

:: JScript
exit /b&::*/ try {
  var xmlFileName = WScript.Arguments(0);
      oXmlDoc = new ActiveXObject('Microsoft.XMLDOM');

  oXmlDoc.load(xmlFileName);

  var colEyeNodes = oXmlDoc.documentElement.getElementsByTagName('eye'),
      colPersonNodes = oXmlDoc.documentElement.getElementsByTagName('person');

  if (colEyeNodes.length === 2 && colPersonNodes.length === 4) {
    var arrEyeBoundX = new Array(parseFloat(colEyeNodes.item(0).selectSingleNode('eye-bounds/geometry/Rectangle').getAttribute('x')),
                                 parseFloat(colEyeNodes.item(1).selectSingleNode('eye-bounds/geometry/Rectangle').getAttribute('x'))),
        person1x = colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person1y = colPersonNodes.item(0).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person2x = colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person2y = colPersonNodes.item(1).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person3x = colPersonNodes.item(2).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person3y = colPersonNodes.item(2).selectSingleNode('geometry/Rectangle').getAttribute('y'),
        person4x = colPersonNodes.item(3).selectSingleNode('geometry/Rectangle').getAttribute('x'),
        person4y = colPersonNodes.item(3).selectSingleNode('geometry/Rectangle').getAttribute('y');

    if (arrEyeBoundX[0] < arrEyeBoundX[1]) {
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person1x);
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person1y);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person2x);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person2y);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person3x);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person3y);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person4x);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person4y);
    } else {
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person3x);
      colEyeNodes.item(0).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person3y);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person4x);
      colEyeNodes.item(0).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person4y);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('x', person1x);
      colEyeNodes.item(1).selectSingleNode('lower-eyelid/geometry/Point').setAttribute('y', person1y);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('x', person2x);
      colEyeNodes.item(1).selectSingleNode('upper-eyelid/geometry/Point').setAttribute('y', person2y);
    }

    oXmlDoc.save(xmlFileName);
    WScript.Quit(0);
  } else {
    WScript.StdErr.WriteLine('Wrong number of either "eye" or "person" nodes.');
    WScript.Quit(1);
  }
}
catch(e) {
  WScript.StdErr.WriteLine(e.message);
  WScript.Quit(1);
}

As you can see the JScript block is not affected by the changes. The FOR /L loop increments the number in %%i that is used as file name and passed to the JScript with extension .xml appended.

Steffen

mogodan2008
Posts: 17
Joined: 25 Jun 2017 02:37

Re: Jrepl

#12 Post by mogodan2008 » 30 Jun 2017 21:42

Hi Steffen,

I tried the code, but is not working. After run the code, the cmd window is open and close very quickly.

Thank you,
Dan

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Jrepl

#13 Post by aGerman » 01 Jul 2017 00:56

Works here. Did you customize variables start and stop? Are they numeric only?
I'll attach the file below.
If the window closes too quick that you can't see any error message then try as follows

- open a cmd window (press [Windows]+[R], type CMD, click OK)
- navigate to the path of your batch file using

Code: Select all

cd /d "c:\path\of\your\file"
- either type the name of the batch file or drag/drop the batch file to the cmd window
- hit Enter to run the script

Now you should see the messages.

Steffen
Attachments
change_xml.zip
(933 Bytes) Downloaded 359 times

mogodan2008
Posts: 17
Joined: 25 Jun 2017 02:37

Re: Jrepl

#14 Post by mogodan2008 » 01 Jul 2017 03:06

Hi Steffen,

it's working! Thanks a lot!

I have just a question: How to modify your code if I have just a pair of lower-eyelied, upper-eyelied and Person1 and Person2?
In the same way, I want to replace x, y points from Person1 and Person2 to lower-eyelied and upper-eyelied, without comparition of eyes. Thank you very much!

Kind regards,
Dan

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Jrepl

#15 Post by aGerman » 01 Jul 2017 07:11

I can extend the script (see the attached file) but I can only guess from what person you want to assign the values. Your explanation wasn't clear enough.

Steffen
Attachments
change_xml.zip
(1009 Bytes) Downloaded 378 times

Post Reply