Working with Shapes

A

Avivit Bercovici

Hi,
3 short questions:
1. If I get a Shape as a parameter to a method, how can I know which slide
does it belong to?
2. How can I compare 2 shapes. I tried to use ReferenceEquals but it doesn't
work if they are from different shape ranges (for example due to selections).
3. Is there a unique property to shape (or a unique identifier)?

I'm using PP 2007.
Thanks a lot
Avivit
 
M

Matti Vuori

=?Utf-8?B?QXZpdml0IEJlcmNvdmljaQ==?=
3 short questions:
1. If I get a Shape as a parameter to a method, how can I know which
slide does it belong to?

s.Parent should have the slide
2. How can I compare 2 shapes. I tried to use ReferenceEquals but it
doesn't work if they are from different shape ranges (for example due
to selections).

Property by property?...
3. Is there a unique property to shape (or a unique
identifier)?

Guess what: the property is named id

Learn to use the watch window in the macro debugger to check out what
properties some object, like your shape, really has. Just add your variable
name as a watch expression and when you step through your code you can see
what your parameters contain.
 
C

Cosmo

This is a function I use to identify the parent slide (or master/custom
layout) for an object

'********************************************************************************************************
' Function to get key used for Slide/Master/Layout/Presentatio
'********************************************************************************************************
Private Function getSlideKey(ByRef theObject As Object) As String
Dim objectType As String
On Error GoTo errorcode
' NOTE - Loop until theObject.Parent is either a
Slide/Design/Master/CustomLayout

objectType = TypeName(theObject)
If objectType = "Slide" Then
' Get name and slide number ( or SlideIndex or SlideID??)
getSlideKey = "Slide " & theObject.slideNumber
ElseIf objectType = "Design" Then
' Get name and Index?
getSlideKey = "Design " & CStr(theObject.Index)
ElseIf objectType = "Master" Then
' Slide Master - Get name and index?
getSlideKey = "Master " & CStr(theObject.Design.Index)
ElseIf objectType = "CustomLayout" Then
' Custom Layout for Slide Master - Get name/Index of master &
name/index of layout
getSlideKey = "Custom Layout " & CStr(theObject.Index)
ElseIf objectType = "Presentation" Then
getSlideKey = "Presentation " & CStr(theObject.FullName)
Else
getSlideKey = getSlideKey(theObject.Parent)
End If
Exit Function
errorcode:
Debug.Print "Error getting slide number - " & Err.Description & " (" &
Err.Number & ")"
Resume Next
End Function
 
A

Avivit Bercovici

Thank you all.
The solution I am using :
Class MS {
private Shape Shape;
....
public bool Equals(MS other) {
return (this.GetSlide().SlideIndex == other.GetSlide().SlideIndex &&
this.Shape.Id == other.Shape.Id);
}
public Slide GetSlide()
{
return (Shape.Parent as Slide);
}
....
}
 

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