Categories > OpenTBS with DOCX >

Hiding Drawing Elements (or Groups of Elements) in Word

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: John Lawler
Date: 2012-08-01
Time: 18:24

Hiding Drawing Elements (or Groups of Elements) in Word

Hi,

I'm working on a label template where it might be nice to be able to hide several drawing elements (lines and several textboxes).  If OpenTBS/TBS can make this easy to accomplish, I'd like to learn how to do that.

I saw this thread which seemed to slightly relate to what I'm trying to do, but not specifically (it didn't mention trying to hide actual drawing elements):

  http://www.tinybutstrong.com/forum.php?thr=2659

The *most* convenient method I suppose would be to allow me to group (using the Word Selection Pane, e.g.) all of the elements that might be hidden into one group and somehow signal to TBS that if a certain variable is set, mark this entire group as hidden.

In fact, when you're in the Selection Pane, looking at all of the elements (and any groups defined on them), you can click the eyeball icon to the right, which toggles the visibility of the elements.  Skrol -- I figured you may have some simple elegant method of tapping into whatever XML attribute that button changes in Word to trigger this.

Another approach that *might* work (and lead to a smaller file size, of course) would be to *delete* all of these same elements, but I'm not sure whether I'd run into possible layout troubles with that approach.  That may work too.  So I guess whichever method might be easiest to implement (if either is possible).

My other option (in this particular case) is to just build two separate templates for the two different cases.  I'm tempted to try to roll it all into one template because the one template basically matches the other exactly, except several of the elements on the page are hidden (but everything else is in the exact position).
By: Skrol29
Date: 2012-08-02
Time: 18:04

Re: Hiding Drawing Elements (or Groups of Elements) in Word

Hi John,

I've not deeply analyzed the synopsis for Drawing elements in DOCX documents, but it seems that element <mc:AlternateContent> is often used by Ms Word to bound a set of drawing items.
And in my last test, they were as an many <mc:AlternateContent> elements as Drawing groups.

So I suggest that you try a conditional bloc defined with "block=mc:AlternateContent".
The corresponding TBS tag should be placed inside the description property of the group, or one of its items.
By: John Lawler
Date: 2012-08-08
Time: 19:22

Re: Hiding Drawing Elements (or Groups of Elements) in Word

Skrol, thanks again for your right-to-the-point assistance.

I simply grouped the objects I wanted to conditionally make disappear (using the Selection Pane feature in Word 2010, which helps speed viewing the objects and grouping and naming them), then I chose 'Format Object' from the context menu of the *group*, went to 'Alt Text' and simply plugged this into the Description field:

[onload;block=mc:AlternateContent;when [var.PkgId]='M']

Now when I test, and have my PHP variable PkgId set to 'M', it includes that group; if it's not set to M, the group does not appear in the document.

This is *exactly* what I was trying to do, and it's simple and elegant.
By: John Lawler
Date: 2013-04-26
Time: 02:37

Re: Hiding Drawing Elements (or Groups of Elements) in Word

Skrol, much later, I've got a followup question on this excellent technique for conditionally hiding drawing elements.  I'm trying to do the same thing now (in the same document, actually), only vary whether a certain element is hidden on this page (it's a single page in the template that may be repeated multiple times in a single final document) based on a *block* variable, not just a single 'onload' one for the whole merge.

E.g., I'm trying to use code like this in the drawing element description:

[b;block=mc:AlternateContent;when [var.PkgIdSub]='string1']

or

[b;block=mc:AlternateContent;when [b.PkgIdSub]='string1']

and various other permutations on that.  It's not work, I suspect you would know why off of the top of your head.  Is there any way to accomplish what I'm shooting for without resorting to a much different technique?

Thanks.
By: John Lawler
Date: 2013-04-26
Time: 21:48

Re: Hiding Drawing Elements (or Groups of Elements) in Word

I'll reply to my own on this one.  It looks like my trouble was that even though I'd tried code starting with "[b;" and "[onload", I hadn't tried the variant starting with "[onshow;".  That ended up being the key for me in this case.  So I used this code:

[onshow;block=mc:AlternateContent;when [b.PkgIdSub]='string1']

and that way, the multiple pages that were created in the 'b' block (where each record had its own possible value for column PkgIdSub) each could either remove or leave alone the particular drawing element I was controlling.