Macros/Impress/004

Description
It is useful to be able to copy an attribute of a currently selected shape or object to the clipboard. To that end, it is quite useful to use Python, since it is easy to find and import a popular library for copying a string to the clipboard, which would be less trivial to do using functions or libraries of LibreOffice Basic. (Andrew Pitonyak's OOME book v3 does include an example of copying to clipboard in LO Basic on p. 267 though.)

In the below macro, the currently selected object is accessed using  i.e. the zeroth element of the array of selected objects. A shape such as a com.sun.star. drawing.RectangleShape will have the attribute FillColor. The color is a single long integer, with the following mathematical definition:


 * Color Value $$=R*2^{16} + G*2^8 + B*2^0$$

where $$R,G,B$$ are 8-bit values (between 0-255) for red, green, blue. Hence, a function has to be created making use moduli and other mathematical operations to extract to the more conventional RGB standard and then to hex color code.

After accessing the FillColor attribute, the script makes use of the pyperclip module for copying to clipboard. To install pyperclip, in run

You may also need to add path of packages if LibreOffice does not find your pyperclip installation, for example as such:

LO Basic
tbc

Download ODP file

 * [[Media:Example macro to copy shape hex color to clipboard.odp| Download ODP file with this macro included. ]]