LibreOffice problems drawing hash marks in shape using Python
Question: I am trying to create a hash mark pattern inside a shape using LibreOffice 5
on Windows 10 using the Python 3.3 that came with LibreOffice. Two thirds of
the code is similar to this
[post](http://stackoverflow.com/questions/36852645/create-flowchart-in-
libreoffice-using-python) with additional questions about creating hash marks
at the end of the code listing.

This is the Python code I tried.

    
    
    import sys
    print(sys.version)
    
    import socket
    import uno
    
    # get the uno component context from the PyUNO runtime
    localContext = uno.getComponentContext()
    
    # create the UnoUrlResolver
    resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext )
    
    # connect to the running office
    ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
    smgr = ctx.ServiceManager
    
    # get the central desktop object
    desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
    model = desktop.getCurrentComponent()
    
    # Create the shape
    def create_shape(document, x, y, width, height, shapeType):
        shape = model.createInstance(shapeType)
        aPoint = uno.createUnoStruct("com.sun.star.awt.Point")
        aPoint.X, aPoint.Y = x, y
        aSize = uno.createUnoStruct("com.sun.star.awt.Size")
        aSize.Width, aSize.Height = width, height
        shape.setPosition(aPoint)
        shape.setSize(aSize)
        return shape
    
    def formatShape(shape):
        shape.setPropertyValue("FillColor", int("FFFFFF", 16))  # blue
        shape.setPropertyValue("LineColor", int("000000", 16))  # black
    
        aHatch = uno.createUnoStruct("com.sun.star.drawing.Hatch")
        #HatchStyle = uno.createUnoStruct("com.sun.star.drawing.HatchStyle")
        #aHatch.Style=HatchStyle.DOUBLE;
        aHatch.Color=0x00ff00
        aHatch.Distance=100
        aHatch.Angle=450
    
        shape.setPropertyValue("FillHatch", aHatch)
        shape.setPropertyValue("FillStyle", "FillStyle.DOUBLE")
    
    shape = create_shape(model, 0, 0, 10000, 10000, "com.sun.star.drawing.RectangleShape")
    formatShape(shape)
    
    drawPage.add(shape)
    

This code should set a double crosshatch pattern inside a rectangle but no
pattern shows ups inside the rectangle.

    
    
    aHatch = uno.createUnoStruct("com.sun.star.drawing.Hatch")
    #HatchStyle = uno.createUnoStruct("com.sun.star.drawing.HatchStyle")
    #aHatch.Style=HatchStyle.DOUBLE;
    aHatch.Color=0x00ff00
    aHatch.Distance=100
    aHatch.Angle=450
    
    shape.setPropertyValue("FillHatch", aHatch)
    shape.setPropertyValue("FillStyle", "FillStyle.DOUBLE")
    

The line to set the hatch style pattern:

    
    
    uno.RuntimeException: pyuno.getClass: 
    

Fails with the following error

    
    
    com.sun.star.drawing.HatchStyleis a ENUM, expected EXCEPTION,
    

Here are some links to
[Java](https://svn.apache.org/repos/asf/openoffice/trunk/test/testuno/source/fvt/uno/sd/shape/ShapeProperties.java)
and
[BASIC](https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Structure_of_Drawings)
examples I used for reference.


Answer: > HatchStyle = uno.createUnoStruct("com.sun.star.drawing.HatchStyle")

This fails because
[HatchStyle](http://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1drawing.html#a021284aa8478781ba1b958b81da7b608)
is an
[Enum](https://wiki.openoffice.org/wiki/Python/Transfer_from_Basic_to_Python#Enum),
not a
[Struct](https://wiki.openoffice.org/wiki/Python/Transfer_from_Basic_to_Python#Struct_Instance).
To use the HatchStyle enum, follow one of the three ways in the python example
from the Enum link.

> shape.setPropertyValue("FillStyle", "FillStyle.DOUBLE")

It looks like you are confusing "FillStyle.HATCH" and "HatchStyle.DOUBLE" from
the example. This is what the code should be in Python:

    
    
    from com.sun.star.drawing.FillStyle import HATCH
    shape.setPropertyValue("FillStyle", HATCH)
    

This seems to be missing as well:

    
    
    drawPage = model.getDrawPages().getByIndex(0)
    

