Visio Guy

Visio Guy Website & General Stuff => User-submitted Stuff => Topic started by: Yacine on May 04, 2010, 05:46:59 PM

Title: Discard *automatic* repositioning of subshapes in a group
Post by: Yacine on May 04, 2010, 05:46:59 PM
Let's say you have no yet upgraded to Visio 2010 and need to design a container. You would set up a group shape, put in a frame and a label. As behaviour, you'd allow it to accept droped shapes.
So far easy... you add and remove sub-shapes – heaven in Visio World.
Now you will want to extend your group with additional shapes, you widen your group and Uhh... the sub-shapes stretch and move around. No prob, you set their behaviour to ,,reposition only". Well that is not enough – the shapes still move in the direction of your stretching. Hmmm... You will open their shapesheets and put numerical values in their PinX, PinY. Fine, they don't move around anymore when you resize the group.
The very next Monday, you're asked to update the group and change the position of the sub-shapes, and you notice that the absolute positions are lost. Visio overwrites them with some ParentShape!width*number. Hummm... dumb Visio.
So you go to the obvious – and each time Visio overwrites your Pins - that is every time the eventFXMod is fired - you do the same and overwrite them their same numerical values, without the reference to the parent shape.
eventFXMod=SETF(GetRef(PinX),GetVal(PinX))+SETF(GetRef(PinY),GetVal(PinY))
I found that trivial solution so amazing simple, that I wanted to share it. Enjoy!

PS: The standard behaviour would be that the coordinates refer to the left bottom corner. One will often prefer to extend the group to the bottom, thus refer to the left TOP corner... Just flip your group vertically.

PPS: There are some other features in the attached container. I'll let you discover by yourselves.
Title: Re: Discard repositioning of subshapes in a group
Post by: vojo on May 04, 2010, 09:12:54 PM
Use the guard function

Pinx = Guard(<something like 22mm from left edge>)  kind of thing
or
Pinx = Guard(<14mm from page-1!pinx>) kind of thing

etc

Ie if you make the "container" have a reference point that is fixed....and use that reference point for subshapes...should be able to scale container without affecting subshapes
Localpinx=0 and reference off that.....if move container...shapes move....if you scale container, shapes stay as is..

Visio guy had an article about 6 months ago on how keep a shape center on an x,y when scalling it.   Might be of help
Title: Re: Discard repositioning of subshapes in a group
Post by: Yacine on May 04, 2010, 09:24:33 PM
Vojo ...  :-\
How do you want me to move the shapes if I "guard" their positions?

didn't see that article, have you got a title or a link?
Title: Re: Discard repositioning of subshapes in a group
Post by: vojo on May 05, 2010, 06:30:34 AM
action.enablemove = setf(getref(actional.enablemove.checked), if(action.enablemove.checked,0,1))

pinx = if(action.enablemove.checked, setatref(user.mypinx),guard(user.mypinx))

something like this should work...may need to play with syntax

In essence, if moves are enabled (right click shape and select enable move), then wherever you move the shape, user.mypinx gets the value....when you turn off moves, the pinx is locked into user.mypinx

This should help
Title: Re: Discard repositioning of subshapes in a group
Post by: Yacine on May 05, 2010, 07:18:10 AM
Vojo,
it took me some time to understand you  :-\ sorry. I'm a bit slow.
My title was confusing. It should have stated "Discard *automatic* repositioning of subshapes in a group".

When groups are resized, they will reposition their sub-shapes. That can be quite annoying, when the distance between the sub-shapes matters.
With my suggestion, you can shrink or widen your group and still keep the relative position of the sub-shapes to each other.

Guess this is rather a case for the suggestion box, than for the user-submitted stuff. Visio should offer this additional option as standard. ::)

By the way, I checked your shapesheet - very nice - worth keeping somewhere. :)
... I would probably have rather worked with the protection cells of the shape and/or the group
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: vojo on May 05, 2010, 06:15:58 PM
I dont think protection would give the choice....I think would be "always moves" or "never moves"

I think you are going to have break out the path to do anything selective
(you may not want to use actions as the trigger....np...but I dont think you can pull this off with only a setatref(xxx,setatrefexpr(setatrefeval))) kind of approach.
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Yacine on May 05, 2010, 06:19:26 PM
Vojo,
this post was not meant as question, the problem is solved. Check my attachment.  ;)
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: vojo on May 05, 2010, 06:22:37 PM
what attachment...original moves subshapes all over the place
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Yacine on May 05, 2010, 07:04:21 PM
 ???
I downloaded my own file and it works.
The green valve has the smart behaviour - that is: it stays in place when the group is resized (just to make sure  :D) -, the red one not.
Does it only work on my computer?
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: wapperdude on May 05, 2010, 07:23:59 PM
Container_001.vsd works on V2007.

Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Visio Guy on May 05, 2010, 08:07:34 PM
This will keep a sub-shape oriented relative to the top-right side of a group:

PinX = SETATREF(User.dx,SETATREFEVAL(SETATREFEXPR(Sheet.3!Width*0.9779)-Sheet.3!Width))+Sheet.3!Width
PinY = SETATREF(User.dy,SETATREFEVAL(SETATREFEXPR(Sheet.3!Height*0.9946)-Sheet.3!Height))+Sheet.3!Height

Sheet.3 is the group
User.dx and User.dy must exist and end up holding the offsets from the right and top sides of the group.
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: vojo on May 05, 2010, 08:33:33 PM
first and last attach does not work on 2003....scale or move

Ie the green changes position when container scales or moves
(I assume you wanted the green to stay fixed even if the container moved).

I am quite surprised you think those formulas work....in essence, pinx scales with sheet.3!width*0.9779...so if container gets bigger, the pinx of subshapes changes.
(nice trick with width...holds the posiiton in the container constant....though unless move is addressed this is no better than pinx=sheet.3!width*0.9779 kind of thing)
(i.e. alot of heavy lifting to get back to where the basics ;-)  )

Could throw in here a scaling factor similar to the font autoscale...use that to adjust pinx to stay constant as container grows.

I did something similar to this for an "isometric snap" of a shape...but it was always on...not selectively
I have used the scaling approach for isometric shapes alot...though always on

Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: vojo on May 05, 2010, 08:37:55 PM
those equations dont appear in the subshapes....just raw numbers like 95mm.

Must be some sort of dependency on 2007 or later....first time I ever saw that with basics like pinx
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Yacine on May 05, 2010, 08:46:24 PM
@Visio Guy
Excuse me Master if I object  ;D, (http://smiles_6.gif)
but I think that I will stay with the flipping option.
The FXMod event method needs only 1 cell to modify, instead of 3 and the user can chose by himself in which direction he wants to stretch the group. The setatref solution would require much more formulas to achieve the same effect.

The whole thing came up because you have absolutely no possibility to resize a complicated group, without changing it's content (positions).
So If the group has the wrong stretching direction, no problem: give the sub-shapes more space, then - in the group window - select the required sub-shapes and reposition them. That is not possible in the standard groups.
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Yacine on May 05, 2010, 08:52:06 PM
I just checked that the EventXFMod exists in V2003. It does. Same for SetF and GetRef.
... ???
Will try this at work, where we still use V2003.
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Visio Guy on May 06, 2010, 07:20:06 AM
The SETATREFEXPR is tricky. When you move the sub-shape by hand, the bit inside the parentheses will change, according to Visio's standard, proportional positioning inside a group. So: if I move a sub-shape so that it is all the way to the bottom, then this:

PinY = SETATREF(User.dy,SETATREFEVAL(SETATREFEXPR(Sheet.3!Height*0.9946)-Sheet.3!Height))+Sheet.3!Height

will change to this:

PinY = SETATREF(User.dy,SETATREFEVAL(SETATREFEXPR(Sheet.3!Height*0)-Sheet.3!Height))+Sheet.3!Height

and User.dy will be equal to minus the entire height of the group. But User.dy will be a number, not a formula. So the resulting PinY of the sub-shape will be "group height-what the group height was" = 0, until we change the height of the group.
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: vojo on May 06, 2010, 02:14:21 PM
so ever time I used this ftype of ormula on other shapes and such, the equation always stays....it does not replace it with numbers.

For example, this equation always stays (snap shape to isometric - actually 2:1 psuedo iso - reference via user.gridx).....never dissappears to a single raw number.
numbers in the middle changes...but formula stays

pinx=INT(SETATREFEXPR(93 mm)/User.gridx+0.5)*User.gridx

Are you suggesting the setatrefeval forces always to number...seems odd since could never update the formula in shape sheet....would have to fire blind all the time
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Yacine on May 06, 2010, 03:51:34 PM
I guess everyone here knows this classic, just in case...
http://blogs.msdn.com/visio/archive/2006/09/29/777101.aspx
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Yacine on May 10, 2010, 08:10:19 PM
Hi Vojo,
been back to office today and I am very sorry to have to say: it works with visio 2003.
;) Cheers Yacine
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: vojo on May 10, 2010, 08:18:15 PM
not mine....shapes move in relation to container and overall scaling of container....tried several times.
Maybe I am missing what you are trying to accomplish (subshape stays fixed while container is moved or scaled).

I have not had a problem with 2003 pretty much ever.   Its not like google sketchup that crashes daily
Title: Re: Discard *automatic* repositioning of subshapes in a group
Post by: Yacine on May 10, 2010, 08:21:49 PM
That will remain one of the unsolved questions of humanity ;)

Joking apart, could you try putting the formula manually in a shape contained in a group?
EventXFMod = SETF(GetRef(PinX),GetVal(PinX))+SETF(GetRef(PinY),GetVal(PinY))

The sub-shape should
1. follow the group as the latter is moved
2. stay in place when the group is resized