Set text on EventDrop

Started by Soundstorm, August 05, 2022, 01:32:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Soundstorm

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?

wapperdude

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.) 
Visio 2019 Pro

wapperdude

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.
Visio 2019 Pro

wapperdude

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.
Visio 2019 Pro

wapperdude

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.
Visio 2019 Pro

Soundstorm

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?

wapperdude

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. 

Visio 2019 Pro

Soundstorm

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.

Croc

#23
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).

vojo

FWIW....setatref functions are very very powerful but also very complex....good luck

wapperdude

There is an almost tutorial on SETATREF here:  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.
Visio 2019 Pro