Cloned shapes with auto-updated text

Started by Garden Dwarf, September 22, 2023, 02:35:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Garden Dwarf

Hello,

I am building diagrams (multiple Visio files, and multiple tabs in each Visio file).
On each diagram I want that the text of multiple shapes to refer a single text which is available in a dedicated shape on the same page.

For instance:

  • I have a box A displaying the reference text (I set the shape name to "reference").
  • I have a box B and I want the label to be automatically set to the same label as box A.
    So in the ShapeSheet I set the Text Fields [Value] to: =SHAPETEXT(reference!TheText)
  • I then clone the box B 5 times with drag/paste (using Ctrl+LeftMousebutton).

This is working fine, unless - by mistake - I copy/paste the box B (Ctrl-C+Ctrl-V) instead of drag/paste.
By doing this, the reference to the box A in the formula disappears and the text is not dynamically updated anymore.
This happen either when copy/pasting inside the same diagram or between different diagrams (pages or Visio files, whatever).
I tried to protect the formula with GUARD(), but this hasn't changed the behavior.

Is there a way to prevent this, at least for copy/paste inside the same diagram (ideally, this behavior is fine when copy/pasting outside of the actual page)?

Thank you in advance :)

Nikolay

You can try this trick:

- create a user-defined cell in the PAGE (or in the document).
- Set its value to your reference, like Page1.User.Row_1 =SHAPETEXT(Sheet.1!TheText) // assuming the reference ("A-type") shape has ID=1
- In the "B-type" shape, refer to this page/document cell, like: =ThePage!User.Row_1

wapperdude

This is very similar to an earlier post: http://visguy.com/vgforum/index.php?topic=10144.msg46935#msg46935

There is reference to video by David Parker that illustrates, basically, what Nickolay, has suggested.  Nikolay takes it one step further and puts the info in the shapesheet of the 1st page.  https://www.youtube.com/watch?v=toweOQWHSCI

Visio 2019 Pro

wapperdude

#3
Did more investigating.  Turns out, I believe there is a bug at work here.

Scenario:  cloned shape on same page.
>>  if the clone references the reference shape directly, i.e., using field insert formulas such as SHAPETEXT(reference!TheText) or SHAPETEXT(Sheet.1!TheText) => both work using duplicating <cntl>+D, or <cntl>+left mouse.  But copy/paste <cntl>+C / <cntl>+V FAIL  This is the bug!!!

>>  if the clone references the page shapesheet, as Nikolay indicates, then all is well.

Scenario:  cloned shape on a different page than reference shape
>>  the above formulas fail because there is no off-page reference.  The formula must be Pages[Page-1]!SHAPETEXT(Sheet.1!TheText) in the case of direct shape referencing.  Or, must be appended to the beginning of the forumula presented in the Nikolay case.  For either of these, the editing must be performed on an off-page.  It cannot be done on the page containing the reference.

There are two things to note: 
a) this shape may be copied to page-1 and still work.  The copied shape may be re-copied to other pages and still work. 
b) with off-page formulas, Visio does not like using named shapes.  So "reference!" will not work.

See attached.  The light gray shapes were copy/paste of dark gray.  Both have direct shape references and fail.  The Yellow is the Nikolay case, but no off-page capability.  The magenta is direct shape reference but includes off-page reference.  Creating of the magenta shape must be performed on an off-page.  Then, that shape may be copied/re-copied anywhere.
Visio 2019 Pro

wapperdude

#4
Updated the file to be bit more explanatory and have 1 more case illustrated.

Also, here's link to cell referencing formula syntax:  https://learn.microsoft.com/en-us/office/client-developer/visio/about-cell-references
Visio 2019 Pro

Garden Dwarf

Thank you for the answers.
It is quite more complex than what I thought.
I will play a bit with the suggested options now :)

wapperdude

#6
Anti-acid to help digest...   
The take-aways
1) there is a copy/paste bug when 1 shape (the clone) directly references another shape
2) if the clone is on a different page, then you must tell it where to find the reference shape.  You do this @ the location of clone.  Do it just once, because it can then be successfully copy/pasted anywhere.
3) alternatively, place the info in a page's shapesheet.  Doing so allows copy/paste.  But, Visio will still need to know where to find for off-line clones.  See (2).
4) using named sheets, in general, should be avoided.  Sometimes Visio rejects namedshape.  Also if shape is re-named, then the local vs universal names get out of sync, leading to identity crisis....counseling needed. 
      > https://learn.microsoft.com/en-us/office/vba/api/visio.shape.nameu
      => rule of thumb:  avoid naming shapes

Visio 2019 Pro

wapperdude

One more thought, when did this issue of copy/paste of a clone shape start having issues.  Was it with V2010?  V2007...I think not!?!  , or more recent.

I believe all you need to do is copy the Rev4 version of my test file, and try changing either the text or the width of the reference shape.  If copy/paste works, then I think all of the gray shapes should respond properly.  Shouldn't have to do anything else.

Just curious.
Visio 2019 Pro

Garden Dwarf

Well, I just checked and it says "Microsoft Visio Plan 2 MSO (Version 2302 Build 16.0.16130.20754) 64 bit".
I am using Visio since years, but this kind of feature is a new experience for me.