How to set the origin for a callout to a specific xy coordinate

D

Dave Jenkins

[I finger-checked earlier, so if this is a dupe, please forgive the wasted
bandwidth.]

In VBA, I want to be able to create a callout autoshape, and "anchor" it, or
set its origin, to a specific xy coordinate (which I know, in pixels). My
problem is in determining where the origin is to begin with. I do know the
top and left of the shape, in points, but that's about it.

I'm creating the shape just fine -- it's just moving it around precisely
that's got me stumped.

Is there any easy way to compute the adjustments I need to make on the shape
to do what I want?

I've thought of manipulating drop value,s but that seems very cumbersome to
me -- is there an easier way?

Thanks!
 
S

Shyam Pillai

Manipulate the adjustments object to get the precise position.

The first adjustment is the X position represented relatively with reference
to the top-left vertex of the parent shape as the point of origin. 1
relatively represents the width/height of the shape.

Dim oSld As Slide
Dim oShp As Shape

Set oSld = ActivePresentation.Slides(1)
Set oShp = oSld.Shapes.AddShape(msoShapeCloudCallout, 50, 50, 100, 100)
oShp.Adjustments(1) = -0.5
oShp.Adjustments(2) = -0.5


--
Regards,
Shyam Pillai

Animation Carbon: Copy/Paste/Share animation libraries.
www.animationcarbon.com
 
D

Dave Jenkins

Thanks, Shyam, but that won't get me all the way there.

I'll try to be more explicit: in the editor, I want the user to be able to
click a point on a slide, and then I want to generate a callout that points
to that place. I am managing to capture the pixel coordinates of right
clicks, and I can certainly generate the callout autoshape, but I want the
callout shape line to point to the place picked by the user.

So I'm thinking that first I have to convert the coordinate of the requested
point to points, and then somehow use adjustment items 1 and 2 to shift the
origin (the line begin point).

What I've tried is this:

Set calloutSh =
ActiveWindow.View.Slide.Shapes.AddShape(msoShapeOvalCallout, L, T, W, H)
calloutSh.Adjustments.Item(1) = -0.5
calloutSh.Adjustments.Item(1) = (RightClickPoint.x /
ActiveWindow.PointsToScreenPixelsX(W))
calloutSh.Adjustments.Item(2) = -0.5
calloutSh.Adjustments.Item(2) = (RightClickPoint.y /
ActiveWindow.PointsToScreenPixelsY(H))

That's a start, but it's not correct. And it also seems to yield varying
results depending on the zoom level being used. It appears to me that there
needs to be some further scaling at one point or another, and maybe some
consideration given to screen resolution?

I just don't know - if you can shed some light on this, I would appreciate it.
--
Dave Jenkins
K5KX


Shyam Pillai said:
Manipulate the adjustments object to get the precise position.

The first adjustment is the X position represented relatively with reference
to the top-left vertex of the parent shape as the point of origin. 1
relatively represents the width/height of the shape.

Dim oSld As Slide
Dim oShp As Shape

Set oSld = ActivePresentation.Slides(1)
Set oShp = oSld.Shapes.AddShape(msoShapeCloudCallout, 50, 50, 100, 100)
oShp.Adjustments(1) = -0.5
oShp.Adjustments(2) = -0.5


--
Regards,
Shyam Pillai

Animation Carbon: Copy/Paste/Share animation libraries.
www.animationcarbon.com



Dave Jenkins said:
[I finger-checked earlier, so if this is a dupe, please forgive the wasted
bandwidth.]

In VBA, I want to be able to create a callout autoshape, and "anchor" it,
or
set its origin, to a specific xy coordinate (which I know, in pixels). My
problem is in determining where the origin is to begin with. I do know
the
top and left of the shape, in points, but that's about it.

I'm creating the shape just fine -- it's just moving it around precisely
that's got me stumped.

Is there any easy way to compute the adjustments I need to make on the
shape
to do what I want?

I've thought of manipulating drop value,s but that seems very cumbersome
to
me -- is there an easier way?

Thanks!
 
D

Dave Jenkins

I think I see a problem with that snippet I posted earlier: it's computing
the adjustment in pixels (I think) - I need to get that converted to points /
height and width in points -- how do I do that? That is, at some point I
have to convert pixels to points - what's tha algorithm (or, hopefully,
method) for doing that?

Thanks.
--
Dave Jenkins
K5KX


Shyam Pillai said:
Manipulate the adjustments object to get the precise position.

The first adjustment is the X position represented relatively with reference
to the top-left vertex of the parent shape as the point of origin. 1
relatively represents the width/height of the shape.

Dim oSld As Slide
Dim oShp As Shape

Set oSld = ActivePresentation.Slides(1)
Set oShp = oSld.Shapes.AddShape(msoShapeCloudCallout, 50, 50, 100, 100)
oShp.Adjustments(1) = -0.5
oShp.Adjustments(2) = -0.5


--
Regards,
Shyam Pillai

Animation Carbon: Copy/Paste/Share animation libraries.
www.animationcarbon.com



Dave Jenkins said:
[I finger-checked earlier, so if this is a dupe, please forgive the wasted
bandwidth.]

In VBA, I want to be able to create a callout autoshape, and "anchor" it,
or
set its origin, to a specific xy coordinate (which I know, in pixels). My
problem is in determining where the origin is to begin with. I do know
the
top and left of the shape, in points, but that's about it.

I'm creating the shape just fine -- it's just moving it around precisely
that's got me stumped.

Is there any easy way to compute the adjustments I need to make on the
shape
to do what I want?

I've thought of manipulating drop value,s but that seems very cumbersome
to
me -- is there an easier way?

Thanks!
 
S

Shyam Pillai

Dave,
You can use the following to convert pixels to twips. 20 Twips is then equal
to 1 Point.
'===========================================================================
Private Declare Function GetDC Lib "user32" (ByVal HWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal HWnd As Long, ByVal
hDC As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal
nIndex As Long) As Long

Const LOGPIXELSX = 88
Const LOGPIXELSY = 90
Const TWIPSPERINCH As Single = 1440

Sub TestIt()
Dim sngX as single
Dim sngY as single

' In pixels
sngX=640
sngY=480

Call ConvertPIXELSToTWIPS(sngX,sngY)

'In points.
MsgBox sngX/20 & " " & sngY/20

End Sub


Sub ConvertPIXELSToTWIPS(x As Single, y As Single)
' PowerPoint uses Points as the unit of measurement.
' 20 Twips = 1 Point
Dim hDC As Long, HWnd As Long, RetVal As Long
Dim XPIXELSPERINCH, YPIXELSPERINCH
hDC = GetDC(0)
XPIXELSPERINCH = GetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = GetDeviceCaps(hDC, LOGPIXELSY)
RetVal = ReleaseDC(0, hDC)
x = (x / XPIXELSPERINCH) * TWIPSPERINCH
y = (y / YPIXELSPERINCH) * TWIPSPERINCH
End Sub
'===========================================================================


--
Regards,
Shyam Pillai

Animation Carbon: Copy/Paste/Share animation libraries.
www.animationcarbon.com


Dave Jenkins said:
I think I see a problem with that snippet I posted earlier: it's computing
the adjustment in pixels (I think) - I need to get that converted to
points /
height and width in points -- how do I do that? That is, at some point I
have to convert pixels to points - what's tha algorithm (or, hopefully,
method) for doing that?

Thanks.
--
Dave Jenkins
K5KX


Shyam Pillai said:
Manipulate the adjustments object to get the precise position.

The first adjustment is the X position represented relatively with
reference
to the top-left vertex of the parent shape as the point of origin. 1
relatively represents the width/height of the shape.

Dim oSld As Slide
Dim oShp As Shape

Set oSld = ActivePresentation.Slides(1)
Set oShp = oSld.Shapes.AddShape(msoShapeCloudCallout, 50, 50, 100, 100)
oShp.Adjustments(1) = -0.5
oShp.Adjustments(2) = -0.5


--
Regards,
Shyam Pillai

Animation Carbon: Copy/Paste/Share animation libraries.
www.animationcarbon.com



Dave Jenkins said:
[I finger-checked earlier, so if this is a dupe, please forgive the
wasted
bandwidth.]

In VBA, I want to be able to create a callout autoshape, and "anchor"
it,
or
set its origin, to a specific xy coordinate (which I know, in pixels).
My
problem is in determining where the origin is to begin with. I do know
the
top and left of the shape, in points, but that's about it.

I'm creating the shape just fine -- it's just moving it around
precisely
that's got me stumped.

Is there any easy way to compute the adjustments I need to make on the
shape
to do what I want?

I've thought of manipulating drop value,s but that seems very
cumbersome
to
me -- is there an easier way?

Thanks!
 
D

Dave Jenkins

I think this is making life a lot easier, Shyam - thanks!

Only one thing more: I need to do this in the editor, not in slideshow. So
everything has to be realtive to the image of the slide in the pane. How can
I get the coordinates of the UL of the slide image?

--
Dave Jenkins
K5KX


Shyam Pillai said:
Dave,
You can use the following to convert pixels to twips. 20 Twips is then equal
to 1 Point.
'===========================================================================
Private Declare Function GetDC Lib "user32" (ByVal HWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal HWnd As Long, ByVal
hDC As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal
nIndex As Long) As Long

Const LOGPIXELSX = 88
Const LOGPIXELSY = 90
Const TWIPSPERINCH As Single = 1440

Sub TestIt()
Dim sngX as single
Dim sngY as single

' In pixels
sngX=640
sngY=480

Call ConvertPIXELSToTWIPS(sngX,sngY)

'In points.
MsgBox sngX/20 & " " & sngY/20

End Sub


Sub ConvertPIXELSToTWIPS(x As Single, y As Single)
' PowerPoint uses Points as the unit of measurement.
' 20 Twips = 1 Point
Dim hDC As Long, HWnd As Long, RetVal As Long
Dim XPIXELSPERINCH, YPIXELSPERINCH
hDC = GetDC(0)
XPIXELSPERINCH = GetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = GetDeviceCaps(hDC, LOGPIXELSY)
RetVal = ReleaseDC(0, hDC)
x = (x / XPIXELSPERINCH) * TWIPSPERINCH
y = (y / YPIXELSPERINCH) * TWIPSPERINCH
End Sub
'===========================================================================


--
Regards,
Shyam Pillai

Animation Carbon: Copy/Paste/Share animation libraries.
www.animationcarbon.com


Dave Jenkins said:
I think I see a problem with that snippet I posted earlier: it's computing
the adjustment in pixels (I think) - I need to get that converted to
points /
height and width in points -- how do I do that? That is, at some point I
have to convert pixels to points - what's tha algorithm (or, hopefully,
method) for doing that?

Thanks.
--
Dave Jenkins
K5KX


Shyam Pillai said:
Manipulate the adjustments object to get the precise position.

The first adjustment is the X position represented relatively with
reference
to the top-left vertex of the parent shape as the point of origin. 1
relatively represents the width/height of the shape.

Dim oSld As Slide
Dim oShp As Shape

Set oSld = ActivePresentation.Slides(1)
Set oShp = oSld.Shapes.AddShape(msoShapeCloudCallout, 50, 50, 100, 100)
oShp.Adjustments(1) = -0.5
oShp.Adjustments(2) = -0.5


--
Regards,
Shyam Pillai

Animation Carbon: Copy/Paste/Share animation libraries.
www.animationcarbon.com



[I finger-checked earlier, so if this is a dupe, please forgive the
wasted
bandwidth.]

In VBA, I want to be able to create a callout autoshape, and "anchor"
it,
or
set its origin, to a specific xy coordinate (which I know, in pixels).
My
problem is in determining where the origin is to begin with. I do know
the
top and left of the shape, in points, but that's about it.

I'm creating the shape just fine -- it's just moving it around
precisely
that's got me stumped.

Is there any easy way to compute the adjustments I need to make on the
shape
to do what I want?

I've thought of manipulating drop value,s but that seems very
cumbersome
to
me -- is there an easier way?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top