none
OpenXML comparing offsets and extents RRS feed

  • Question

  • How do I compare an offset of a GroupShape that is already in a presentation to another offset? I am trying to check if a presentation is at the right place. What I have tried doing so far is:

    Drwng.Offset testOffset = new Drwng.Offset { X = xPos, Y = yPos };
    Drwng.Extents testExtents = new Drwng.Extents() { Cx = width, Cy = heigth };
    if (group.GroupShapeProperties.TransformGroup.Offset.Equals(testOffset)
        && group.GroupShapeProperties.TransformGroup.Extents.Equals(testExtents))
    {
        Console.WriteLine("IDGroup already exists and has correct position and size.");
    }

    and this:

    Drwng.Offset testOffset = new Drwng.Offset { X = xPos, Y = yPos };
    Drwng.Extents testExtents = new Drwng.Extents() { Cx = width, Cy = heigth };
    if (group.GroupShapeProperties.TransformGroup.Offset == testOffset
        && group.GroupShapeProperties.TransformGroup.Extents == testExtents)
    {
        Console.WriteLine("IDGroup already exists and has correct position and size.");
    }

    But the conditions never are true even though the GrouShape I am testing was set at that exact position by me:

        static long width = 1800000;            // Shape width in in 1/360000 cm.
        static long heigth = 1800000;            // Shape heigth in in 1/360000 cm.
        static long xPos = 10392000;            // Represents the shape x position in 1/36000 cm (width of the slide minus width of shape).
        static long yPos = 0;                   // Represents the shape y position in 1/36000 cm.

    Drwng.Offset offset2 = new Drwng.Offset() { X = xPos, Y = yPos };        // Group positiion

    Drwng.Extents extents2 = new Drwng.Extents() { Cx = width, Cy = heigth };// Group size;// Group size

    Can somebody tell me what I am doing wrong? If you need any additional information please tell me.


    • Edited by not_a_table Thursday, August 11, 2016 8:22 AM Added information.
    Thursday, August 11, 2016 7:36 AM

Answers

  • Hi,

    The issue comes from the new offset/extents you declared.

    For the Offset node of the PowerPoint, it has parent node while there is no parent node for the new offset.(You could see the picture below) That's why the condition never comes true.

    Try

           var offsetx= group.GroupShapeProperties.TransformGroup.Offset.X.Value ;
                    var offsety = group.GroupShapeProperties.TransformGroup.Offset.Y.Value;
                    var extentsCx = group.GroupShapeProperties.TransformGroup.Extents.Cx.Value;
                    var extentsCy = group.GroupShapeProperties.TransformGroup.Extents.Cy.Value;
     
                    if (offsetx== testOffset.X.Value && offsety== testOffset.Y.Value
                        && extentsCx == testExtents.Cx.Value && extentsCy== testExtents.Cy.Value )


    • Marked as answer by not_a_table Friday, August 12, 2016 11:01 AM
    Friday, August 12, 2016 10:36 AM
    Moderator

All replies

  • How many shapes do you group? Is there any multiple combination for your shapes?

    I suggest you use Open XML SDK Tool to check if you are accessing the right node.

    Click here to download Open XML SDK Tool.

    You could paste your XML info of the whole ShapeTree node here, we could help you check if you are accessing the right node.

    The following is an example of two groups for three shapes.

    <p:spTree xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
      <p:nvGrpSpPr>
        <p:cNvPr id="1" name="" />
        <p:cNvGrpSpPr />
        <p:nvPr />
      </p:nvGrpSpPr>
      <p:grpSpPr>
        <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
          <a:off x="0" y="0" />
          <a:ext cx="0" cy="0" />
          <a:chOff x="0" y="0" />
          <a:chExt cx="0" cy="0" />
        </a:xfrm>
      </p:grpSpPr>
      <p:grpSp>
        <p:nvGrpSpPr>
          <p:cNvPr id="4" name="Group 3" />
          <p:cNvGrpSpPr />
          <p:nvPr />
        </p:nvGrpSpPr>
        <p:grpSpPr>
          <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
            <a:off x="2988127" y="1053193" />
            <a:ext cx="5551716" cy="3624941" />
            <a:chOff x="2988127" y="1053193" />
            <a:chExt cx="5551716" cy="3624941" />
          </a:xfrm>
        </p:grpSpPr>
        <p:grpSp>
          <p:nvGrpSpPr>
            <p:cNvPr id="7" name="Group 6" />
            <p:cNvGrpSpPr />
            <p:nvPr />
          </p:nvGrpSpPr>
          <p:grpSpPr>
            <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
              <a:off x="2988127" y="1053193" />
              <a:ext cx="3526970" cy="3624941" />
              <a:chOff x="2661556" y="1469572" />
              <a:chExt cx="3526970" cy="3624941" />
            </a:xfrm>
          </p:grpSpPr>
    

    Friday, August 12, 2016 5:58 AM
    Moderator
  • I group only two shapes. Here is the corresponding XML of the whole tree:

      <p:spTree>
        <p:nvGrpSpPr>
          <p:cNvPr id="1" name="" />
          <p:cNvGrpSpPr />
          <p:nvPr />
        </p:nvGrpSpPr>
        <p:grpSpPr>
          <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
            <a:off x="0" y="0" />
            <a:ext cx="0" cy="0" />
            <a:chOff x="0" y="0" />
            <a:chExt cx="0" cy="0" />
          </a:xfrm>
        </p:grpSpPr>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="2" name="Title 1" />
            <p:cNvSpPr>
              <a:spLocks noGrp="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
            </p:cNvSpPr>
            <p:nvPr>
              <p:ph type="ctrTitle" />
            </p:nvPr>
          </p:nvSpPr>
          <p:spPr />
          <p:txBody>
            <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
            <a:lstStyle xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
            <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
              <a:endParaRPr lang="de-DE" />
            </a:p>
          </p:txBody>
        </p:sp>
        <p:sp>
          <p:nvSpPr>
            <p:cNvPr id="3" name="Subtitle 2" />
            <p:cNvSpPr>
              <a:spLocks noGrp="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
            </p:cNvSpPr>
            <p:nvPr>
              <p:ph type="subTitle" idx="1" />
            </p:nvPr>
          </p:nvSpPr>
          <p:spPr />
          <p:txBody>
            <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
            <a:lstStyle xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
            <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
              <a:endParaRPr lang="de-DE" />
            </a:p>
          </p:txBody>
        </p:sp>
        <p:grpSp>
          <p:nvGrpSpPr>
            <p:cNvPr id="5" name="IDGroup" />
            <p:cNvGrpSpPr />
            <p:nvPr />
          </p:nvGrpSpPr>
          <p:grpSpPr>
            <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
              <a:off x="10392000" y="0" />
              <a:ext cx="1800000" cy="1800000" />
              <a:chOff x="10392000" y="0" />
              <a:chExt cx="1800000" cy="1800000" />
            </a:xfrm>
          </p:grpSpPr>
          <p:sp>
            <p:nvSpPr>
              <p:cNvPr id="4" name="SlideID" />
              <p:cNvSpPr />
              <p:nvPr />
            </p:nvSpPr>
            <p:spPr>
              <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:off x="10392000" y="0" />
                <a:ext cx="1800000" cy="1800000" />
              </a:xfrm>
              <a:prstGeom prst="rect" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:avLst />
              </a:prstGeom>
              <a:solidFill xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="accent2">
                  <a:lumMod val="40000" />
                  <a:lumOff val="60000" />
                  <a:alpha val="0" />
                </a:schemeClr>
              </a:solidFill>
              <a:ln xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:noFill />
              </a:ln>
            </p:spPr>
            <p:style>
              <a:lnRef idx="2" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="accent1">
                  <a:shade val="50000" />
                </a:schemeClr>
              </a:lnRef>
              <a:fillRef idx="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="accent1" />
              </a:fillRef>
              <a:effectRef idx="0" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="accent1" />
              </a:effectRef>
              <a:fontRef idx="minor" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="lt1" />
              </a:fontRef>
            </p:style>
            <p:txBody>
              <a:bodyPr rtlCol="0" anchor="ctr" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
              <a:lstStyle xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
              <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:pPr algn="ctr" />
                <a:r>
                  <a:rPr lang="de-DE" smtClean="0">
                    <a:solidFill>
                      <a:srgbClr val="FF0000" />
                    </a:solidFill>
                  </a:rPr>
                  <a:t>1</a:t>
                </a:r>
                <a:endParaRPr lang="de-DE" dirty="0">
                  <a:solidFill>
                    <a:schemeClr val="tx1" />
                  </a:solidFill>
                </a:endParaRPr>
              </a:p>
            </p:txBody>
          </p:sp>
          <p:sp>
            <p:nvSpPr>
              <p:cNvPr id="3" name="SlideIDLink">
                <a:hlinkClick r:id="rId99" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
              </p:cNvPr>
              <p:cNvSpPr />
              <p:nvPr />
            </p:nvSpPr>
            <p:spPr>
              <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:off x="10392000" y="0" />
                <a:ext cx="1800000" cy="1800000" />
              </a:xfrm>
              <a:prstGeom prst="rect" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:avLst />
              </a:prstGeom>
              <a:solidFill xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="accent2">
                  <a:lumMod val="40000" />
                  <a:lumOff val="60000" />
                  <a:alpha val="0" />
                </a:schemeClr>
              </a:solidFill>
              <a:ln xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:noFill />
              </a:ln>
            </p:spPr>
            <p:style>
              <a:lnRef idx="2" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="accent1">
                  <a:shade val="50000" />
                </a:schemeClr>
              </a:lnRef>
              <a:fillRef idx="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="accent1" />
              </a:fillRef>
              <a:effectRef idx="0" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="accent1" />
              </a:effectRef>
              <a:fontRef idx="minor" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:schemeClr val="lt1" />
              </a:fontRef>
            </p:style>
            <p:txBody>
              <a:bodyPr rtlCol="0" anchor="ctr" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
              <a:lstStyle xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
              <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                <a:pPr algn="ctr" />
                <a:endParaRPr lang="de-DE" dirty="0">
                  <a:solidFill>
                    <a:schemeClr val="tx1" />
                  </a:solidFill>
                </a:endParaRPr>
              </a:p>
            </p:txBody>
          </p:sp>
        </p:grpSp>
      </p:spTree>


    Friday, August 12, 2016 6:21 AM
  • Hi,

    The issue comes from the new offset/extents you declared.

    For the Offset node of the PowerPoint, it has parent node while there is no parent node for the new offset.(You could see the picture below) That's why the condition never comes true.

    Try

           var offsetx= group.GroupShapeProperties.TransformGroup.Offset.X.Value ;
                    var offsety = group.GroupShapeProperties.TransformGroup.Offset.Y.Value;
                    var extentsCx = group.GroupShapeProperties.TransformGroup.Extents.Cx.Value;
                    var extentsCy = group.GroupShapeProperties.TransformGroup.Extents.Cy.Value;
     
                    if (offsetx== testOffset.X.Value && offsety== testOffset.Y.Value
                        && extentsCx == testExtents.Cx.Value && extentsCy== testExtents.Cy.Value )


    • Marked as answer by not_a_table Friday, August 12, 2016 11:01 AM
    Friday, August 12, 2016 10:36 AM
    Moderator