Part of dropped shape appearing in wrong place

A

Andy

Visio 2003 SP2

I have a diagram where I am deleting a shape from the diagram and
dropping a new shape in the same place within VBA. Just occasionally
parts of my newly dropped shape appear to be missing. However, the
have in fact be drawn at the bottom left corner of the diagram. Its as
if Visio has drawn part of the shape relative to the diagram rather
than to the shape. It isn't 100% repeatable although it does it quite
frequently. More if the PC is busy. It is redrawn correctly by
refreshing Ctrl-Alt-G.

Ayyone seen this or any ideas

thanks
 
J

JuneTheSecond

I've offten experienced due to my miss-coding.
It was case-by-case how did I mistake.
 
A

Andy

Its not really a coding problem as such. I am deleting a shape of my
diagram and dropping a new master shape on the diagram from my vba
code. Its part of the dropped master that is drawn in the wrong place.
 
J

John

So your code drops a single master in a single page.drop statement and part
of the resulting shape is detatched? Have a think about the following:

1) What's the PinX / Y formulae for the stray shape?

2) Is it the same in the master?

3) Is the stray shape part of a group (on the page and in the master)?

4) Is there any on-drop behaviour in the master under the Events shapesheet
section?

5) How does your code set the drop location for the new shape?

Best regards

John
 
A

Andy

So your code drops a single master in a single page.drop statement and part
of the resulting shape is detatched? Have a think about the following:

1) What's the PinX / Y formulae for the stray shape?

The part of the shape that is stray is a 1-d line, with BeginX, EndX
etc referencing cells in the parent shape, i.e. Sheet.1187!Height*0.25

I had to access my sub shapes using the drawing explorer. Strangely
when i clicked on the stray shape in the drawing explorer, the control
handles were shown in the correct place, not where the line had been
drawn. Its almost as if visio believes it is in the right place, even
though it has actually been drawn in the wrong place. If I select on
the stray shape, the control handles are highlighted in the position
it should have been drawn.Panning and zooming makes not difference.
2) Is it the same in the master?

It is the same as the formula in the master shape, spart from
obviously the change to the parent sheet name.
3) Is the stray shape part of a group (on the page and in the master)?

The shape is part of a group in the master, other parts of the shape
in the same group are drawn in the correct position.
4) Is there any on-drop behaviour in the master under the Events shapesheet
section?

No on drop behaviour.
5) How does your code set the drop location for the new shape?

I have the pin positions as absolute values extracted from the other
shape.
 
A

Andy

Geometryfor the stray shape is

moveto width*0 0 mm
lineto width*1 0mm

Nothing at all complicated.

I'm sure its something to do with the shape being deleted and then a
new master dropped, some sort of timing thing where visio has
forgotten something.

As an experiment i after the delete i called doevents and then dropped
my new master. It appeared to solve the problem, looks a bit clunky
now of course as you see the one shape disappear before the new one is
dropped. Still I guess that suggests its a timeing/cache problem.
 
J

John

If DoEvents helps then I presume your code is taking it's time. How are you
getting a reference to the shape that you delete? Are you using the
selection object?

Can you post the code that you're using to reference, delete and drop?
Might make it easier to diagnose.

John
 
A

Andy

I have internal objects within my application and this has a frerence
to the shape being deleted.

....

set delEquipment = dictEquipment(strEquipmentName)

set delShape = delEquipment.dynamicShape

set vsoPage = delShape.ContainingPage

dblPrevX = .delShape.cells("PinX").ResultIU
dblPrevY = delShape.cells("PinY").ResultIU

call diagram.unlockLayers

delShape.Cells("LockDelete").formula= 0

call .delShape.Delete

DoEvents

Set dropShape = vsoPage.Drop( masterObj, dblPrevX, dblPrevY))

dropShape.Cells("LockDelete").formula= 1

call diagram.lockLayers

....

This is the essential processing being done, not a copy of the exact
code as you would not have sufficient context to make sense of it.
 
J

John

Hi Andy,

Well I guess you've solved it with DoEvents. I've just tested a
page.drop("shape",... with x,y declared but not given a value and this
results in the shape being placed at in the bottom left hand corner of the
page (ie 0,0).

I don't know if dropping the shape before you delete the old one would help
ie:

Page.Drop dropShape,1,1

dropShape.Cells("PinX").Formula = delShape.Cells("PinX").Formula

delShape.Delete

In any case, if DoEvents seems to work then I guess this solves it.

Best regards

John
 
A

Andy

I think i would prefer it if it got the whole shape in the wrong
place, but to be just one sub shape wrong. I will try swapping the
order. Still at the end of the day, Visio is screwing it up somewhere.
I don't think i'm doing anything really unreasonable in deleting and
adding a shape. And most of the time it gets it right, just seems to
go wrong when its being demo'd to customers, lol. Maybe my application
is pushing Visio a bit, currently around 30k lines of code split
between VBA and a VB dll.

Thanks for your help John. Did make me look at a few things I hadn't
thought about, even if it didnt find the problem. I will live with the
doevents for now, guess 2007 may behave differently.
 
A

Andy

I swapped the order so the new shape is dropped and then the previous
shape is deleted. This appears to work properly without forcing a
doevents. I guess just the event processing order has changed. Still
suggests there is some internal issue with visio.
 

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