BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Quantum Entanglement for Visio Shapes

Started by Hey Ken, October 31, 2018, 01:25:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hey Ken


   The question of sharing data between shapes has come up many times, such as two shapes sharing the same text.  But what about going beyond text?  Take wireframes, for example.  You often need to duplicate the same shape with the same text on multiple pages so that if you changed the text of one, the text of the others would follow suit.  But there's also a need for a shape to always be at the same location on multiple pages such that if you moved any one, the others would also move; and if you changed the size of any of them, the change would be reflected in the others.  The same is true for many other attributes as well.  SETATREF certainly does the trick – unless you clobber or delete the shape that's the source of the value!  Because then all the shapes that SETATREFed to the deleted shape would be left adrift and unconnected.  And that's Bad.

   The inspiration for a solution came from quantum mechanics, of all things, specifically quantum entanglement where a change of state in one particle is reflected instantaneously in another particle, irrespective of distance.  As it turns out, the same principles can be applied to the Visio world.  I call the solution Quantum Entanglement for Visio Shapes, or simply Entanglement.  It's a 100% shapesheet solution, but it's easier to set up and maintain via VBA. 

   Entanglement involves three steps:

   1. The fundamental basis for the solution is to create some sort of unique identifier to define the entanglement.  Call it an "Entanglement ID."  Once you have it, you can entangle a variety of attributes among any number of shapes on any number of pages.  You can either create your own Entanglement ID manually, or use the UniqueID that every shape and page has.  To my knowledge, you can only access the Visio-supplied UniqueID via VBA.  Here's the function to get the ID:

Public Function EntanglementGuid(TheShape as Shape) As String

EntanglementGuid = TheShape.UniqueID(visGetOrMakeGUID)
EntanglementGuid = Replace(EntanglementGuid, "{", "")
EntanglementGuid = Replace(EntanglementGuid, "}", "")
EntanglementGuid = Replace(EntanglementGuid, "-", "_")

End Function

   The editing of the Entanglement guid is necessary, as will be seen below. 

   Regardless of the source of the Entanglement ID, whether manually-entered or UniqueID, it gets saved in the entangled shape's shapesheet's User section as the value of a cell named User.Guid.  If the cell exists, the shape can be entangled; if not, then not.  Two or more entangled shapes all share the same Entanglement ID regardless of whose UniqueID it may happen to be.

   2.  To entangle a particular cell of a shape or page, the actual desired value is stored in the User section of the document's shapesheet.  The name of that user cell is a concatenation of the name of the cell being entangled (such as PinX, Height, etc.) plus the Entanglement ID, making a cell name such as "User.PinX_E7EA5991_D4FF_4AEF_84A6_D84F1ED9A59A".   Call it the "Entangled Cell Name."  (Note that the braces and dashes have been removed from the Visio UniqueID because they are not allowed to be used in a User cell name.)

   3.  In the entangled shape's shapesheet, simply reference the document's shapesheet cell value using the SETATREF function as follows:


   That's it.  Any time the value of the entangled cell changes in the shape, it's the value in the document's spreadsheet that changes, and all other entangled shapes share in the changed value.  Even better, you can delete the original shape and not affect any of the other shapes entangled with it.  Best of all, it's a 100% shapesheet solution that's easy to set up.  And unentangling a shape is trivial: just overtype the SETATREF with whatever unentangled value you like.  If you want to re-entangle it, you still have the Entangle ID in the source or target shape's User section as a reference.

   One drawback to Visio Entanglement is that it relies on SETATREF, meaning it's limited only to certain shapesheet cells, and the most-common negative impact is seen with a shape's User cells.  SETATREF does not work with User section cells.  Fortunately, user cells can be entangled in the same manner as any other, except that any reference to that User cell name throughout the shapesheet must be replaced with the document's Entangled Cell Name.  That change can be done manually, or a short VBA loop can be written using the CellsSRC function to scan the shapesheet sections and replace the original User cell name with the document's Entangled Cell Name.

   Another drawback is with a shape's text.  Entangling text requires using the Text Fields shapesheet section, which is one that does not work with SETATREF.  Here only VBA can help, specifically by adding an Actions row to trigger a macro to prompt for the new text, which the macro then stores in the document's shapesheet's entangled cell.  Multiple Text Fields rows become problematic, but can still be entangled by using one document shapesheet row per Text Fields row.

   Taking it all a step further, a form can be created to allow for turning on and off individual entanglements such that they entangle a shape's position only, a shape's size only, the text only, or any combination.  Mix and match!  (See sample form below.)

   One annoyance is that too many entangled shapes tend to clog up the document's shapesheet visually, and performance issues can start to set in when thousands of rows are used.  But then, how often does one look at the document's shapesheet, or entangle thousands of shapes?  Besides me, that is?

   I can' t tell you how much time and trouble entangled shapes have eliminated for me, especially with creating wireframes where buttons and checkboxes need to be at the same location with the same topology on multiple pages.  Entanglement has been a life saver.  You can call me lazy, but as we all know: when it comes to most anything, laziness is a virtue.

   - Ken

Ken V. Krawchuk
No Dogs on Mars - A Starship Story

Paul Herber

This looks wonderful. I'll have a good look at it next week.
Electronic and Electrical engineering, business and software stencils for Visio -


Perhaps I'm missing the point.  But, why not create a master shape, that writes its value to TheDoc!User.whatever, using setatref?  That way, copies of that shape will reference the same User.whatever.  Add / subtract as desired.

Attached is a corner rounding example.  Select any shape...perhaps that's the issue??? only want a single parent?...and then use the GUI to set the rounding.  In addition, I setup a shape data entry to allow direct entry instead of GUI interface.

Note:  when placing shape on a stencil, the formula containing The Doc reference gets clobbered.  A work-around is to place the desired formula in the EventXFMod cell, and let setf/getref push the formula into the rounding cell on drop.

The caveat is that the TheDoc shapesheet has to be setup ahead of time to have all of the needed references.  Ah!  Maybe that's the point.

I think "TEXT" requires a dumby placeholder so there is a TextField section and a text holding cell.

For what it's worth the attachment.


Visio 2019 Pro


In the same vain, here's an older file that did some text cloning.  It's setup such that you can either write text to the document or to Page-1.  The shapes may be toggled thru the Action menu (top entry) to use either source of text.  Again, there is no "parent" shape.  Any shape can be used to modify the text.

Visio 2019 Pro

Hey Ken

Mr. Dude:

   Thanks for the comments and suggestions.  Here're some in return...

   The reason why you can't create a master shape that writes a value to TheDoc!User.whatever is because Visio does not allow it.  The TheDoc field has to exist in advance.  To get around it in the past, I've added a SETF to the EventDrop cell to automagically create what I needed.  Also, if you added entanglement stuff to the master, that assumes you want to always entangle that shape when only a tiny percentage of shapes need entanglement.  And setting up the document in advance means you have to set up the document in advance.  Too much work!  And what of the unschooled user?  Now you're talking templates, which means it's not easily retrofittable for existing documents.  (Absent a Supershape, of course; but that's a topic for a future post.)

   Pardon me for quibbling, but shape data entry is a GUI interface.  Six of one, six of the other.  And using a form means fewer clicks—a very important consideration!  More like six of one, three of the other.  ;- )

   The text holding cell you refer to should be TheDoc!User.TextHoldingCell. IMO.  Why have two?

   On your first example, why did you add the SETATREFEVAL and SETATREFEXPR?  It works fine without them.

   Not sure I understand your goal for the second example.  How do I change the text?  Editing the shapesheet does nothing.  Seems much less trouble to put a TheDoc! reference in the Text Fields section, set LockTextEdit, and change the text via an Action row macro, which is how I approach it.

   I also don't understand why you have the SETATREFs in the shape's User section – SETATREF does not work in User cells.  Doesn't matter – it appears you don't reference them anyhow.

   Thanks again for the comments, as always.

   - Ken

Ken V. Krawchuk
No Dogs on Mars - A Starship Story


I guess I missing something:
- so each shape, separately has read back the entanglement value from the doc
    - read back to actually use it.
         - might be simpler to hard code say 8 entanglement cells at doc, user tells the shape which to use.
         - can still use UUI format if you want.
    - probably need a DEPENDSON to catch it reliably
- so what happens if you want 2 or more engaglement domains in a given page
    - doing this at a doc level greatly simplifies the intelligence but forces user to have an unique drawing file for each
      entanglement domain
    - so how does a given shape pick up the right entanglement cell in the doc.
           - I think you would have to predefine something like 4-8 entanglement domain cells at doc level
                  - use docmd on the shape to identify which entanglement domain to use...the let setatref doo its magic.
- so assume all this worked out, is the goal something like passing text or numbers to all shapes in a domain (2 or more)?
    - if so, would need to either go shape to shape (cells in the shape, 2 shapes in an entanglement,
      common entanglement handle, etc)
    - or cells in the doc layer, some "mailbox" cells (who gets to write?, do you need a write semaphore to identify who owns
      write token?, etc)

I messed around with something like this i.e.  "shape awareness for visio or DHCP for visio shapes"   
It became overly complex to do in shapesheet and still be usuable.

right or wrong, my experience trying to do similar is that you are off to a good start, but now comes the hard work.


Hi Ken...

WRT to the 2nd, or "text" example, text entry is via shape data.  That is, "data" entry is only a double click away.

The doc shapesheet has no Text Field section.  Either, User or Data sections are available.  But, anything in doc shapesheet needs either pre-config or code to make relevant "reception" cells.

To avoid that, using Vojo's terminology, you need a DHCP network.  Hence your initial steps.  But, at some point, somewhere, somehow decisions have to be made to limit accessibility, what info can be shared.  There needs to be some "intelligence" at some point.  Seems there's only two fundamental choices: 1) an universal environment where all possible info is available and each member has built-in restrictions that limit access to what's relevant.  Or, each member has universal access with some "master" deciding whom gets appropriate info.  I agree with Vojo, this is a very complex endeavor.

Visio 2019 Pro

Hey Ken


   Thanks for the observations, but my apologies; I don't follow you all.  I'm wondering why you think you need a DEPENDSON or DOCMD.  What do you mean by "entanglement domain" and DHCP?  Why hard-code anything?  The TheDoc!entanglements are defined via macro as you entangle each shape.  Everybody gets to write to all the entangled attributes, and by extension to all the entangled shapes.

   No hard work here.  Three simple steps, as mentioned above.  Took a few hours total to code, already saved far more than that when it came to the mindless tedium of adjusting shape locations every time something moved or changed.


   Thanks to you too! 

   Sorry, can't use a doubleclick, as it's often used for other things (such as in the attached demo).

   Sorry if I was unclear about the TextFields section.  It is, of course, on the shape.  That's where you add your reference to "TheDoc!User.TheText_<your guid here>".  The EditText macro changes that cell's value.

   Again, not sure what you mean by a DHCP network, or why you'd need one.  Not sure why you'd want to limit accessibility – that's the whole point of entanglement, to be able to access all the entangled attributes from any of the entangled shapes anywhere.  There is no master.  All share equally.  If you don't want something entangled, don't.

   Also again, not a complex endeavor at all.  To quote Madge from an old TV soap commercial, "You're soaking in it."  See the attached demo (.vsd format, just for you).

   The demo was built using the entanglement form I showed above, plus, of course, the macros behind it.  In the demo, all the boxes are entangled for text, size, location on the page, text attributes (bold, italic, etc.), line formatting, and fill.  Change any of those, and all the other entangled shapes follow suit.  To change the text, right click on it and choose Edit Text.  Those boxes that aren't entangled say they're not entangled.  All lines are not (yet) entangled.  The box that says Do Not Click is entangled with its Click Me clones, except not for text or text attributes.

   Play around with it, look under the hood, whatever.  For convenience, I added two navigation buttons at the top right to allow easier back-and-forth access.  Any questions, let me know.

   - Ken

Ken V. Krawchuk
No Dogs on Mars - A Starship Story


I'm gone for extened weekend.  Won't be able to look at this until after that.
QuoteIf you don't want something entangled, don't.

So, there is some intelligence involved...the user.  But, there must be some hooks, more intelligence, as there would be different entanglements...Hence, some implied restrictions.   Again, can't look at this now.


Visio 2019 Pro


First,   1 single entanglement domain per document (all shapes share the handle at the document level) is pretty useless
           You already have that by the shear fact you have a document so why bother creating a rube Goldberg solution for
           same thing.

Second, even if there some obscure reason for the rube Goldberg entanglement, what do you want to do with it?
            I suspect you want to pass information between shapes dynamically (not apriori design text I.e child data in a group)
            so that raises questions
                - how shape 1 find shape 2 vs shape 3?
                - what information would you want to pass
                      -Fixed text define when shape created 6 months ago (not really useful or so comprehensive it is
                       becomes unusable because there is 5,384,292 pre set messages defined 6 months ago)
                      - or
                      - some dynamic text user created 10 minutes ago
                - Assuming dynamic (otherwise, again what is the point), then how would user get the dynamic text into the system
                - etc
Dependson will force ALL cells to reevaluate so that shape 2 and shape 3 would check "incoming traffic"....shape 3 ignore
(there are situations where one shape changes but the "listening shape" is not triggered for cell evaluation)
(that is why the function was created by MS!!!)   I suspect something like this entanglement may not trigger all shapes

Docmd would launch the GUI to enter in dynamic text (BTW, MS was crazy to stop supporting at top level since
now inconsistent usage between shape at the top level of the page vs every other shape below that
(I.e. group has to be by shape data, while child shapes can be either....I guess MS gets paid by the number of clicks it
takes to do anything useful ;-)  )

Perhaps I am being harsh, but I really don't see the value of this if its
A) 1 single entanglement for entire document
B) not sharing any sort of dynamic information between shapes

maybe a detailed example of what you are trying to accomplish


Hi Ken,
I think this is a very good and useful function.
My Sharem Tool does a similar job, but without using the doc's shapesheet and it can't entangle shapes over different pages.
I had also a try using absolute shape IDs, but this is definitely nothing you can copy and paste over pages or documents.
So, for me ... definitely a thumbs up!

Hey Ken


   I'm guessing you and I do different things with Visio, because I find entanglement far from useless.  I use it primarily for two functions:

    1) Active wireframing.  I do an awful lot of this, and it's reached the point where I have active dropdowns, checkboxes, and other active elements.  Before you say "Hey, Visio can do all that!", let me mention that most people do not have Visio, so I distribute my wireframes as PDFs.  About 5 years ago, I posted the details of how I build wireframes, but it's gotten much easier with entanglement.  For example, one wireframe can span multiple pages, such as one page where a dropdown has dropped down and another where it hasn't, and all the elements of the wireframe are duplicated on two pages.  If an element changes (such as getting larger, changing color, different text, etc.) you need to make the change on multiple pages.  With entanglement, if you change it on one page, all the others change with it.

    2) Business architecture drilldowns.  I do an awful lot of this, too.  The sample .vsd I posted above is a crude version of one.  The way I use them, you start with one icon that represents the entire system in question.  Click on it, and it expands to show all the systems that it touches.  Click on it again, and it shows what data passes between each one.  Click on it again, and it expands to show the entire neighborhood of systems that feed the systems that feed the original system in question.  Attached is a sanitized JPEG of one of the neighborhood pages.  That started as a page with a single box.  Clicking on it repeatedly lets you drill down deeper and deeper, and more and more of the other shapes appear until you have that entire, crowded neighborhood picture attached below.  Now imagine that you need to cram one more box into the neighborhood picture.  Not only do you have to push things aside on the bottom level, you also need to correspondingly push things aside on all the higher-level pictures as well.  A big pain in the butt!  But if the boxes are entangled, changing the location or text on any one level automatically changes all the others.

   To address some of your other points, let me add:

  • I'm not so much passing info between shapes, but rather sharing certain attributes on their shapesheets.
  • Shape 1 does not "find" Shape 2.  Shape 1 exists, and the entanglement form creates a clone of it on a page of your choosing.  That's when all the entanglement occurs.  And you can always cut and paste an entangled shape and the entanglement travels with it.
  • Not sure what you mean in your "5,384,292 pre set messages" example.  But if you wanted to share them, they can be entangled too.  The sample .vsd attached above allows you to change the text as needed.
  • I see why you mention DEPENDSON now.  But what do the shapes listen to?  One "master" shape?  What if that shape gets deleted?  You can listen to TheDoc!User.Whatever, but that's what I'm already doing, except it's a direct reference rather than a triggered reference.  Either way would work, but they'd both require a similar setup to what I already do with my approach to entanglement.  But maybe DEPENDSON can be used as an alternative for the cells that SETATREF can't do?  Hmmm... Have to try that.
  • Not sure why you'd think entanglement would not change all shapes every time.  It's a direct reference to TheDoc!User.Whatever on the shapesheet.  What's not to work?
  • As the sample .vsd attached above shows, you can have more than one entanglement per shape, and multiple entangled shapes per page or per document.
   Regardless of the usefulness of entangled shapes for you, I find them immense timesavers.  They work flawlessly.  And I have my form set up that I can add or remove entanglements at will because the form is pre-populated based on the shape's User.Guid.Value.  You'll see in the sample .vsd that it holds a delimited list of all the entangled attributes.  I parse that to populate the form.

   Thanks for the comments, Vojo!


   That SHAREM is pretty impressive.  It does FAR much more than my simple entanglements.

   Regarding absolute shape IDs copied between documents, you got me wondering: How unique are the shape UniqueIDs?  If I cut and pasted an entangled shape from Document A into Document B, would Document B already be using that UniqueID?  Apparently not.  I found this article that explains how Microsoft builds guids.  Looks like it's truly unique.

   - Ken

P.S.  Here it is, a mere 21 hours away from the polls opening.  You'd think I'd have better things to do than discuss arcane Visio stuff!  But then one of my planks is to create a complete business architecture of how the state government works.  Of course that'll be done using Visio and entangled shapes, so I guess there's some connection.

Ken V. Krawchuk
No Dogs on Mars - A Starship Story

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 401 (show)
Files included: 38 - 1676KB. (show)
Memory used: 1315KB.
Tokens: post-login.
Cache hits: 17: 0.00160s for 26,766 bytes (show)
Cache misses: 6: (show)
Queries used: 16.

[Show Queries]