<html>Are you looking to insert the caption, or the reference to the caption? I think you want to insert a reference to a dependent field for a text field master. Does this sound correct? <br /><br />The text field master, which is of type: <br /><br />com.sun.star.text.fieldmaster.SetExpression.Figure<br /><br />But you want to reference a Dependent field. If my guess is correct, this is how I insert a reference to the first Figure using Basic. Note that there is almost no error checking, so, this could go very wrong. <br /><br />Sub Main<br /> Dim oField<br /> Dim oNewField<br /> Dim oText<br /> Dim oCurs<br /> Dim oReferencedField<br /> Dim oEnum<br /> Dim oDispatcher ' Dispatcher object.<br /> Dim oFrame<br /><br /> ' Setup to perform a dispatch.<br /> oFrame = ThisComponent.CurrentController.Frame<br /> oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")<br /><br /> oText = ThisComponent.getText()<br /> oCurs = ThisComponent.CurrentController.getViewCursor()<br /><br /> oEnum = ThisComponent.getTextFields().createEnumeration()<br /> If Not IsNull(oEnum) Then<br /> Do While oEnum.hasMoreElements()<br /><br /><br /> oField = oEnum.nextElement()<br /> 'Inspect oField<br /> If oField.supportsService("com.sun.star.text.TextField.SetExpression") Then<br /> If oField.VariableName = "Figure" Then<br /> Print "Found one"<br /> Exit Do<br /> End If<br /> End If<br /> Loop<br /> End If<br /><br /> ' No error checking, I just assume that I found one. DANGER DANGER DANGER<br /><br /><br /> oNewField = ThisComponent.createInstance("com.sun.star.text.textfield.GetReference")<br /> oNewField.ReferenceFieldPart = com.sun.star.text.ReferenceFieldPart.CATEGORY_AND_NUMBER<br /> oNewField.ReferenceFieldSource = com.sun.star.text.ReferenceFieldSource.SEQUENCE_FIELD<br /> oNewField.SequenceNumber = oField.SequenceValue<br /> oNewField.SourceName = "Figure"<br /> oText.insertTextContent(oCurs, oNewField, True)<br /> <br /> ' This next part will NOT work until after all of the fields have updated.<br /> ' So, force an update.<br /> oDispatcher.executeDispatch(oFrame, ".uno:UpdateFields", "", 0, Array())<br />End Sub<br /><br /><br />On Thursday, September 05, 2019 10:59 EDT, LORENZO Vincent <vincent.lorenzo@cea.fr> wrote:<br /> <blockquote type="cite" cite="5F1D688F935F194EB6A8D80D5BB99FCF73302263@EXDAG0-B0.intra.cea.fr">Hello everybody,<br />Since my last question, I switched task. Now I come back to my LibreOffice task to resolve my caption problem.<br />I'm still blocked on this problem. I get a different result compared to my last email, but the reference for the caption is still not found.<br />I replace Illustration by Figure, but the problem keeps the same.<br /><br />I obtain a text:sequence-ref instead of a text:sequence. Does someone know why or which is the API to use to generate a text:sequence...<br /><br />My result for the numbering of the caption:<br /><text:sequence-ref text:reference-format="value" text:ref-name="refFigure0">Erreur : source de la référence non trouvée</text:sequence-ref> (the french text said "reference not found")<br /><br />I would like to get :<br /><text:sequence text:ref-name="refFigure0" text:name="Figure" text:formula="ooow:Figure+1" style:num-format="1">1</text:sequence><br /><br />My java code for that :<br /><br />Object oReference = xMultiServiceFactory.createInstance("com.sun.star.text.textfield.GetReference");<br />XPropertySet oReferencePropertySet = UnoRuntime.queryInterface(XPropertySet.class, oReference);<br />oReferencePropertySet.setPropertyValue("SourceName", "Figure");// I get <text:sequence-ref<br />oReferencePropertySet.setPropertyValue("ReferenceFieldPart", ReferenceFieldPart.ONLY_SEQUENCE_NUMBER);<br />oReferencePropertySet.setPropertyValue("ReferenceFieldSource", ReferenceFieldSource.SEQUENCE_FIELD);<br />oReferencePropertySet.setPropertyValue("SequenceNumber", 0);// (short) 2);//not requireed ?<br />XTextContent xRef = UnoRuntime.queryInterface(XTextContent.class, oReference);<br />localCursor.getText().insertTextContent(localCursor, xRef, false);<br /><br />Regards,<br />--<br />Vincent Lorenzo<br /><br /><br />-----Message d'origine-----<br />De : LibreOffice <libreoffice-bounces@lists.freedesktop.org> De la part de LORENZO Vincent<br />Envoyé : vendredi 15 février 2019 14:37<br />À : Kaganski Mike <mikekaganski@hotmail.com>; Miklos Vajna <vmiklos@collabora.com>; sos <sos@pmg.be><br />Cc : libreoffice@lists.freedesktop.org<br />Objet : [PROVENANCE INTERNET] RE: need help to insert an image with a caption with the Libo java API<br /><br />Hello everybody,<br />I thank you for your answers. Yes I want to add an image with a caption programmatically and I want a caption like this "Illustration 1 : My caption"<br />To my mind, it would be better/cleaner if I was able to generate the same thing than I do the UI. Thanks to you, I succeed to build the expected structure for the image and to set a text below it, but I still have some problems, mainly with the GetReference.<br /><br />The GetReference generates :<br /><text:reference-ref text:reference-format="text" text:ref-name="refIllustration0">Erreur : source de la référence non trouvée</text:reference-ref> (sorry my Libo is in French, it is written "Sorry : source of the reference not found").<br /><br />And I would like to get a text:sequence instead of a text:reference, to get this result:<br /><text:sequence text:ref-name="refIllustration0" text:name="Illustration" text:formula="ooow:Illustration+1" style:num-format="1">1</text:sequence><br /><br />Please, do you know how I can build a text:sequence ?<br /><br />Please found in attachment the java code I wrote [1], the expect xml structure [2] and the current xml structure [3].<br />I know I have some difference between [2] and [3] with the width/height properties and inside the draw frame, but it is not the subject of this thread.<br /><br />[1] insertImage.java<br />[2] expectedResult.xml<br />[3] currentResult.xml<br /><br />In addition, I have more generic question, do you know if it exists a documentation, indicating mapping, between the xml elements and how to get/create them from java ? For example, in xml svg:width is called Height in the java API, and my Textframe becomes <draw:text-box...<<br /><br />Best regards,<br />--<br />Vincent Lorenzo<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />-----Message d'origine-----<br />De : Kaganski Mike [mailto:mikekaganski@hotmail.com]<br />Envoyé : mercredi 13 février 2019 11:42<br />À : Miklos Vajna <vmiklos@collabora.com>; LORENZO Vincent <vincent.lorenzo@cea.fr><br />Cc : libreoffice@lists.freedesktop.org<br />Objet : Re: need help to insert an image with a caption with the Libo java API<br /><br />On 13.02.2019 12:45, Miklos Vajna via LibreOffice wrote:<br />> Hi,<br />><br />> On Tue, Feb 12, 2019 at 09:27:15AM +0000, LORENZO Vincent <vincent.lorenzo@cea.fr> wrote:<br />>> I would like to add a caption, to an inserted image in a text<br />>> document, but I don't find how to do that... Please do you have<br />>> pointer/documentation for me ?<br />><br />> I think captions are just a UI feature. The doc model just stores a<br />> text frame around the image and the image is followed by the caption itself.<br />><br />> (I.e. later it's not possible to reliably detect if some content<br />> around an image in a frame was created by hand or using the captions<br />> UI code.)<br />><br />> So you can do the same "manually" using the UNO API. When in doubt,<br />> see what UNO API the ODT import uses to create the doc model based on<br />> the input markup.<br /><br />And actually, if an image is not intended to be floating, but (as seen in majority of cases) is a part of normal text flow, then the frame could be not needed at all - simply add an image anchored as character, then add a paragraph with required style and numbering range field, then continue with other paragraphs. This makes the document structure clearer. Just an advise based on own experience.<br /><br />--<br />Best regards,<br />Mike Kaganski<br />_______________________________________________<br />LibreOffice mailing list<br />LibreOffice@lists.freedesktop.org<br />https://lists.freedesktop.org/mailman/listinfo/libreoffice</blockquote><br /><br /><br /> </html>