Draw Direct Shape Position Size - Rotation
The ooodev.format.draw.direct.position_size.rotation.Rotation
class is used to modify the values seen in Fig. 866 of a shape.
Setup
from __future__ import annotations
import uno
from ooodev.draw import Draw, DrawDoc, ZoomKind
from ooodev.loader.lo import Lo
from ooodev.format.draw.direct.position_size.rotation import Rotation
from ooodev.units import Angle100
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = DrawDoc(Draw.create_draw_doc())
doc.set_visible()
Lo.delay(500)
doc.zoom(ZoomKind.ZOOM_75_PERCENT)
slide = doc.get_slide()
width = 36
height = 36
x = round(width / 2)
y = round(height / 2)
rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
style = Rotation(rotation=45)
style.apply(rect.component)
f_style = Rotation.from_obj(rect.component)
assert f_style is not None
assert f_style.prop_rotation == Angle100(4500)
Lo.delay(1_000)
doc.close_doc()
return 0
if __name__ == "__main__":
raise SystemExit(main())
Fig. 866 Shape Rotation Dialog
Set Rotation of a Shape
Setting rotation of the shape is done by using the Rotation
class.
from ooodev.format.draw.direct.position_size.rotation import Rotation
# ... other code
rect = slide.draw_rectangle(
x=x, y=y, width=width, height=height
)
style = Rotation(rotation=45)
style.apply(rect.component)
The results of the setting the shape rotation can be seen in Fig. 867.
Fig. 867 Text Shape with Rotation set
Get Shape Rotation
We can get the Adapt properties of the shape by using the Rotation.from_obj()
method.
from ooodev.format.draw.direct.position_size.rotation import Rotation
from ooodev.units import Angle100
# ... other code
# get the properties from the shape
f_style = Rotation.from_obj(rect.component)
assert f_style.prop_rotation == Angle100(4500)