Categories > OpenTBS with DOCX >

Extent of ope=changepic?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Sarah
Date: 2013-01-18
Time: 21:18

Extent of ope=changepic?

I am trying to use docx's for my subtemplates so they can be more easily maintained. I cannot figure a way to use the docx directly, so I am extracting the document.xml and using that with getpart to get the section I need. This works, but the section I want contains an image. When I include the xml, the image is obviously not attached to my main template automatically, so I am trying to use ope=changepic to tell the main template to include the image I want (basically switching in the same image that is already in the subtemplate). The section I am grabbing from the subtemplate is <mc:alternateContent> and there is no room for text inside. So I added the ope=changepic tag to my main template like this:

<w:r>[LineItem.template;block=w:r;file=[val];getpart=(mc:AlternateContent);noerr;if '[val]'=='default';then '';else 'templates/[val].xml';]
  <w:t>
    [LineItem_sub5;block=w:t;p1]
    [LineItem_sub5.fullname;ope=changepic;default=current;noerr;]
  </w:t>
</w:r>

This results in an error (even with noerr included) :
  TinyButStrong Error OpenTBS Plugin: Parameter ope=changepic used in the field [LineItem_sub5.fullname] has failed to found the picture. The process is ending, unless you set NoErr property to true.

The structure of the subtemplate being included is essentially:

<mc:AlternateContent>
  <mc:Choice ..>
    <pic:pic>
    </pic:pic>
  </mc:Choice ...>
  <mcChoice ...>
    <v:shape>
      <imagedata/>
    </v:shape>
  </mcChoice ...>
</mc:AlternateContent>

My goal is to run ope=changepic on both the v:shape and the pic:pic (replacing the image in both Word 2007 and Word 2010).

I also tried putting the changepic tag inside a textbox within the <mc:AlternateContent> tag inside the subtemplate with the same result.

So my question is, how close does the ope=changepic have to be to the picture to find it? In both cases, my changepic is placed later than the images in the code.

Thanks for reading, any help is welcome.
By: Skrol29
Date: 2013-01-18
Time: 23:24

Re: Extent of ope=changepic?

Hi Sarah,

You're pushing TBS to the limits :-) You'll be soon an expert. Join the team ?

In your case,  the sub-block [LineItem_sub5] should be merged after [LineItem.template]. So its should be good.
Are you sure you've got as many "ope=changepic" as image elements ? [LineItem_sub5] seems to be a sub-block that can have several items for one sub-template.
You can check the XML by deactivating the automatic sub-block. Like this : [xLineItem_sub5;block=w:t;p1] ... [xLineItem_sub5.fullname]


By: Sarah
Date: 2013-01-19
Time: 00:41

Re: Extent of ope=changepic?

Thanks for your quick response!

I am trying - it seems there is always more to learn. I am trying to help around the forums, but I don't have your expertise. I don't know what help I can offer, but I am willing to try.

LineItem_sub5 is actually only set up as a subblock so that it will merge after LineItem.template. It always has only one element (is there a better way to do this?). There are two pictures though, since there is one pic:pic for Word 2010 and one v:shape for Word 2007. It didn't occur to me to think of them as two pictures needing two ope=changepics until you mentioned it... I have since tried adding a second changepic tag (which I can see merges correctly when I print the value instead of adding the changepic part) with the same result.

I used the [xLineItem] method you suggested (thank you, by the way, that is a helpful technique) and looked at my XML. I had 21 "v:imagedata"s, 21 "pic:pic"s and 21 "changepic"s - so it looks like I have enough to go around, but I still get the same error when I allow the tags to merge.

The only way I have been able to get it to replace the images correctly is to put the changepic in between <pic:pic> and </pic:pic> (same for v:shape). Is there maybe a way to replace all the pictures in the subtemplate or to switch them by title or description like with OPENTBS_CHANGE_PICTURE?

Thanks again for your response.
By: Skrol29
Date: 2013-01-21
Time: 16:58

Re: Extent of ope=changepic?

Hi,

> LineItem_sub5 is actually only set up as a subblock so that it will merge after LineItem.template.
> It always has only one element (is there a better way to do this?)

Well, if you want only one element to display, you can replace the [LineItem_sub5] tags with:
   [LineItem.the_sub5_column.0.fullname;ope=changepic;default=current;noerr]

There are two pictures though, since there is one pic:pic for Word 2010 and one v:shape for Word 2007.
I think the two XML element are not necessary, only one of them should be enough. Word 2007 should display the picture correctly but may not support all styles en effects of Word 2010.
You should try with only one XML element until you have a solution that works .And then, eventually, try with two, but I not recommended that.

OpenTBS always try to find a <v:imagedata> (Word 2007) element first, and if it not succeed then it tries for <a:bli> (Word 2010 and higher).
Your two elements should be ok with this, but it may have border effects if something else is going wrong.

> I used the [xLineItem] method you suggested (thank you, by the way, that is a helpful technique)
> and looked at my XML. I had 21 "v:imagedata"s, 21 "pic:pic"s and 21 "changepic"s
> - so it looks like I have enough to go around, but I still get the same error when I allow the tags to merge.

Try to deactivate the "changepic" action like this: [LineItem_sub5.fullname;xope=changepic;default=current;noerr;]
And check if the merged XML is as expected.

> The only way I have been able to get it to replace the images correctly is to put the changepic in between <pic:pic> and </pic:pic> (same for v:shape).

Strange.

> Is there maybe a way to replace all the pictures in the subtemplate or to switch them by title or description like with OPENTBS_CHANGE_PICTURE?

I don't understand.
By: Sarah
Date: 2013-01-21
Time: 19:41

Re: Extent of ope=changepic?

I tried replacing my Line_sub5 with [LineItem.images.0.fullname] but the tag does not merge because this is in a subtemplate that gets merged after LineItem, as I understand it. That is actually why I made this one item array (images) - so that I could have a subblock that would be processed after LineItem. I also tried [onshow.quote.items[LineItem.$].images.0.fullname] but that gets me errors that '[LineItem' is not a key in the array (because [LineItem.$] never gets processed).

Unfortunately. I have found that both picture elements are required for my project. I am using the drawing canvas as a container for my images (and the rest of my diagram) because I need the editing stability it lends (have you tried nudging groups of images in Word with the arrow keys outside of the canvas? It all goes unpredictable and diagonal). I am using the 2010 format (not compatibility mode) because the new features (like rotating a group that contains a textbox and resizing a textbox separate from the group that contains it) are extremely helpful for my project. However, the new format in 2010 uses WPC (?) which does not work in 2007, therefore it also includes a 2007 compatible version of the canvas (hence the mc:alternateContent tag, and the two copies of the same image). I actually did have a working version with one image, but that was several versions back now. I tried getting just one image to merge in this version and the tag merged but the image did not get added (unless I put the tag inside of the image tags, which works even for two).

>> Is there maybe a way to replace all the pictures in the subtemplate or to switch them by title or description like with OPENTBS_CHANGE_PICTURE?

>I don't understand.

I meant, the documentation for OpenTBS 1.8.0 (Beta) says that:
$PicRef must be a string that is saved in the Title or the Description of the picture. If several pictures have the same key string then
they are all replaced with the picture.
So I was wondering if using some kind of string in the title or description tag would allow the ope=changepic to find the image. However, when I went to look this up, I rediscovered the tagpos=inside option which is way better! I tried adding:

[LineItem_sub5;block=v:shape;p1;][LineItem_sub5.fullname;ope=changepic;default=current;tagpos=inside;noerr;]

to the alt attribute of the v:shape (for 2007) and to the descr attribute of the pic:pic (for 2010). I also switched the block=v:shape to block=pic:pic for the different parts (in my XML). This worked beautifully. However, my goal was to make my subtemplates WYSIWYG-able so I moved to Word 2010 and tried adding my tag to the Alt Text screen (under description). This caused problems:

Problem #1) Lots of tag not found TBS errors because my block=v:shape only applies to one of the images (the other needs to be pic:pic) and Word automatically updates both images to have the same description. I either need some way to say block=v:shapeORpic:pic, or block=nearestElement, or some way to print my single element without the block= declaration (this would still need to process after LineItem.template to work in my sub template).

Problem #2) (minor) When I fill in the description field in Word 2010, it inserts the text I use into the Alt attribute of the v:shape in the 2007-compatible section, which is good. However, it also inserts part of the tag ('shape;p1;][LineItem_sub5') into the o:title attribute of the <v:imagedata> tag. This doesn't cause any problems that I have found yet, but I don't know why it is deciding to only take the middle section, or if this partial tag might cause problems eventually.

I also tried putting my tag into the Title box (rather than Description) - this filled the Title attribute of the pic:pic, but it did nothing to any attribute of the v:shape.

This made me try putting this in the title box (so it would show in the pic:pic but not the v:shape):

[LineItem_sub5;block=mc:AlternateContent;p1][LineItem_sub5.fullname;ope=changepic;default=current;tagpos=inside;noerr;]

And then put this in the description box (so it would show in the v:shape):

[LineItem_sub5.fullname;ope=changepic;default=current;tagpos=inside;noerr;]

This gave me images like this:

<pic:cNvPr id="1549" name="Picture 1585" descr="[LineItem_sub5.fullname;ope=changepic;default=current;tagpos=inside;noerr;]"
   title="[LineItem_sub5;block=mc:AlternateContent;p1][LineItem_sub5.fullname;ope=changepic;default=current;tagpos=inside;noerr;]"/> //(in the pic:pic)

//and

<v:shape id="Picture 1585" o:spid="_x0000_s1028" type="#_x0000_t75" alt="[LineItem_sub5.fullname;ope=changepic;default=current;tagpos=inside;noerr;]">
        <v:imagedata r:id="rId9" o:title="[LineItem_sub5"/>
</v:shape>

I thought this might merge ok, because the desc attribute of the pic:pic would fail to merge since it comes before the block declaration and then the other two would merge correctly (they do merge correctly if that desc attribute is not present in the pic:pic). The o:title attribute would obviously fail to merge because it is incomplete. Instead I get this new error:

TinyButStrong Error : TBS is not able to merge the field [LineItem_sub5.fullname;ope=changepic;default=current;tagpos=inside;noerr;]
because parameter 'att' makes this fied moving forward over another TBS field.

I figured this is because I have two tags inside of different attributes of the same element and TBS doesn't like that...

I ended up fixing this (yay!) by abandoning the title box and using the description box to hold this:

[LineItem_sub5;block=mc:AlternateContent;p1][LineItem_sub5.fullname;ope=changepic;default=current;tagpos=inside;noerr;]

Mc:AlternateContent is the only similar element containing both images (both versions of the same image really). I was worried about using a block definition so far away from the element I wanted to change but it seems to work (of course I'm not doing anything in multiples here, and it is never empty).

I am wondering now if in order for OpenTBS to find the image element using tagpos=after, it needs to be contained by the same block you use for the block definition? (I was using the w:t surrounding my tag, not the mc:AlternateContent surrounding my images) Would it be helpful for me to test this or is this too deep in the weeds to be of value to anyone?

Sorry about all these ridiculously long posts I keep leaving... and thank you very much for your patience and help. Being forced to organize my thoughts for a post does seem to get my problems fixed, even when I am not able to give you enough information to figure all of my problems out for me :)