selection_list = self.svg.selected
if len(selection_list) < 1:
inkex.errormsg('nothing selected')
return
# Import the python random range function
from random import randrange
# Import the inkex Transform module
from inkex import Transform
for item in selection_list:
# Get the bounding box of the item
# This will not work for Text objects
item_bbox = item.bounding_box()
# Get a random rotation value
random_rotation_degrees = randrange(0, 360)
# Create a Transform object
rotate_transform = Transform()
# Add the transform degrees and centre to the object
rotate_transform.add_rotate(random_rotation_degrees, item_bbox.center)
# Multiply the existing object Transform by the Rotation Transform
item.transform = item.transform @ rotate_transform
How do I rotate an object.
https://inkscape.gitlab.io/extensions/documentation/source/inkex.transforms.html
Really much appreciated, Thanks!