Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: Soundstorm on August 05, 2022, 01:32:23 PM

Title: Set text on EventDrop
Post by: Soundstorm on August 05, 2022, 01:32:23 PM
Hi

As I'm working on making a complete template for all our flow diagrams, I find a lot of cool things I can do with Visio, but I also seem to stumble upon some issues.

I have a shape for a valve. I want a piece of text next to it with a tag number. The shapes we used before had the automatic numbering thing included in Visio, but we have now decides on using a different numbering scheme. That scheme requires manual input of the tag number. So I included "V-xxxx" in the master shape. If you select the shape, you start typing and you can change the tag number to whatever you want. This is great and exactly what we want.

Now if we would copy/paste this shape, it would also copy the tag number. The chance of duplicates becomes high, because you have to pay attention when pasting shapes, especially when pasting large groups of shapes.

So my idea was to add a function in the EventDrop to set the text value back to "V-xxxx". But I'm running into some issues.
I know you can get the text value into the Shapesheet. I also know you can use fields to input text from within the Shapesheet.
But the field sections disappear once you start typing your own tag number, so all the formulas get lost or lose their references.

I was thinking of placing a function to rewrite everything in the TheText event, but that doesn't work either.

Any tips on how to proceed with this?

Thanks!
Title: Re: Set text on EventDrop
Post by: wapperdude on August 05, 2022, 02:14:51 PM
It's been awhile since I posted this, but it might give you some hints:  Of Field Insert Text: with / without VBA (//http://Of%20Field%20Insert%20Text:%20with%20/%20without%20VBA)

Basically, what comes to mind id:
1) create a Shapedata entry for the tag number.  This will be the only means that a user can make an entry.
2) lock the text from editting. 
3) use the field insert to display the Shapedata entry.
4) on drop, it might be possible to clear the data entry.
5) set the DblClick event cell to Docmd(1312).  This will invoke the Shapedata window and prompt for tag number.

There are variations to this approach. 
Title: Re: Set text on EventDrop
Post by: Paul Herber on August 05, 2022, 03:27:12 PM
Visio has a built-in addon that handles all the processing for P&ID shapes, including keeping track of and setting the shape IDs in the text.
Title: Re: Set text on EventDrop
Post by: Surrogate on August 05, 2022, 03:40:11 PM
Quote from: Paul Herber on August 05, 2022, 03:27:12 PM
Visio has a built-in addon that handles all the processing for P&ID shapes, including keeping track of and setting the shape IDs in the text.
This add on named Number Shapes(https://ieda8485.files.wordpress.com/2010/05/general-shape-numbering.jpg)
Title: Re: Set text on EventDrop
Post by: Paul Herber on August 05, 2022, 03:55:33 PM
No, it's called PESolution.
Title: Re: Set text on EventDrop
Post by: Surrogate on August 05, 2022, 06:47:44 PM
Quote from: Paul Herber on August 05, 2022, 03:55:33 PM
No, it's called PESolution.
Never met it. Find list of add-ons in this ancient thread (https://social.technet.microsoft.com/Forums/en-US/9409a6c3-586e-42e1-8116-d3d04c05206b/share-data-rack-and-quotserversquot-in-it-get-quotstuckquot-and-i-cant-pull-them-out?forum=visiogeneral)  ;D
Title: Re: Set text on EventDrop
Post by: wapperdude on August 05, 2022, 07:04:31 PM
Not sure these addins provide the desired solution.  The "undertood" need is:
1) custom, "arbitrary" numbers.
2) numbers are not linked to their sequential placement on drawing page, thus not automatically created.  Manual is OK, but...
3) existing number must be reset in a copy/paste scenario.  No duplicates!!!
Title: Re: Set text on EventDrop
Post by: vojo on August 06, 2022, 02:14:06 PM
for 1 and 2 and 3

user.unique_id = rand() + ID()    // I believe would make the number WW unique...you can replace with desired number
                                        // also since ID is the sheet.<ID>, copy and paste would make number different for new shape
                                        // if you manually update number, then would need to update manually after copy paste

could also do
user.id = id()
user.hdr = "<some header text>"   // can put in props.cell to use GUI ==> trigger to edit would be DOCMD(1312).
user.wholeID = concat(user.hdr, user.id)

use user.wholeID for whatever you want

Title: Re: Set text on EventDrop
Post by: wapperdude on August 06, 2022, 04:08:56 PM
I didn't intend to put words in the ops mouth, but it does seem I may have inadvertently created confusuion. 
@Vojo:  the numbers in (1) are not shape IDs.  As I interpret, these might be product numbers.   Thus, they are not random numbers.   In (2), the user does manually enter the number.  In (3), the user is allowed to copy/paste.  Then, the previously entered number of the copy must be edited.  No duplicate numbers.  So, (3) would reset this value upon drop/paste, forcing the user to edit/update the value.

It's not that complicated.  The OP just wants the reset to work on drop.
Title: Re: Set text on EventDrop
Post by: vojo on August 06, 2022, 09:41:25 PM
ZZZZZZZZ... thanks for playing!!!

check the shapesheet function ID() in all the docs

basically, a shape name is sheet<sheet number>.<id number>

sheet1.1 = is first shape droppe.....id() = 1
sheet1.9876 = the 9,876 shape dropped....id() = 9876
Title: Re: Set text on EventDrop
Post by: Yacine on August 07, 2022, 08:26:21 AM
I'm very late to join, but I may drop my 2 cents too.

There are two aspects to this post. The exact answer to OP's question and the elaboration on his real needs.

Getting just a unique number as Vojo suggests would work to answer the question. But this is not how PFDs work. (1) It's the whole tag, that needs to be unique and (2) you don't want to have weird numbers completely separated from any sorting order.

The tag can be something short, like V-xxx for valves or P-xxx for pumps.
But more often you - actually the electricians and the programmers - will want to subdivide the drawing into functional groups. So you'll add a code in front the "part type" and "number" to get something like 815-V-13.

And if the equipment gets bigger (several machines = several electrical cabinets) and bigger (several lines) you can end up with:
  location code / line code / machine or cabinet code / function code / part code / number.

The PESolution that Paul suggested does already answer OP's question. It has a "renumbering" function that will eliminate duplicates.
It includes also some features to change the tagging category, etc.

Unfortunately it lacks the long tagging option. This long prefix could be written as "dumb" text in a corner of the drawing to allocate all the shapes to this one group.

My advice would be:
- if you draw PFDs only occasionaly stick with PESolution.
- if you want to get serious with tagging write your own code! I can provide some support if needed.

Resources - You may want to have a look at the following norms
- EN 81346
- EN 62424
- ISA 5.1 (https://vdocuments.net/isa-51.html (https://vdocuments.net/isa-51.html))







Some additional thoughts about a custom implementation.


- When renumbering, collect first all the prefixes - every thing that's in front of the number, then do the actual renumbering for each prefix.
- Think of improving the readability for instance by sorting the shapes by columns (ranges of x coordinates) and rows (y coordinates). So knowing your number you can visually find the shape much faster.
- When preparing the prefixes, think about grouping some. eg: say you have different valve types with different drives VP (pneumatical v.), VE (electrical), VM (manual). But to avoid renumbering when you want to change a drive, you would better number over all Vx - regardless of the drive type. Or in other words, don't number of sub-groups.
- The actual tagging - assigning values to different grouping fields - is only indirectly connected to the displayed text. When the tags get too long (over 7-8 characters), you'll want to de-clutter the drawing by surrounding shapes of a same group by a frame displaying the group's text. The shapes themselves would only display the last part of the tag. Thus the setting of the text displayed needs to be easily adjustable.
- When adding new numbers, consider if you want to use the gaps the numbering or only append to current numbering.
- You may also consider a differentiation between standard parts and project specific ones. e.g.: new parts start from 100.
- When renumbering you may think about preserving already existing sorting orders. Think about changes made in project in progress. Don't modify already allocated tags, unless there is very important reason for it and you documented it properly!!!


You see the list of considerations is quite big and it's only the ones I put up in 10 minutes.
Title: Re: Set text on EventDrop
Post by: Soundstorm on August 08, 2022, 07:10:31 AM
Wow, that's a lot of replies and insights! I didn't have time over the weekend to look into this, but I did think about a solution.

I'll elaborate the issue I have first:

We are building test skids that are used in a University laboratory. These things are 'living entities', so they get changed a lot.
Up to last year, we have always been using the built in Visio numbering mechanism, where a valve would be V-xxx, and the number just keeps incrementing. This becomes really difficult once you start adding V-209 right after V-035 on page 2, and on page 5 there is V-208 and V-210. Sometimes Visio also manages to duplicate numbers, and you have to go look for those manually. At that point, you can't use the renumber function anymore, because there are valves in the field tags attached.

We now came up with a numbering solution that should work properly:
XX-ABC
Where XX is the device type, A is the section of the setup (1 digit), B the subsection (2 digits) and C is the unique identifier.
By doing this, we get the benefit that we might have a tank, with heating, pressure measurement, level measurement,... Those would all have the same tag number, making it more easy to organise all documentation and identifying on the diagram.

So adding a tag number will be a manual action for sure. You can't link to any shape ID, because that wouldn't help at all. I also want it to be clear that the tag number hasn't been given yet, so a newly dropped or copied shape should always have XXXX.
You can instruct to always drop from the stencils (so you don't copy the tag numbers), but sometimes you have made an assembly of shapes that need to be duplicated. And at that point, you would duplicate the tag number.

So wapperdude his summary is correct
Quote from: wapperdude on August 05, 2022, 07:04:31 PM
Not sure these addins provide the desired solution.  The "undertood" need is:
1) custom, "arbitrary" numbers.
2) numbers are not linked to their sequential placement on drawing page, thus not automatically created.  Manual is OK, but...
3) existing number must be reset in a copy/paste scenario.  No duplicates!!!

Having the tag number in the shape data would indeed give more solutions. But the ease of workflow when just have to select a shape, and start typing is something we need. There is of course shape data to be filled in (part numbers etc), but that is mostly at a later stage.

The solution I have in mind, and will give a try today is the following:
- Add a text shape to the group, this shows text from a user field
- Hide the text of the shape
- Add a function the event TheText to update the user field to whatever that was entered
- Add a function to the event EventDrop to set the user field to V-xxxx

I may add a menu item to restore an old tag number, in case you did a cut/paste action. Then it's just a right and left click to restore the number instead of having to retype.
Title: Re: Set text on EventDrop
Post by: Soundstorm on August 08, 2022, 08:26:09 AM
Ok, that doesn't work  ::)

It seems that when dropping the shape, it does both events, and TheText event is the last one it does...
Title: Re: Set text on EventDrop
Post by: vojo on August 08, 2022, 12:45:45 PM
works fine

Attached is the ensence of what I believe you want to do
Look at shapesheet for details
Title: Re: Set text on EventDrop
Post by: wapperdude on August 08, 2022, 01:01:16 PM
It's early, coffee hasn't kicked in yet...  so, I haven't processed your latest implementation approach.

Nonetheless, couple of points.  Instead of using both events, you might try catenating commands in the event drop cell.  For example, =setf(getref(User.tag),"V-xxxx")  + Docmd(1312).  Both commands, sequentially, push text into user.tag, and field insert displays the current value.  You can add more commands, e.g., show/hide text.  The idea being, haven't tried this out, is that on drop the tag text is reset and then the Shapedata UI form is invoked allowing new info to be added.  (Although, Shapedata can be called on drop ( I don't normally do this), and, I think, it can be set to default to the reset text.  That is, both commands are built-in.  But for sake of example, I wanted to show catenations that are applicable.
Title: Re: Set text on EventDrop
Post by: Soundstorm on August 08, 2022, 02:40:40 PM
Quote from: vojo on August 08, 2022, 12:45:45 PM
works fine

Attached is the ensence of what I believe you want to do
Look at shapesheet for details
This is similar to what I already tried. Problem is that once you type new text, the logic connected to the field is deleted. So if you copy/past a shape with replaced text, you just get the shape with the same text everywhere.

Quote from: wapperdude on August 08, 2022, 01:01:16 PM
It's early, coffee hasn't kicked in yet...  so, I haven't processed your latest implementation approach.

Nonetheless, couple of points.  Instead of using both events, you might try catenating commands in the event drop cell.  For example, =setf(getref(User.tag),"V-xxxx")  + Docmd(1312).  Both commands, sequentially, push text into user.tag, and field insert displays the current value.  You can add more commands, e.g., show/hide text.  The idea being, haven't tried this out, is that on drop the tag text is reset and then the Shapedata UI form is invoked allowing new info to be added.  (Although, Shapedata can be called on drop ( I don't normally do this), and, I think, it can be set to default to the reset text.  That is, both commands are built-in.  But for sake of example, I wanted to show catenations that are applicable.
What I have noticed is that if you copy several shapes at the same time, the shapedata prompt popup doesn't come up all the time. You also don't know what shape it is 'talking' about. Wouldn't this behave the same?
Title: Re: Set text on EventDrop
Post by: wapperdude on August 08, 2022, 03:03:30 PM
Good point.  You did say multi-shape copy and paste.  Yes.  This scenario has a problem.  The "reset" is probably fine, but setting new text would be on an individual basis.  So, each shape would need to be individually selected.  Not sure how Visio duplicates a bunch of shapes...whether it treats them in a sequential manner or as a virtual group.  I would think the former, so "reset" ought to work.  (Disclaimer:  I'm not at my computer so I cannot check this, nor Iooked at any recent, preceding posts.) 
Title: Re: Set text on EventDrop
Post by: wapperdude on August 08, 2022, 09:45:24 PM
Here's sample that has the Event formula in place.  The functionality assumes that there is a fixed prefix.  In this case TT.  Field insert adds input text after the prefix.  In this case, 4 digit number.  The active formula is in Event Drop Cell as suggested above.  Shape drop automatically resets to predefined text, xxxx in this example, brings up shapedata form for new entry.  Text editing is locked, so no direct entry possible.  Dbl click the shape will invoke shapedata form to change existing value.
Title: Re: Set text on EventDrop
Post by: wapperdude on August 08, 2022, 11:49:17 PM
New file with some embellishments:
1) Added User Defined cell to hold the default text string.  More obvious.
2) If the actual actual string matches the default string, then color changes to red.  Otherwise, it is black.
Title: Re: Set text on EventDrop
Post by: wapperdude on August 09, 2022, 02:42:28 AM
To fully automate this behavior for both single and multiple drop scenarios will some code.  So, as you've experienced, when dropping multi shapes, with formula in only the event drop cell, behavior is uncertain.  You can copy that formula to the multi strip cell and all of the shapes will be predictably impacted...as if they were in virtual group.  Thus, singular editing  doesn't happen.  So, the best that can be achieved is to merely reset all shapes to default value.  Then, deselect all and go back and individually edit each shape.  Coloring the text helps identify which shapes to edit.  To achieve full, to accommodate individual editing in both the single and multi drop scenarios would take some code.

I don't believe the simplicity you desire for all scenarios is possible with shapesheet only solution.
Title: Re: Set text on EventDrop
Post by: Soundstorm on August 09, 2022, 07:22:12 AM
Quote from: wapperdude on August 08, 2022, 11:49:17 PM
New file with some embellishments:
1) Added User Defined cell to hold the default text string.  More obvious.
2) If the actual actual string matches the default string, then color changes to red.  Otherwise, it is black.
Thanks! This indeed works to reset the tag. But having the option to just select a shape and start typing the tag number is something that really helps the workflow.
There is a lot of other shape data to be entered, and this might become distracting.

I fiddled some more with my idea to use the text and drop events, and came up with something that almost works! (I would hide the shapetext, I just leave it visible for testing)
Input of a new tag works, when doing copy paste, it resets.
BUT! When dragging the shape around, it also seams to trigger the text event. Moving it with the arrow keys on the other hand has no influence.
This is probably Visio mystery behaviour  :o

Is there a way to detect a drag of a shape, such that I can 'lock out' the text event with the user.resetcounter?
Title: Re: Set text on EventDrop
Post by: wapperdude on August 09, 2022, 02:43:19 PM
Good morning.  Working on that cup of coffee...

QuoteBut having the option to just select a shape and start typing the tag number is something that really helps the workflow.  There is a lot of other shape data to be entered, and this might become distracting.

The requirements are becoming more fluid, dynamic.  The provided solution targeted setting a tag shape.  Double click the shape and the tag entry can be edited.  Allowing the user to edit directly would clobber the Field Insert methodology.

As for all the other properties, a lot more definition is needed.  Looking at the built-in solutions suggested by the others, or a custom consideration, e.g., as outlined by Yacine, needs more consideration.  For example, the main shape, which has the associated tag, could contain these properties.  These could be defined/labeled.  The user could manually edit, chose from dropdown list, imported from Excel or a dedicated database.  Most of these would leverage both shapesheet functionality and some sort of coding solution...built-in or custom.  Whatever is implemented, caution must be exercised wrt end user.  To wit, the amount/ease of editing allowed, protecting the implemented solutions.

We're happy to help where possible.  But as volunteers, our scope is limited.  Some volunteers are available for extended, paid development/solutions. 

Title: Re: Set text on EventDrop
Post by: Soundstorm on August 11, 2022, 09:16:05 AM
I hope I didn't give the impression that I want you guys to provide me with a perfectly working solution. The topics in this forum have helped me a lot in understanding the workings of Visio, and I'm starting to enjoy it now. That is also why I'm trying to figure out things, even after I ask my question here. It's only when I get stuck, that I'm happy to come over here and get some input from you guys to keep me going.

Now going back to how to input the tag name, we have decided that using Shape Data is not that much more work. We go from "click to select, type, click to deselect", to "a double click, type, press enter". If that change messes up the workflow too much, I think we have a different more serious problem ;)

So I think the solutions you guys provided is perfect!

That being said, I'd like one more favour. I went through all the documentation, but this formula is still breaking my mind
=SETATREF(User.PIDTagInputText,SETATREFEVAL(SETATREFEXPR("Default Tag")))
Can you explain what is happening here?

I have some formulas that automatically correct the Tag in case a typo was made. So is it possible to place the output of that user cell back into the shape data? Or would that create a circular reference?
Whatever tag is input in the Shape Data, gets transferred to User.PIDTagInputText, I then have a formula that checks for typos, and either outputs a correct tag, or an error to make it clear that the tag is wrong. That formula outputs to User.PIDCorrectedText.
Title: Re: Set text on EventDrop
Post by: Croc on August 11, 2022, 10:59:36 AM
QuoteI went through all the documentation, but this formula is still breaking my mind
=SETATREF(User.PIDTagInputText,SETATREFEVAL(SETATREFEXPR("Default Tag")))
Can you explain what is happening here?
The SETATREF function assumes that there are two cells:
Cell1 - the one where the function itself is placed
Cell2 - the one where you need to pass the value
The function not only transfers the value to the Cell2 cell, but also returns this value to the Cell1 cell. Moreover,  the formula is not destroyed.
Let's take an example. Let the shape have a ShapeData labeled "a".
The Value cell contains the formula
In this case, Cell1 is Prop.a.Value. It contains formula =SETATREF(Prop.a.Prompt,SETATREFEVAL(SUBSTITUTE(SETATREFEXPR("hh"),"11","2")),FALSE)
Cell2 is Prop.a.Prompt. But Cell2 is not important. Only Cell1 is interesting. It contains a formula and we need to return the changed value to it.
The above formula should replace two adjacent "1" characters with a single "2" character.
SUBSTITUTE(SETATREFEXPR(),"11","2")
See the animated gif for how it works.
-----------
When the user changes the value of Prop.a through the UI or programmatically, Visio does the following in sequence:
- Detects that a formula contains the SETATREFEVAL function
- Finds among its arguments the SETATREFEXPR function
- Executes SETATREFEXPR - remembers the value that the user is trying to enter in Cell1.
- Performs a SETATREFEVAL function on this value - in this example, SUBSTITUTE.
- Passes the computed result to Cell2.
- Replaces the value of Cell1 with the value of Cell2 (returns the result).
Title: Re: Set text on EventDrop
Post by: vojo on August 11, 2022, 01:13:25 PM
FWIW....setatref functions are very very powerful but also very complex....good luck
Title: Re: Set text on EventDrop
Post by: wapperdude on August 11, 2022, 01:35:35 PM
There is an almost tutorial on SETATREF here:  http://visguy.com/vgforum/index.php?topic=6383.msg26308#msg26308 (http://visguy.com/vgforum/index.php?topic=6383.msg26308#msg26308).   Start at the beginning.  That sets the ground work.  Then, a variety of examples are added to see how the formulas are applied.