0

I need to get the number of lines on a slide. To access the lines, I am using MSO_CONNECTOR as it is not an AUTO_SHAPE. However when I run the below it returns an None value for some reason. How can I know if a shape is a line or not? (tried using is_connector also returned an error)

def get_number_of_lines(slide):
    lines = 0
    for shape in slide.shapes:
        if shape.shape_type == MSO_CONNECTOR:
           print('it is a line')
           lines = lines + 1 

    return lines
Rami.K
  • 189
  • 2
  • 11

2 Answers2

1

Hmm, interesting. It looks like we left the .shape_type property off of the Connector object. I'll add an issue to get that fixed up.

In the meantime, you can check for a distinctive Connector property, like .begin_x:

def is_connector(shape):
    """Return True if `shape` is a connector (line), False otherwise."""
    return hasattr(shape, "begin_x")
scanny
  • 26,423
  • 5
  • 54
  • 80
0

Looks like MSO_CONNECTOR's attribute should be used to compare. for ex)

if shape.shape_type == MSO_CONNECTOR.STRAIGHT:
Chong Yu
  • 470
  • 3
  • 8
  • Same problem.. it doesn't catch it... I am adding manually lines in ppt and saving the file and then running the code above (including yours) and it doesn't catch any lines.. thanks – Rami.K Jul 02 '19 at 03:13
  • may need to iterate over the `Connector`s? https://python-pptx.readthedocs.io/en/latest/api/shapes.html#connector-objects – David Zemens Jul 02 '19 at 17:42