question about ungrouping shapes

Started by david, August 30, 2009, 02:51:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

david

hi everybody,
hope you can help me with the following problem.

when i ungroup a shape i need to do some actions in code on the shapes which where inside the group (and now are no longer part of a group).  i didn't find a way to recognize those shapes.

for example i have a shape named sheet.9 which has two objects in it: a rectangle and a circle.
when i ungroup sheet.9, the event Document_BeforeSelectionDelete is called since the shape sheet.9 should be deleted.  in addition i need to do some actions on the rectangle and circle's properties (their coordinates should now be relative to the page instead of the group) but i have no access to them since the ungroup was already done and i don't know which shapes where in group sheet.9 (i didn't find an event before_ungroup or something like that...).  so now their coordinates are wrong and i can't fix it...

any idea how to make it work?

vojo

since you are writing code....why not just keep the group and walk it with your code to make updates?
If you have difference shapes in the group, place a handle (in a user cell) for the type of shape or query the geometry to the "type"  (e.g.  square means somethign vs circle).

david

hi vojo,
i didn't understand why keeping the type of the shape...
but i thought about a similar idea. to keep in user-cell the shape's parent each time i make a group.  and when i ungroup i search in all the shapes on the frame looking for the relevant shapes.
it may work but the problem is that sometimes there are thousands of objects on the frame so each time i ungroup it will go through all the objects and waste time.  i just hoped there's a faster way...

btw, do i have to save a shape's data somewhere in its shapesheet?
can't i do something similar to c++ and make a member of the shape in code?

vojo

dont ungroup...select the group, call your code.   The selection will subset all the shapes on the frame.
If you are trying to update all the shapes of a type....then go to the document stencil and update it there with code.
doc stencil update will hit all the shapes in the drawing (all sheets).
If you are trying to update all shapes on a sheet but not on all sheets...then I think you are looking at all shapes in
the frame and have to walk them to see.


vojo

you can save in shape or in C...I just figured in shape would be easier to figure out for the non coder.   If in C, then only the guys developing the code will get a look at the values.

Nikolay

Quote from: david on August 30, 2009, 02:51:06 PM
when i ungroup a shape i need to do some actions in code on the shapes which where inside the group (and now are no longer part of a group).  i didn't find a way to recognize those shapes.

Have you seen the QueryCancelUngroup event?
In this event you can "grab" all sub-shapes (child shapes) of the shape that is being ungroupped, save them, and "fix" them later in (e.g.) "no event pending" event

david

thanks.
i didn't know about the event QueryCancelUngroup.  it helped alot!  i saved the shapes in that event and fixed them in the event BeforeSelectionDelete (don't know the event "no event pending").

Visio Guy

Another technique is to save shapes or shape ids in a collection or array, and then process them when the NoEventsPending event fires for the application. So you might do something like this:

private _shapeIdsToProcess = new List(int);

QueryCancelUngroup(...)
{
  // get all the shapes in the group about to be ungrouped
  // add their ids to _shapeIdsToProcess
  // allow the ungroup
}

Visio.NoEventsPending(...)
{
  // for each item in _shapeIdsToProcess
  //  try to get the shape
  //  do something to the shape
  // next
}

For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

david

i don't understand why you're telling me to use the event NoEventPending and not BeforeSelectionDelete.

i wrote the code (that do some actions on the saved shapes) in the event BeforeSelectionDelete and it seems to work...

Visio Guy

No, my code still uses QueryCancelUngroup. But sometimes when you respond to Visio events you have to do things to shapes that can cause problems during the event. If BeforeSelectionDelete works for you, that is good!

The NoEventsPending strategy is good for allowing Visio to "settle down" and finish what it is immediately doing. For instance, sometimes you want to delete other shapes when certain shapes are deleted--like deleting connectors attached to shapes.

In this case deleting shapes inside the BeforeSelectionDelete event will cause big problems. So instead, we find out which connectors we want to delete, then add them to a to-delete array, but we don't delete them. Then when NoEventsPending fires later on, we look at the to-delete array and process it. This seems more complicated, but ends up being less messy.

When we delete the connectors by code, we can set a flag that tells the BeforeSelectionDelete even to ignore the current deletions.

Not exactly what you asked about in your original question, but hopefully people who read this thread will find it interesting :)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Paul Herber

Are you really sure you need to ungroup the shape, David?
What are you trying to achieve that cannot be done with the shape still grouped?

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/