Adding an icon to a process shape then including it into an exiting stencil

Started by paulricot, September 24, 2018, 11:05:54 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

paulricot

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.

Yacine

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?
Yacine

wapperdude

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

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

paulricot

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

Yacine

@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.
Yacine

wapperdude

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

paulricot

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

wapperdude

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

Yacine

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
Yacine

wapperdude

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

paulricot

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.