Inserting a geometry section and losing master/shape relationship issue.

Started by Gustavo, June 09, 2018, 04:29:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Gustavo

Hello all. I have this big number of shapes, all of them instances of the same master. The master, and their instances have a big number of shape data rows, some of them linked to external data. When I tried to add another geometry to the master, this new geometry change didn't propagete to the shape instances, so I tried to add the aditional  geometry by code, here it is:

Sub Añadirgeom_y_action()

Dim sel As Visio.Selection
Set sel = Visio.ActiveWindow.Selection

Dim shp As Visio.Shape
On Error Resume Next
For Each shp In sel

    shp.addsection visSectionFirstComponent + 1 ' Añadir geometria 2
    shp.AddRow visSectionFirstComponent + 1, visRowComponent, visTagComponent
    shp.AddRow visSectionFirstComponent + 1, visRowVertex, visTagLineTo
    shp.AddRow visSectionFirstComponent + 1, visRowVertex, visTagMoveTo
    shp.CellsSRC(11, 0, 0).FormulaForceU = "FALSE"
    shp.CellsSRC(11, 0, 1).FormulaForceU = "FALSE"
    shp.CellsSRC(11, 0, 2).FormulaForceU = "User.ventdatos"
    shp.CellsSRC(11, 0, 3).FormulaForceU = "FALSE"
    shp.CellsSRC(11, 0, 5).FormulaForceU = "FALSE"
    shp.CellsSRC(11, 1, 0).FormulaU = "0"
    shp.CellsSRC(11, 1, 1).FormulaU = "0"
    shp.CellsSRC(11, 2, 0).FormulaU = "0"
    shp.CellsSRC(11, 2, 1).FormulaU = "0"
    shp.RowType(visSectionFirstComponent + 1, 1) = visTagMoveTo
    shp.CellsSRC(visSectionFirstComponent + 1, 1, 0).FormulaU = "Width*1.2"
    shp.CellsSRC(visSectionFirstComponent + 1, 1, 1).FormulaU = "Height*1.2"
    shp.RowType(visSectionFirstComponent + 1, 2) = visTagLineTo
    shp.CellsSRC(visSectionFirstComponent + 1, 2, 0).FormulaU = "Width*1.2+5 cm"
    shp.CellsSRC(visSectionFirstComponent + 1, 2, 1).FormulaU = "Height*1.2"
    shp.AddRow visSectionFirstComponent + 1, 3, visTagLineTo
    shp.CellsSRC(11, 3, 0).FormulaU = "Geometry2.X2"
    shp.CellsSRC(11, 3, 1).FormulaU = "Height*1.2+4cm"

    shp.AddRow visSectionFirstComponent + 1, 4, visTagLineTo
    shp.CellsSRC(11, 4, 0).FormulaU = "Geometry2.X1"
    shp.CellsSRC(11, 4, 1).FormulaU = "Geometry2.Y3"

    shp.AddRow visSectionFirstComponent + 1, 5, visTagLineTo
    shp.CellsSRC(11, 5, 0).FormulaU = "Geometry2.X1"
    shp.CellsSRC(11, 5, 1).FormulaU = "Geometry2.Y1"

    shp.AddRow visSectionFirstComponent + 1, 6, visTagLineTo
    shp.CellsSRC(11, 6, 0).FormulaU = "Width*0.7"
    shp.CellsSRC(11, 6, 1).FormulaU = "Height*0.7"

    shp.Cells("User.ventdatos").Formula = "FALSE"

Next shp
End Sub


the thing is that, when I run the subroutine on the shapes, they lose their relationship with the master shape, and I need to keep it. This is odd, because if I add a geometry in the shapesheet, the shape keeps its relationship with the master. Do you have any idea why this is happening? any workaround?

Best regards

Surrogate

You are right! When you change something in instance, it lose relationship.

All instances have inheritance, please open master in document stencil and add geometry there one time. After you change master and update it, all instances (copy of this master) in all pages must update also!

wapperdude

Adding to Surrogate's comment...

The key is the Document Stencil.  When you drag and drop a shape from a stencil, onto a drawing page, Visio places a copy of it on the Document stencil.  This, in effect, becomes the "Document" master.  A main advantage, when you share a Visio document, you don't have to include each and every stencil you used....unless you have code in the stencil and need to share that too.

As long as nothing is altered at the page level, you can edit the doc stencil shape and apply changes to the entire doc.  If, however, some of the shapes on a page were altered, e.g., fill color, these shapes will no longer respond to the doc stencil shape, as they are uniquely different from it.

Now, let's say you later change the master in the stencil.  The doc doesn't see the change.  That only happens when you drag the shape onto a drawing page or doc stencil.  BUT, this altered master will be given a new name in the document as there is already a copy of the original shape in use.  Visio won't overwrite.  Rather, you get masterwhatever.2. 

So, propagating changes gets to be a bit tricky.  If you want to truly propagate the updated master and overwrite any incidental changes already done at the individual shape level, then, you have to either:
1) write code...may be some examples in the forum.
2) I think Paul Herber's Super Utilities has a replace functionality
3) the more recent Visio releases might have shape replacement function...don't recall if this is true.

HTH
Wapperdude
Visio 2019 Pro

Gustavo

but, why when only when I bulk modify the instances by code is when the instance lose its relationship to the master, and not when I modify it one by one?

vojo

3 shapes off 1 master
Modify 1...new master added to doc stencil
modify 2...another new master added to doc stencil
etc

3 shapes off 1 master
Modify master...all 3 shapes updated