BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Shape Sheet Code

Started by Scott10284, June 23, 2023, 02:12:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


I am having trouble figuring out how to write a line of code, maybe its not possible at all.

When my shape is rotated to the horizontal plane [ OR(Angle=0 deg,Angle=180 deg) ] I want to lock a control point associated to this shape to NOT be movable in the Y plane but still be movable in the x plane. This part is easy enough. When the shape is rotated to the vertical plane the same control point can be placed anywhere.

I there a way to write this code with a simple IF statement?

Thomas Winkel

Try this formula in the Y Behavior cell:
=IF(OR(Angle=0 deg,Angle=180 deg,Angle=-180 deg),1,0)

See attached document.


Thomas answer is the easiest, most straightforward approach.

But, for a less obvious approach, that also works, enter this formula into the Controls.Y cell:  =SETATREF(User.Row_1,SETATREFEVAL(SETATREFEXPR(Height*-0.01)),IF(OR(Angle=0,ABS(Angle)=180),1,0)).  Note, it does require the addition of the User Defined section, with default 1st row.

It uses SETATREF function family.  (Everyone's favorite  ???).  It takes advantage of the optional last entry for SETATREF, ignore value.  Using an IF statement, when the test is true, the ignorev value is set to 1.  (This inhibits updating the placeholder value.)  Otherwise, the value will be set to 0, the default value for the function.  I know.  Who cares?

While both approaches lock the Y-position, there is a behavioral difference.  The 1st method freezes the Y-position, while the 2nd method jumps the Y-position back to edge of the shape.  This might be helpful if there's a lot of clutter.
Visio 2019 Pro


you may want to consider the guard function
y = guard(<formula of interest>)

guard prevents the cell from being updated based on user actions
without it  y= <function>  becomes y=<some sort of mm or inches based on where control point moves to?


I have actually already tried most of the above mentioned solutions with unsuccessful results. The suggestions that Thomas and Wapper made work, however the control point can be put in an undesirable location prior to rotating the shape and it gets locked somewhere I do not want it to be locked at.

I think I need to put the code in the Controls.X and Controls.Y fields to place the control point exactly where I need it when Angle=0,180,-180, however when Angle=90,270 I need to be able to move the control point freely.

Here are the 2 problems I have with this.

1. I cannot use an IF statement effectively. With and IF THEN ELSE approach, I am not sure how to define the "ELSE" to give the user the ability to move the point freely when Angle=90,270
2. If I go not GUARD the statement, it gets blown out when the user moved the control point

Half of the time I need the control point completely locked down, the other half of the time I need it free. This is why I am struggling to do this with an IF statement approach.


Couple observations...
1). In your original request, you merely mentioned disabling the Y-direction control.  Now, you indicate you need it at some specific location.  That is a new restriction.  However, the SETATREF formula did, at least in my test case, park the Y-direction along the buttom edge of the shape.  So, this does seem to meet the new requirement.  Perhaps a better explanation of your need?  A couple of pix to illustrate what you want, don't want.

2) The SETATREF formulas do not get blown-away when User makes an entry via ribbon GUI.  The formula gets clobbered if (a) it is intentionally overwritten directly in shapesheet, or, (b) via SETF function in another shapesheet cell, or, (c) via code.  Perhaps you can upload what you've tried.

3). Thomas's solution is likewise unaffected by GUI ribbon entries.   The behavior cell is unaffected.

4). In both methods, the Y-direction is only inhibited for the 3 angles.  For ALL other angles, the user can freely place it.

5) the IF statement can do what you want.  Its syntax is IF something true, do this, otherwise do something else.

The following should do what you want.  In the Y-Value cell, use this formula:  =IF(OR(Angle=0,ABS(Angle)=180),SETATREF(User.Row_1,-0.25),SETATREFEXPR(Height*-0.186))  This locks the Y-position at specified place, 0.25" below the shape.  Change value as desired.  Otherwise, the control point is free to locate.  The IF syntax is:  when angle =0,+180,-180, then lock Y-position to set value, else, let control point move freely. 

Note1:  Still requires User section.
Note2:  in indicated formula, setatrefexpr() shows 0.186 value.  Don't worry about this.  It will update when the control point is moved.
Visio 2019 Pro

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 245 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1105KB.
Tokens: post-login.
Cache hits: 13: 0.00157s for 26,764 bytes (show)
Cache misses: 2: (show)
Queries used: 16.

[Show Queries]