News:

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

Reference a Container from Shape, and Vice Versa

Started by manifold1978, October 16, 2023, 06:23:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

manifold1978

This feels like it should be simple but I can't figure it out.
Apologies if I'm not using the right terminology, hopefully it makes sense!
I'd post an image but I don't even know how you do that!

I have a shape which has some shape data, it's inside a container.
The container also has some shape data.

First off, I want the container's title to be whatever the value of it's "Title" field of it's own shape data is. I created this "Title" shape data, I'm not referring to the title containers have anyway.

Then, I want the value of one of the fields in the contained shape to also be what's in the "Title" field of it's parent container.

Then, where I have multiple shapes within a container, I want another field beneath the container title that adds up the values of a specific field from all of the contained shapes.

I'm also confused about what the " - Plain" means after where it says Shape Data for the container.

I feel like I've already worked out harder stuff than this. I just don't know where to start.
Can anyone give me a clue?

Thank you!

snay

For the first one, you can use CONTAINERSHEETREF(1) method to get the contianer it belongs.
However, there might be many containers, so it's better to add a category to the conainter, and then use CONTAINERSHEETREF(1, "container-category") to fiter the desired one.

manifold1978

Thanks for the reply.
I was aware of the CONTAINERSHEETREF fucntion, but I just seem to be stuck with getting it to do anything whatsoever.

I've started really simple.

Created a box.
Right click, add it to a container.
Double click in the text box, enter a field of "=CONTAINERSHEETREF(1)" in as a custom formula.

Visio says "Error in formula", and I can't proceed.

Could anyone give me a really basic exmaple of anything that at least does something, then I can get a foothold into how to work with containers?

Thanks!

wapperdude

The formua is incomplete.  As given, it knows where to look, but not what to look for.  It needs to be something like:  CONTAINERSHEETREF(1)!Height  See this for more complete details:  https://learn.microsoft.com/en-us/office/client-developer/visio/containersheetref-function
Visio 2019 Pro


Nikolay

I think it is not possible to change the container header from a shape when you drop that shape into that container with formulas only.
Just forget it. Look for another approach (such as VBA) for whatever you are trying to accomplish.

wapperdude

#6
Attached is example.  There is a large, "master" container, which has 1 member, a "sub container".  That sub container has an orange rectangle.  The orange rectange has two field inserted texts, both use the ContainerSheetRef() fcn.  When both containers were created, a User row was added, User.MyTxt.  The value given was appropriate to each container.  In the orange shape, the formulae are:  ContainersheetRef(1)!User.MyTxt and ContainersheetRef(2)!User.MyTxt.

No errors encountered.   
Visio 2019 Pro

wapperdude

#7
The previously attached example seemed to have the necessary elements to let a member shape change the header of it's container (or any other container for that matter) from within the shapesheet without using code.

Attached updated file accomplishes that.  But, it's not a simple Easy button solution.  Basically, do the changes previously described in Replt#6. Then, select the header shape.  Do a field insert custom formula that points to the User.MyTxt of the Container shape.  If you then change the User.MyTxt entry, it should show up in the header.

Now, in the rectange shape that is a member of this container, open shapesheet.  Make the following modifications:
1) Add a shape data entry for text.  In my example, it is Prop.Header.  This will be one way of pushing text from the rectangle into the Container Header.
2) For convenience, in the Event section, double click cell, add DOCMD(1312).  This allows you to double click the rectangle and bring up the shape data dialog form.
3) Add an User row.  In my example, I called it User.Header.  This has a SETATREF() formula.  It needs to be copied exactly as is.  When, the shape data is changed by the form, this formula pushes the result, via SETF into the Container User.MyTxt.  From there, the preceding work pushes the text into the header.

I also added a 2nd page.  The formula in the rectangle User section was modified, and is a more traditional SETATREF() construction.  The 1st page was borrowed from a previous effort, and the rationale for that formula doesn't apply here.

This is not something that is cookie cutter.
Enjoy

Visio 2019 Pro

manifold1978


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: 295 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1158KB.
Tokens: post-login.
Cache hits: 14: 0.00266s for 26,740 bytes (show)
Cache misses: 4: (show)
Queries used: 16.

[Show Queries]