Inkscape.org
Creating New Extensions Rotate an object
  1. #1
    dr_erk dr_erk @dr_erk

    How do I rotate an object.

  2. #2
    inklinea inklinea @inklinea⛰️

     

    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
    

    https://inkscape.gitlab.io/extensions/documentation/source/inkex.transforms.html

  3. #3
    dr_erk dr_erk @dr_erk

    Really much appreciated, Thanks!