Help!

Working with Shapes

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> General Discussions RSS
Next:  Delegates receiving meeting requests in error - O..  
Author Message
Avivit Bercovici
External


Since: Oct 13, 2009
Posts: 3



PostPosted: Thu Oct 22, 2009 12:48 pm    Post subject: Working with Shapes
Archived from groups: microsoft>public>powerpoint (more info?)

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
Back to top
Steve Rindsberg
External


Since: Apr 02, 2004
Posts: 8464



PostPosted: Thu Oct 22, 2009 4:38 pm    Post subject: Re: Working with Shapes [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <B3E65337-C13C-4E45-9CEB-F9F8352FD1EA.TakeThisOut@microsoft.com>, Avivit
Bercovici wrote:
> 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?

The shape's .Parent property will return the slide the shape is on:

Function HoosierDaddy (oSh as Shape) as Slide
Set HoosierDaddy = oSh.Parent
End Function

It's not quite that simple really ... .Parent returns the shape's "container"
which might also be a notes page, a master, layout, etc. If that's a concern:

Function HoosierDaddy (oSh as Shape) as Object
Set HoosierDaddy = oSh.Parent
End Function

Then use a Select Case on Typename(HoosierDaddy(oSh)) to decide what to do
next.

> 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).

Compare in what way? What do you need to determine? Whether you have two
references to the same shape?

Make sure they're on the same slide first, then compare their ShapeID property.

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

See above. The shape's .Name should be unique in theory; in practice, PPT bugs
make it unreliable.

> I'm using PP 2007.

My sympathies. Wink



==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/
Back to top
Matti Vuori
External


Since: Sep 29, 2009
Posts: 5



PostPosted: Thu Oct 22, 2009 6:10 pm    Post subject: Re: Working with Shapes [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

=?Utf-8?B?QXZpdml0IEJlcmNvdmljaQ==?=
<AvivitBercovici.DeleteThis@discussions.microsoft.com> wrote in
news:B3E65337-C13C-4E45-9CEB-F9F8352FD1EA@microsoft.com:
> 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.
Back to top
Steve Rindsberg
External


Since: Apr 02, 2004
Posts: 8464



PostPosted: Thu Oct 22, 2009 10:01 pm    Post subject: Re: Working with Shapes [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> 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.

Or from the IDE, press F2 and browse to the Shape object; in the pane on the
right, you'll see all shape properties.

Or again in the IDE, assuming a reference is set to a shape object oSh, just
type

oSh. and a pop-up appears listing all shape properties.


==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/
Back to top
Cosmo
External


Since: Apr 18, 2006
Posts: 23



PostPosted: Fri Oct 23, 2009 10:10 am    Post subject: Re: Working with Shapes [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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/Presentation
'********************************************************************************************************
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


"Steve Rindsberg" wrote:

> In article <B3E65337-C13C-4E45-9CEB-F9F8352FD1EA.RemoveThis@microsoft.com>, Avivit
> Bercovici wrote:
> > 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?
>
> The shape's .Parent property will return the slide the shape is on:
>
> Function HoosierDaddy (oSh as Shape) as Slide
> Set HoosierDaddy = oSh.Parent
> End Function
>
> It's not quite that simple really ... .Parent returns the shape's "container"
> which might also be a notes page, a master, layout, etc. If that's a concern:
>
> Function HoosierDaddy (oSh as Shape) as Object
> Set HoosierDaddy = oSh.Parent
> End Function
>
> Then use a Select Case on Typename(HoosierDaddy(oSh)) to decide what to do
> next.
>
> > 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).
>
> Compare in what way? What do you need to determine? Whether you have two
> references to the same shape?
>
> Make sure they're on the same slide first, then compare their ShapeID property.
>
> > 3. Is there a unique property to shape (or a unique identifier)?
>
> See above. The shape's .Name should be unique in theory; in practice, PPT bugs
> make it unreliable.
>
> > I'm using PP 2007.
>
> My sympathies. Wink
>
>
>
> ==============================
> PPT Frequently Asked Questions
> http://www.pptfaq.com/
>
> PPTools add-ins for PowerPoint
> http://www.pptools.com/
>
>
> .
>
Back to top
Steve Rindsberg
External


Since: Apr 02, 2004
Posts: 8464



PostPosted: Fri Oct 23, 2009 3:17 pm    Post subject: Re: Working with Shapes [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <92C8D1D8-25A9-44A6-958F-54C00A9598B7.DeleteThis@microsoft.com>, Cosmo wrote:
> This is a function I use to identify the parent slide (or master/custom
> layout) for an object

Thanks for posting that. One thing: I'd use .SlideIndex rather than .SlideNumber

SlideNumber gives you the slide number that appears e.g. when you insert a Slide Number placeholder.
Normally it's = SlideIndex but if the user changes Page Setup to start numbering with some number other
than the default of 1, you're ... um ... hosed. SlideIndex won't change.

>
> '********************************************************************************************************
> ' Function to get key used for Slide/Master/Layout/Presentation
> '********************************************************************************************************
> 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
>
> "Steve Rindsberg" wrote:
>
> > In article <B3E65337-C13C-4E45-9CEB-F9F8352FD1EA.DeleteThis@microsoft.com>, Avivit
> > Bercovici wrote:
> > > 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?
> >
> > The shape's .Parent property will return the slide the shape is on:
> >
> > Function HoosierDaddy (oSh as Shape) as Slide
> > Set HoosierDaddy = oSh.Parent
> > End Function
> >
> > It's not quite that simple really ... .Parent returns the shape's "container"
> > which might also be a notes page, a master, layout, etc. If that's a concern:
> >
> > Function HoosierDaddy (oSh as Shape) as Object
> > Set HoosierDaddy = oSh.Parent
> > End Function
> >
> > Then use a Select Case on Typename(HoosierDaddy(oSh)) to decide what to do
> > next.
> >
> > > 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).
> >
> > Compare in what way? What do you need to determine? Whether you have two
> > references to the same shape?
> >
> > Make sure they're on the same slide first, then compare their ShapeID property.
> >
> > > 3. Is there a unique property to shape (or a unique identifier)?
> >
> > See above. The shape's .Name should be unique in theory; in practice, PPT bugs
> > make it unreliable.
> >
> > > I'm using PP 2007.
> >
> > My sympathies. Wink
> >
> >
> >
> > ==============================
> > PPT Frequently Asked Questions
> > http://www.pptfaq.com/
> >
> > PPTools add-ins for PowerPoint
> > http://www.pptools.com/
> >
> >
> > .
> >


==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/
Back to top
Avivit Bercovici
External


Since: Oct 13, 2009
Posts: 3



PostPosted: Wed Oct 28, 2009 3:03 am    Post subject: Re: Working with Shapes - 10x, your Solution works [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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);
}
....
}
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> General Discussions All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum