master shapes and instances

J

Jonathan Spane

Hi everyone,

I currently have a Visio Add-On in C++ that is reading a custom XML file
that creates a stencil with shapes. These shapes have custom properties as
defined by the XML.

With this stencil I proceed to make a drawing with no problems. Here is
where it gets interesting. There will be times where this custom XML will be
updated with new shapes, new properties, or existing shapes will have new
properties defined with them. Here is what I do when that happens in pseudo
code when I read this XML file in.

I close the existing stencil.
I then add new empty stencil by a default name.
I then add the shapes to this stencil with custom properties.
I then save this default stencil as the same name as the old stencil thus
overriding it.
After updating the stencil, I then find the active drawing and try to update
the instance shapes with their new properties based on what was just done to
the stencil.

Most of the time this seems to work. My problem is I sometimes try to get
the shape name in the active drawing and it says it is called "Sheet.#".
Where # is some index. This is weird since this same shape was called
something completely different before I reimported the XML file. It seems
like creating a new stencil has does something to the instanced shapes
intermittently. Once this instanced shape becomes like this, there is new
way to get it working. I have to delete the shape and start over. The other
weird thing is if I look at the custom properties window it displays the
correct name of the instanced shape in title bar. This proves is used to be
named correctly.

Any ideas on how I should approach this problem? I have tried setting the
local name and universal name of the shape. Also, this problem does not seem
to affect every instanced shape. It seems to be random. This is going to be
a problem. If you made it this far thanks for reading.

JP
 
J

John Goldsmith

Hello Jonathan,

Visio has a range of ways to identify shapes. It has name properties, as
you mentioned, plus index and ID properties such as, surprisingly, ID and
UniqueID. Take a look at this DVS link which explains the area:

http://msdn2.microsoft.com/en-us/library/aa201761(office.10).aspx#782

In your case you might also find it useful if you're working with a
selection object to use the shape's Master property to find out if you're
dealing with the correct/intended shape. For example:

shp = ActiveWindow.Selection.PrimaryItem
If shp.Master.Name = "MyMasterName" Then
'My code
End If

What route did you choose in the end for the 'updating with new shapes'
part?

Best regards

John


John Goldsmith
www.visualSignals.co.uk
 
J

Jonathan Spane

Oddly enough the ones that do break no lner have a valid master shape. I
just don't know how it radomly is breaking shapes.
 
J

Jonathan Spane

Here is another update. If I just use the stencil I created programmaticaly
by just dragging the same shape over and over to the drawing eventually one
of these shapes will revert to "Sheet.#" instead of the new name in the
stencil. If I make a copy of this "broken" shape in the drawing the copied
one reverts back to the shape name. Vey weird.
 
J

Jonathan Spane

I can get this to happen outside of my plugin. Here are the following steps.

1. Open an exitings stencil that comes with Visio.
I picked the Basic flowchart.
2. Save this stencil under "My Shapes" so that it can be edited.
3. Pick a shape in the master stencil and edit this master shape to have a
custom property in it. I picked "Rectangle".
4. Now drag this shape to a drawing. You should see the property in the
instanced shape.
5. Keep dragging the same shape from the stencil to the drawing and
eventually an instanced shape will be named "Sheet.#" instead of
"Rectangle.#".

Why would Visio does this occaisnally? By the way I am using Visio 2003
Standard with SP2.
Thanks
JP
 
N

Nikolay Belyh

1. Open an exitings stencil that comes with Visio.
I picked the Basic flowchart.
2. Save this stencil under "My Shapes" so that it can be edited.
3. Pick a shape in the master stencil and edit this master shape to have a
custom property in it. I picked "Rectangle".
4. Now drag this shape to a drawing. You should see the property in the
instanced shape.
5. Keep dragging the same shape from the stencil to the drawing and
eventually an instanced shape will be named "Sheet.#" instead of
"Rectangle.#".

Cannot confirm this.
Just out of curiosity, have tried this on Visio 2003 SP2 and Visio
2007.
Have dropped 34 (!) rectangles.
[Hello, lunar man, we came in peace (c) :) ]
All they are all called "Rectangle.#".

Try disabling all addons/extensions (including your's) and repeat this
fancy experiment... ;)

Kind regards, Nikolay
 
J

Jonathan Spane

I think there may be a couple more steps.

1. At some point during the dropping, add some more properties to the Master
shape.
2. Delete all the dropped shapes on the drawing.
3. Start droppping this new updated stencil shape.
4. Keep repeating this until the problem happens.

Nikolay Belyh said:
1. Open an exitings stencil that comes with Visio.
I picked the Basic flowchart.
2. Save this stencil under "My Shapes" so that it can be edited.
3. Pick a shape in the master stencil and edit this master shape to have
a
custom property in it. I picked "Rectangle".
4. Now drag this shape to a drawing. You should see the property in the
instanced shape.
5. Keep dragging the same shape from the stencil to the drawing and
eventually an instanced shape will be named "Sheet.#" instead of
"Rectangle.#".

Cannot confirm this.
Just out of curiosity, have tried this on Visio 2003 SP2 and Visio
2007.
Have dropped 34 (!) rectangles.
[Hello, lunar man, we came in peace (c) :) ]
All they are all called "Rectangle.#".

Try disabling all addons/extensions (including your's) and repeat this
fancy experiment... ;)

Kind regards, Nikolay
 
D

David Parker

Just checking:
Are you updating Master shapes in code without using the master.Open method?

Jonathan Spane said:
I think there may be a couple more steps.

1. At some point during the dropping, add some more properties to the
Master shape.
2. Delete all the dropped shapes on the drawing.
3. Start droppping this new updated stencil shape.
4. Keep repeating this until the problem happens.

Nikolay Belyh said:
1. Open an exitings stencil that comes with Visio.
I picked the Basic flowchart.
2. Save this stencil under "My Shapes" so that it can be edited.
3. Pick a shape in the master stencil and edit this master shape to have
a
custom property in it. I picked "Rectangle".
4. Now drag this shape to a drawing. You should see the property in the
instanced shape.
5. Keep dragging the same shape from the stencil to the drawing and
eventually an instanced shape will be named "Sheet.#" instead of
"Rectangle.#".

Cannot confirm this.
Just out of curiosity, have tried this on Visio 2003 SP2 and Visio
2007.
Have dropped 34 (!) rectangles.
[Hello, lunar man, we came in peace (c) :) ]
All they are all called "Rectangle.#".

Try disabling all addons/extensions (including your's) and repeat this
fancy experiment... ;)

Kind regards, Nikolay
 
J

Jonathan Spane

I do that with the stencil but I think I may be out of the woods. Here is
what I do now.

I create a new stencil when I load in my custom XML file. This time however
I set the match master by name on drop checkbox instead of relying on the
GUIDs I guess. I am now updating the masters of the document to match the
same in terms properties to that of the stencil. After updating those
masters, I then update the instanced shapes of the document. Now when I drop
new shapes from the stencil to the document, Visio is just creating shapes
from the internal stencil of the document. Since I have updated thos
internal shapes, it is no problem. Now I get no conflicting shapes in the
document's internal master shapes which is what I think was happening.

I do not explicitly want to use that opening of master copy because I need
to control how the merging of properties and geometry happens to the
instanced shapes. I won't say this is completely fix but it seems to be much
more stable. Thanks for all the help...I know I will have more questions in
the future.


Regards
JP
David Parker said:
Just checking:
Are you updating Master shapes in code without using the master.Open
method?

Jonathan Spane said:
I think there may be a couple more steps.

1. At some point during the dropping, add some more properties to the
Master shape.
2. Delete all the dropped shapes on the drawing.
3. Start droppping this new updated stencil shape.
4. Keep repeating this until the problem happens.

Nikolay Belyh said:
1. Open an exitings stencil that comes with Visio.
I picked the Basic flowchart.
2. Save this stencil under "My Shapes" so that it can be edited.
3. Pick a shape in the master stencil and edit this master shape to
have a
custom property in it. I picked "Rectangle".
4. Now drag this shape to a drawing. You should see the property in the
instanced shape.
5. Keep dragging the same shape from the stencil to the drawing and
eventually an instanced shape will be named "Sheet.#" instead of
"Rectangle.#".

Cannot confirm this.
Just out of curiosity, have tried this on Visio 2003 SP2 and Visio
2007.
Have dropped 34 (!) rectangles.
[Hello, lunar man, we came in peace (c) :) ]
All they are all called "Rectangle.#".

Try disabling all addons/extensions (including your's) and repeat this
fancy experiment... ;)

Kind regards, Nikolay
 
J

Jonathan Spane

I now have the problem if the shape name stays but the geometry changes I
can't see to update geometry. Any instanced shapes revert back to the old
geomtry while the stencil the user drags from looks like the new geometry.

Is there a slick way given two visio shapes to set one shape's geometry
based on the other without deleting the shape?

Jonathan Spane said:
I do that with the stencil but I think I may be out of the woods. Here is
what I do now.

I create a new stencil when I load in my custom XML file. This time
however I set the match master by name on drop checkbox instead of relying
on the GUIDs I guess. I am now updating the masters of the document to
match the same in terms properties to that of the stencil. After updating
those masters, I then update the instanced shapes of the document. Now
when I drop new shapes from the stencil to the document, Visio is just
creating shapes from the internal stencil of the document. Since I have
updated thos internal shapes, it is no problem. Now I get no conflicting
shapes in the document's internal master shapes which is what I think was
happening.

I do not explicitly want to use that opening of master copy because I need
to control how the merging of properties and geometry happens to the
instanced shapes. I won't say this is completely fix but it seems to be
much more stable. Thanks for all the help...I know I will have more
questions in the future.


Regards
JP
David Parker said:
Just checking:
Are you updating Master shapes in code without using the master.Open
method?

Jonathan Spane said:
I think there may be a couple more steps.

1. At some point during the dropping, add some more properties to the
Master shape.
2. Delete all the dropped shapes on the drawing.
3. Start droppping this new updated stencil shape.
4. Keep repeating this until the problem happens.

1. Open an exitings stencil that comes with Visio.
I picked the Basic flowchart.
2. Save this stencil under "My Shapes" so that it can be edited.
3. Pick a shape in the master stencil and edit this master shape to
have a
custom property in it. I picked "Rectangle".
4. Now drag this shape to a drawing. You should see the property in
the
instanced shape.
5. Keep dragging the same shape from the stencil to the drawing and
eventually an instanced shape will be named "Sheet.#" instead of
"Rectangle.#".

Cannot confirm this.
Just out of curiosity, have tried this on Visio 2003 SP2 and Visio
2007.
Have dropped 34 (!) rectangles.
[Hello, lunar man, we came in peace (c) :) ]
All they are all called "Rectangle.#".

Try disabling all addons/extensions (including your's) and repeat this
fancy experiment... ;)

Kind regards, Nikolay
 

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