Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active May 10, 2023 11:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/091486327848348c105b79e1bf2b16a7 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/091486327848348c105b79e1bf2b16a7 to your computer and use it in GitHub Desktop.
Lock or Unlock PowerPoint Presentations in Python
# load presentation
with slides.Presentation("presentation.pptx") as pres:
# loop through all the slides in the presentation
for slide in pres.slides:
for shape in slide.shapes:
# if shape is autoshape
if type(shape) is slides.AutoShape:
auto_shape_lock = shape.shape_lock
# apply locks
auto_shape_lock.position_locked = True
auto_shape_lock.select_locked = True
auto_shape_lock.size_locked = True
# if shape is group shape
elif type(shape) is slides.GroupShape:
group_shape_lock = shape.shape_lock
# apply locks
group_shape_lock.grouping_locked = True
group_shape_lock.position_locked = True
group_shape_lock.select_locked = True
group_shape_lock.size_locked = True
# if shape is a connector
elif type(shape) is slides.Connector:
connector_lock = shape.shape_lock
# apply locks
connector_lock.position_move = True
connector_lock.select_locked = True
connector_lock.size_locked = True
# if shape is picture frame
elif type(shape) is slides.PictureFrame:
picture_lock = shape.shape_lock
# apply locks
picture_lock.position_locked = True
picture_lock.select_locked = True
picture_lock.size_locked = True
# save the presentation file
pres.save("Locked.pptx", slides.export.SaveFormat.PPTX)
# load presentation
with slides.Presentation("Locked.pptx") as pres:
# loop through all the slides in the presentation
for slide in pres.slides:
for shape in slide.shapes:
# if shape is autoshape
if type(shape) is slides.AutoShape:
auto_shape_lock = shape.shape_lock
# remove locks
auto_shape_lock.position_locked = False
auto_shape_lock.select_locked = False
auto_shape_lock.size_locked = False
# if shape is group shape
elif type(shape) is slides.GroupShape:
group_shape_lock = shape.shape_lock
# remove locks
group_shape_lock.grouping_locked = False
group_shape_lock.position_locked = False
group_shape_lock.select_locked = False
group_shape_lock.size_locked = False
# if remove is a connector
elif type(shape) is slides.Connector:
connector_lock = shape.shape_lock
# remove locks
connector_lock.position_move = False
connector_lock.select_locked = False
connector_lock.size_locked = False
# if shape is picture frame
elif type(shape) is slides.PictureFrame:
picture_lock = shape.shape_lock
# remove locks
picture_lock.position_locked = False
picture_lock.select_locked = False
picture_lock.size_locked = False
# save the presentation file
pres.save("Unlocked.pptx", slides.export.SaveFormat.PPTX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment