Interactive Draw objects - draw:custom-shape

How to pass parameters from cells in a Calc document embedded in a Draw document to change the position of a line?

I am using LO 7.4 in Ubuntu 20.4.

I have tried editing the .fodg file to accept variables in the svg:x2 and svg:y2 parameters in the draw:line element of draw:custom-shape with no luck.

Can someone please help me out with the syntax here? (snippet below)

<draw:line draw:style-name="gr2" draw:text-style-name="P1" draw:layer="layout" svg:x1="14cm" svg:y1="11.75cm" svg:x2="9.75cm" svg:y2="5cm">


Andy K

OK, I think I found the answer by using;

draw:type = “non-primitive”

Some of the commands in the attributes seem to accept parameters and variables. I’ll see how it goes and will report back with my findings.

If your are going to define your own shapes by tweaking the markup in the file, then you should have a look at the book “Custom Shape Tutorial” on English documentation | LibreOffice Documentation - LibreOffice User Guides

1 Like

That’s what I’ve been using, but I’m quite new to it.
After I posted I went back to this book and dived deeper. I think I’m OK with the mechanics of handles - I’m now grappling with passing values from an embedded Calc spreadsheet into the various attributes.
Thanks for your reply.

That will be difficult. There is no direct way for the spreadsheet to push values to the shape and no direct way for the shape to pull values from the spreadsheet. You will need macros to make the shape aware of the spreadsheet values.

1 Like

In pursuit of this question I reconsidered some ideas - and had to accept strange experiences, one of them that exactly the same code running a fourth or fifth time comes up with the expected results while it failed before. ( No changes actually made to the documents.)

Anyway: Only speaking of ordinary shapes I can get in a Calc DrawPage, I need user code to synchronize property values with cell results. It would now be helpful to be able to transfer such a “sheet-controlled” shape to Draw or Writer whether from an embedded sheet or otherwise, and this seems complicated. In specific I can’t use the XTransferable due to bug tdf#151713. Do you (@Regina) know remedy?

No sorry, I’m no expert in macros. Do you have tried .uno:Copy and .uno:Paste via dispatcher?

Yes - I’m discovering the difficulty.
I’m presently thinking to Dim a global variable and refer to it in draw:formula. I’ve got that bit partly working. Now I’m trying to figure out how to assign a spreadsheet value to the global variable. I’m thinking, named rages, perhaps, but I might have to get into the Calc XML.

It’s not “macro” to my perception, but API, and the respective documentation describes services and interfaces (and a bit more). If the service is documented as exporting the interface XTransferableSupplier, it should actually do.
Your idea to dodge the issue using the dispatcher was worth a try, of course:

Sub tryAsReginaSuggested()
dhlp    = CreateUnoService("")
shsDoc  = ThisComponent
shsCtrl = shsDoc.CurrentController
shsFr   = shsCtrl.Frame
drwDoc  = StarDesktop.loadComponentFromUrl("private:factory/sdraw", "_blank", 0, Array())
drwCtrl = drwDoc.CurrentController
drwFr   = drwCtrl.Frame
dhlp.executeDispatch(shsFr, ".uno:Copy",  "", 0, Array())
dhlp.executeDispatch(drwFr, ".uno:Paste", "", 0, Array())
dhlp.executeDispatch(shsFr, ".uno:Paste", "", 0, Array())
End Sub

runs without an error and places a twin of the originally selected single shape into the sheet, but the drawing remains “clean”. Sorry. In a next try it worked as expected: Also the slide got a copy. Am I getting crazy?

Why? Open the Calc document with Calc, read the values you need from the cells, and do whatever is needed with them. I don’t see any reason to tamper with the persistent representation.

A few years ago I made a sheet where I entered/calculated the coordinates for the points of a PolyPolygonShape and created and inserted that shape into the sheet’s DrawPage. No problem.
If you are interested I surely can find that thing again (but not now, and probably not tomorrow).
My concern:
I needed examples to test an algorithm that counted the half-wraps of a point with a non-simple polygon.

If I understand you correctly, your suggestion consists of a manual operation.
My requirement is for a shape to respond automatically to changes in a spreadsheet.

The best way to “get into a Calc” document imo isn’t to analyze the XML contained in the dead file, but to open the file with Calc, and to look with well shaped API tools on its objects. This is the same whether you start the process manually or by user code. If doing it by code, the method .loadComponentFromURL does the XML parsing for the “live analysis”. What tool would you use for the “dead-file-analysis”?.

Sorry. I can’t get a consistent interpretation of your intentions.