none
XYToPage Problems RRS feed

  • Question

  • I'm trying to use the XYToPage to convert shape coordinates to page coordinates, but it doesn't seem to work on the simplest case, when a shape is not grouped:

    Dim xPos As Double

    Dim yPos As Double

    thisShape.XYToPage(thisShape.Cells("PinX").Result("in"), thisShape.Cells("PinY").Results("in"), xPos, yPos)

    the inputs and results are:

    PinY = 6.537...

    PinX = 6.7125...

    yPos = 12.287...

    xPos = 12.6378...

    When my shape is not part of a group on the page, shouldn't the shape's coordinates be the same as the page coordinates?   The pageScale/drawingScale = 1.

    Thank you in advance.

    Gina


    Gina

    Tuesday, March 5, 2013 2:20 PM

Answers

  • Hi Gina,

    Thank you for posting in the MSDN Forum.

    Based on my observation, they are not the same thing.

    In Page Setup->Drawing Scale window, I've seen that the Drawing Scale is set to No Scale(1:1) by default.

    Then I've tested with a single shape and macro below.

    Sub test()
        Dim shp As Shape
        Set shp = ActiveDocument.Pages(1).Shapes(1)
        Debug.Print shp.Cells("PinX").Result("mm")
        Debug.Print shp.Cells("PinY").Result("mm")
        
        Dim xPos As Double
        Dim yPos As Double
    
        shp.XYFromPage x:=shp.Cells("PinX").Result("mm"), y:=shp.Cells("PinY").Result("mm"), xprime:=xPos, yPrime:=yPos
        Debug.Print xPos
        Debug.Print yPos
        
    End Sub

    Scenario 1:

    Scenario 2:

    You can right click on the pictures and download them to see them more clear.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 7, 2013 11:29 AM
    Moderator
  • Hi Gina,

    Thank you for your last reply.

    I've tested with macro below.

    Sub test2()
        Dim shp As Shape
        Set shp = ActiveDocument.Pages(1).Shapes(1)
        Debug.Print shp.Cells("PinX").Result("mm")
        Debug.Print shp.Cells("PinY").Result("mm")
        
        Debug.Print shp.Shapes(1).Cells("PinX").Result("mm")
        Debug.Print shp.Shapes(1).Cells("PinY").Result("mm")
        Debug.Print shp.Shapes(1).Cells("Height").Result("mm")
        
    End Sub

    Scenario:

    When the target shape is in a group, the PinX/ PinY of the target shape refers to its position within the group,

    For the shape you want to add, I think the

    • PinX value can be set to the PinX value of child shape.
    • PinY value can be set to the PinY value of the grouped shape + 1/2 of the child shape height.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Gina1111 Friday, March 8, 2013 4:38 PM
    Friday, March 8, 2013 5:45 AM
    Moderator

All replies

  • Hi Gina,

    Thank you for posting in the MSDN Forum.

    Based on my observation, they are not the same thing.

    In Page Setup->Drawing Scale window, I've seen that the Drawing Scale is set to No Scale(1:1) by default.

    Then I've tested with a single shape and macro below.

    Sub test()
        Dim shp As Shape
        Set shp = ActiveDocument.Pages(1).Shapes(1)
        Debug.Print shp.Cells("PinX").Result("mm")
        Debug.Print shp.Cells("PinY").Result("mm")
        
        Dim xPos As Double
        Dim yPos As Double
    
        shp.XYFromPage x:=shp.Cells("PinX").Result("mm"), y:=shp.Cells("PinY").Result("mm"), xprime:=xPos, yPrime:=yPos
        Debug.Print xPos
        Debug.Print yPos
        
    End Sub

    Scenario 1:

    Scenario 2:

    You can right click on the pictures and download them to see them more clear.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 7, 2013 11:29 AM
    Moderator
  • Thank you, Quist.  This is helpful for you to repeat my problem.

    I'm trying to get the program to drop a new shape on top of a target shape.  The new shape doesn't have to be centered exactly over the target shape, just overlapping or close.  I want this to work whether the target shape is in a group or not. 

    When the target shape is not in a group, I simply make the PinX/ PinY the same for both shapes.  When the target shape is in a group, the PinX/ PinY of the target shape refers to its position within the group, so plugging those coordinates into the new shape makes the new shape drop away from the target shape, not over it, like I want.  I thought the XYToPage was supposed to translate the X/Y coordinates of a shape within a group to its coordinates on a page, but apparently not.

    Any ideas on how to get a new shape to drop onto a target shape that is in a group?


    Gina

    Thursday, March 7, 2013 1:46 PM
  • Hi Gina,

    Thank you for your last reply.

    I've tested with macro below.

    Sub test2()
        Dim shp As Shape
        Set shp = ActiveDocument.Pages(1).Shapes(1)
        Debug.Print shp.Cells("PinX").Result("mm")
        Debug.Print shp.Cells("PinY").Result("mm")
        
        Debug.Print shp.Shapes(1).Cells("PinX").Result("mm")
        Debug.Print shp.Shapes(1).Cells("PinY").Result("mm")
        Debug.Print shp.Shapes(1).Cells("Height").Result("mm")
        
    End Sub

    Scenario:

    When the target shape is in a group, the PinX/ PinY of the target shape refers to its position within the group,

    For the shape you want to add, I think the

    • PinX value can be set to the PinX value of child shape.
    • PinY value can be set to the PinY value of the grouped shape + 1/2 of the child shape height.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Gina1111 Friday, March 8, 2013 4:38 PM
    Friday, March 8, 2013 5:45 AM
    Moderator
  • Great.  Thank you!

    Gina

    Friday, March 8, 2013 4:38 PM
  • Hi Gina,

    Glad to hear that your issue has been resolved.

    I'll mark my first reply as answer since it answers your original question

    shouldn't the shape's coordinates be the same as the page coordinates?

    Have a nice day.


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 11, 2013 5:02 AM
    Moderator