Help, Parent assignment failing

J

Jumper2

I'm trying to change the parent of an object depending on what it is
connected to.
I catch ConnectionAdded and ConnectionDeleted just fine.

When connecting a module to an object, I set the parent of the module.
This works also.

myObjModule.Parent = myObjSystemShape

When disconnecting the module, I want to set it back to having the page
as its parent.

myObjModule.Parent = myObjModule.ContainingPage.PageSheet

But this just generates an exception.

Why would it fail on the second one, but not the first?

Thanks,
-James
 
J

Jumper2

This is really weird. Even something like:

myObjModule.Parent = SomeTopLevelShape.Parent

produces the same exception. There doesn't appear to be anything
useful in the "Err" object that says why there was an exception.

The Visio Automation documentation for the Parent property of shape
says:

When assigning a new parent shape, you must assign a Shape object. If
you want to assign a page or master to be the parent of a shape, you
must assign the Shape object returned by the Page or Master object's
PageSheet property.

Using the syntax:

Set myObjModule.Parent = myObjSystemShape

Always produces an exception of "Object doesn't support this property
or method". Without the set it works fine as long as the Parent isn't
a pagesheet.

I've watched through the event viewer and it doesn't occur while in any
Scope. I did move the assignment to a NoEventsPending handler just in
case, but the behavior was the same.

Given that assigning a pagesheet as the parent of a shape is explicitly
referred to in the documentation and that when performing that action
with the UI, I see the ShapeParentChanged event showing the page
becoming the parent, it has to be possible.

Is this a bug or am I just missing something. I just want to remove a
shape from a group and put it back at the top (page) level. (Given how
the events are processed, I don't want to have to create selection
objects and call the remove from group method repeatedly until it gets
back to the top level).

Thanks,
-James
 
R

Roger

Hello James
In some cases I've found the ContainingShape property to be more reliable
than the Parent property. I don't know why this is the case, but I thought it
might help resolve the problem you've encountered.
Best regards
Roger Billsdon
 

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