Visio Guy

Visio Discussions => Shapes & Templates => Topic started by: paulricot on September 24, 2018, 11:05:54 AM

Title: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 24, 2018, 11:05:54 AM
I am using a stencil provided by our consultants. There are shapes that have been specially designed to have a icon in the top left corner and text in the middle, which if you double click, you can edit.

This is all fine, but they have missed a certain type of process step and I need to create a new process shape with a cogwheel icon in the top left to denote "automated step" which is not in their stencil. I can do this "manually" by importing an image of a cogwheel, pasting it into position within one of the existing "special" process shapes (when I ungroup I get the message about breaking link with master) then regroup and dragging onto their stencil. However, this does not work:

1. When you make the process shape longer, the icon distorts (because its an image)
2. The text (I saved the shape with default text) cannot be edited

I know its something to do with adding custom section to the process shape and messing with the shapesheet and I need a vector cogwheel to stop distortion. I've searched and searched the internet for a process on this, but I can't find it.

Can anyone help?
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 24, 2018, 01:46:53 PM
Hi Paul,
it would last too long to explain every thing in detail, so here are just the steps, that should do what you want.

1) Drop one of the "good" shapes on your canvas. We'll try to modify it as little as possible, so as to keep the original behaviour (text, ...)
2) Copy the cogwheel picture to the clipboard (ctrl-C)
3) "OPEN" the group - don't ungroup it. You can find this option under group/open ...
4) Paste the cogwheel into the group. Resize it to your needs. Delete the old picture and position the new one at its place.
5) To avoid distording the cogwheel, when the parent shape is resized:
a) Under File / Options / Advanced you can find the option "run in development mode". Check it.
b) Now when right-clicking on the image, you should see the option "open shapesheet". Click it.
c) on the left top side you should see the 2 fields "width" and "height". Each of them contain a formula - something like "sheet.123!width*0.2". Replace both formulas by an absolute value eg "5 mm" or "0.5 in".

Your're done.
Close the group, test it, then copy the shape to a stencil.

HTH, Y.
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Nikolay on September 24, 2018, 06:06:28 PM
+1

The key point - open the group to edit (right click -> group -> open group), DO NOT UNGROUP, ungrouping breaks the shape.
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 25, 2018, 11:27:13 AM
Thanks very much Yacine. I've done what you suggest and it does work. Just one slight problem:

Although the shape no longer distorts as you change the  process shape its attached to, what does happen is that as you (Say) stretch to right, the icon image moves (no distortion) also a % to the right (grrrr!). I have tried to fix in the shapesheet (LocPinX, LocPinY) but these can't be the right parameters cos it makes no difference (in fact, original values just keep reappearing)

Any ideas?
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 25, 2018, 11:57:22 AM
Right, it's PinX and PinY that you need to change, not LocPinX/Y.
You might be interested in this topic: http://visguy.com/vgforum/index.php?topic=7120.0
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 25, 2018, 02:29:57 PM
Thanks Yacine - your first video on shape handling is most enlightening! I now know a little more what those parameters on the shapesheet do.

Having "fixed" the horizontal position (PinX) at zero, this means that when the parent shape is changed, the cogwheel remains rock steady on the horizontal plane. However, because of positioning, I cannot seem to "fix" the Vertical PinY at 0, so then if the shape is stretched vertically, the cogwheel starts to move slightly lower as you stretch the parent. Its not a showstopper, but it looks ugly. I have fiddled with the vertical parameters, but not having much luck.

(see attached)
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 25, 2018, 02:48:30 PM
Hi Paul,

The formula should be: PinY = sheet.185!height * 1 - 1mm
1 mm is the fix distance from top, you choose
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 25, 2018, 03:34:37 PM
Hi Yacine,

The problem with making it sheet.185!height * 1 is that the shape then appears right at the top of the parent shape & covers up the outline of the parent shape and looks ugly.

I appreciate the your solution, but I cannot help but think that there is a method within Visio to do this. So let's suppose I wanted to create one of these "special" shapes from scratch. You would start with a basic process step then add the icon in the top left corner. Maybe some shapesheet parameters are changed, but the shape is then protected. How do I know that? Because if I apply your procedure to one of these shapes as supplied by our consultants, you cannot edit or do anything with the icon they have attached. A message comes up saying something about shape protection. And it gets worse. If I drag my own "special" shape onto a stencil, then use it as normal, the icon moves and distorts. I look at the image shapesheet and all the parameters have been reset. 

Also, to enable the text to be double clicked from the stencil, I'm sure you would then add a "section" to the shape and specify it as text. I'm sure all this is documented somewhere because our consultants have provided these custom shapes for us. I just have no idea where I would find it.
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 25, 2018, 04:20:50 PM
Quote from: paulricot on September 25, 2018, 03:34:37 PM
The problem with making it sheet.185!height * 1 is that the shape then appears right at the top of the parent shape & covers up the outline of the parent shape and looks ugly.

That's right the "-1 mm" was meant as example. Set the distance to a value that does not overlap the border. ;) The formula is [sheet.185!height * 1 - n mm]. Replace n by a number that suits you.

As for the protections, there are several possibilities to realise them.
There's the protection section and each cell of the shapesheet can be enclosed in a "Guard()" function.

The double-click behaviour can be set in the behaviour dialogue or in the events section of the shapesheet.

... and be patient with yourself, the shapesheet is a wonderful tool, but it is big and it takes some time to 1) understand it, 2) to learn to play with it.
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: wapperdude on September 25, 2018, 07:02:19 PM
There is also the Drawing Explorer Window (DEW).  It gives you a tree view of the Visio document.  You can expand it to show drawing pages/ background pages.  Expand a page to see shapes, layers.  Expand shapes if they are grouped.  Click on a shape and it will be selected in the normal drawing window.  Right click a shape in the DEW, and you get related options like viewing its shapesheet.  The point being, you can see the level of complexity of one of consultant supplied shapes.  They can become quite involved, requiring a lot of time, effort, and learned skills.

There is no "canned" procedure for building these things. 

Wapperdude
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 25, 2018, 07:07:14 PM
Quote from: wapperdude on September 25, 2018, 07:02:19 PM
There is no "canned" procedure for building these things. 
+1
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 26, 2018, 12:39:43 PM
Thanks Yacine & Wapperdude for all your patience and help.

But lets try and keep it as simple as possible (Albert Einstein-wise!).

Can either/both of you just try this (will not take you guys long, promise!)

ok - take a standard process shape. Now import picture of an icon - anything will do but a cogwheel is good. Now all you have to do is group these two together so that the icon
1. Stays in the same location when process shape is stretched
2. Does not distort when the process shape is stretched
3. Keeps these properties when added to a custom stencil.

How hard can that be?

Thanks
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 26, 2018, 01:28:42 PM
Why don't you use the tool in the link previously posted? It does all that stuff.
(http://visguy.com/vgforum/index.php?topic=7120.0 (http://visguy.com/vgforum/index.php?topic=7120.0))
Load the stencil in your current Visio instance, drag the yellow square on the canvas and start adjusting the group shape.
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: wapperdude on September 26, 2018, 03:03:34 PM
Not at my computer at the moment, but, for sake of completeness, the manual, DIY, steps are...
(If you haven't discovered this, you can right click in shapesheet and select to display either formulas or values.  Handy to toggle back n forth.)

1) drop the process shape on the page
2) note the size of its width and height
3) size & place your icon as desired;  note its width and height
4) open icon shapesheet and place guard function around both the width and height values
5) group; note the shape name of the group.  S/B sheet.3
6) once grouped, select the icon and open shapesheet
7) verify that width and height are still guarded, with same values in step (3); if not, make it so Scotty!
8.) ...now for some math.  Display values.
        a) look at PinX, note its value, do same for PinY
        b) enter formula into Pin X:  guard(sheet.3!width*0+xpinval) where xpinval is the literal number for PinX in step (a)
        c) calculate the height offset:  ho = value of step (2) height - value of step (8a) PinY
        d) enter this formula into PinY:  guard(sheet.3!height*1-ho) where ho is the literal value you just calculated
9) Deselect your icon

Assuming I remembered everything, and all steps done correctly...no typos...your group ought to look exactly as it did when you first created it.  Now when resizing the group, the icon will remain in its relative location, and size will not change.

Wapperdude
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 26, 2018, 03:12:10 PM
Hi Yacine,
Ok - I have imported GroupBehavior and followed your video for instructions. You are correct, it now works as expected.

However...when I drop the "now working" grouped shaped onto a stencil, save the stencil then drag the now "master" shape onto the working area, it no longer works. Looks like putting these shapes into a stencil undoes all the good work from your macro.

Any way round this?
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 26, 2018, 03:16:50 PM
Hi Wapperdude - I will work through your steps later on, however, I have a feeling that even though on the canvas, it will work as expected, when the working shape is dropped into a stencil, then using it from the stencil will reset all the shapesheet parameters. But we'll see.
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 26, 2018, 03:31:12 PM
Quote from: paulricot on September 26, 2018, 03:12:10 PM
However...when I drop the "now working" grouped shaped onto a stencil, save the stencil then drag the now "master" shape onto the working area, it no longer works. Looks like putting these shapes into a stencil undoes all the good work from your macro.

I haven't experienced such a behaviour in the past. Would like to upload some material (shape, stencil , ...)? Either to the forum or to private message?
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: wapperdude on September 26, 2018, 04:10:35 PM
I concur with Yacine re stencil dropping behavior, and agree that if you could upload simple file would be helpful.

At my computer, followed the steps I outlined.  Worked as expected.  Copied grouped shape to stencil.  Dropped stencil shape onto drawing page.  Works as expected.

See attached.



Wapperdude
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Paul Herber on September 26, 2018, 04:28:25 PM
I'm wondering if the grouping at step 5 happened correctly?
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 27, 2018, 11:28:33 AM
So, using Yacine's "Group Behavior" macro, I find that when the shape is on the working pane, after transformations, it works ok.
But then if you drag & drop to a stencil, save the stencil, then pull of an example to use, it does not work properly.

(File attached - the shaded process shape is the one not from the stencil and that works. I will also try and attach the stencil)

Thanks again for your help
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 27, 2018, 12:59:14 PM
@Paul,
Your observations are indeed correct. But neither have I observed this behaviour yet, nor can I explain it.
A workaround (tested) is to guard the cells. ie: include every formula or value in the object section in a "Guard( ... )" function.

My tool is in so far buggy as it doesn't yet set properly the guard function. So until I upload a corrected version, please do the adjustments manually.
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: wapperdude on September 27, 2018, 01:49:12 PM
The issue is, indeed, the lack of the guard function.  When the group is copied to the stencil, Visio overwrites non-grouped referenced values, e.g., width, height, with group references.  So, yes, before copying to stencil, the guard fcn must be added. 

So, until the macro is updated, you will, have to do some manual shapesheet editing.

Wapperdude
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on September 27, 2018, 02:46:19 PM
ok Wapperdude

- so is it just "Width" & "Height" on the icon that needs changing (leave PinX, PinY, LocPinX, LocPinY alone) or do I need to GUARD the parent shape "Width" & "Height" as well?

Thanks
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: wapperdude on September 27, 2018, 03:43:27 PM
Rather than me telling you.  Just open the shapesheet of the stencil master...make stencil editable, right click the icon, edit master, select the shape, open shapesheet.  Compare the contents with your original grouped shape's (that works correctly) shapesheet.  Look at the differences and make the corrections.  This gives you hands on experience.  Close shapesheet of stencil master.  Close stencil master...say yes to update.  Now drop on the drawing page.  Should work fine.  Hint:  not every cell you named needs editing.
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: Yacine on September 30, 2018, 12:52:55 PM
Wapperdude pushed me to finish the job ...
so I refactored the code, so as to make readable. Replaced the nested if statements by a select case on a coded combination of the operations.
I did also check the behaviour when formulaForce and Guarded options are selected. Both options work fine.

Still sometimes some formulas get lost when applying different operations in a row.
I suspect it has less to do with the operation flow of the tool, than with the order of the formulas applied to the shapes.... couldn't really get my head around it and ... gave up.
At least the code is cleaner now and the guard function works. Modified shapes can now be saved to stencils without losing their behaviour.

Cheers,Y.

PS:The code setting the formulas with select case:

            If Optsize Then op = "size_" Else op = "pos_"
           
            If OptX Then dir_ = "x_" Else dir_ = "y_"
           
            If OptProp Then rel = "Prop"           
            If OptFixed Then rel = "Fixed"            If OptMid Then rel = "Mid"            If OptMin Then rel = "Min"            If OptMax Then rel = "Max"
           
            combo = op & dir_ & rel
           
            Select Case combo
                Case "size_x_Prop":     writeFormula subShp, "width", "sheet." & pShp.ID & "!width*" & Replace(sWidth / pWidth, ",", ".")
                Case "size_x_Fixed":    writeFormula subShp, "width", Replace(sWidth, ",", ".")
                Case "size_x_Mid":
                                        writeFormula subShp, "PinX", Replace(sPinX - sLocPinX, ",", ".")
                                        writeFormula subShp, "LocPinX", "width*0"
                                        writeFormula subShp, "width", "sheet." & pShp.ID & "!width*1 - " & Replace(pWidth - sWidth, ",", ".")
                Case "size_y_Prop":     writeFormula subShp, "height", "sheet." & pShp.ID & "!height*" & Replace(sHeight / pHeight, ",", ".")
                Case "size_y_Fixed":    writeFormula subShp, "height", Replace(sHeight, ",", ".")
                Case "size_y_Mid":
                                        writeFormula subShp, "PinY", Replace(sPinY - sLocPinY, ",", ".")
                                        writeFormula subShp, "LocPinY", "height*0"
                                        writeFormula subShp, "height", "sheet." & pShp.ID & "!height*1 - " & Replace(pHeight - sHeight, ",", ".")
                Case "pos_x_Prop":      writeFormula subShp, "pinX", "sheet." & pShp.ID & "!width*" & Replace(sPinX / pWidth, ",", ".")
                Case "pos_x_Min":       writeFormula subShp, "pinX", Replace(sPinX, ",", ".")
                Case "pos_x_Mid":       writeFormula subShp, "pinX", "sheet." & pShp.ID & "!width*0.5-" & Replace(pWidth / 2 - sPinX, ",", ".")
                Case "pos_x_Max":       writeFormula subShp, "pinX", "sheet." & pShp.ID & "!width*1-" & Replace(pWidth - sPinX, ",", ".")
               
                Case "pos_y_Prop":      writeFormula subShp, "pinY", "sheet." & pShp.ID & "!height*" & Replace(sPinY / pHeight, ",", ".")
                Case "pos_y_Min":       writeFormula subShp, "pinY", Replace(sPinY, ",", ".")
                Case "pos_y_Mid":       writeFormula subShp, "pinY", "sheet." & pShp.ID & "!height*0.5-" & Replace(pHeight / 2 - sPinY, ",", ".")
                Case "pos_y_Max":       writeFormula subShp, "pinY", "sheet." & pShp.ID & "!height*1-" & Replace(pHeight - sPinY, ",", ".")
            End Select
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: wapperdude on September 30, 2018, 11:52:25 PM
For the specific case of this post, I played with the shape to enhance its smartness. 
First, the icon size and offset were parameterized.  You can immediately access the data entry by double-clicking the shape.
Second, the offsets are edge to edge defined.  Just seemed like common sense.  Plus, if the icon size is changed, its relative distance from top / left edge remains unchanged.
Third, unlike Word, where you have word wrapping around a picture, Visio has no such option (that I'm aware of).  To circumvent this deficiency, the first tab stop is defined to be the icon width + 2*horizontal offset from the left edge of the group shape.  Well, it's better than a poke in the eye with a sharp stick!

Wapperdude
Title: Re: Adding an icon to a process shape then including it into an exiting stencil
Post by: paulricot on October 02, 2018, 05:29:54 AM
Thanks Yacine & Wapperdude - you have both gone to a lot of trouble to help me and that is much appreciated. I will try both new GroupBehaviour and GroupTest.