Connector
Contents
[
Hide
]
This article demonstrates how to connect shapes with connectors and change their targets using Aspose.Slides for Python via Java.
Install the package as described in Installation. Each example imports asposeslides before starting the JVM, then imports the API after the JVM is running.
Add a Connector
Insert a connector shape between two points on the slide.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
connector = slide.getShapes().addConnector(ShapeType.BentConnector2, 0, 0, 100, 100)
finally:
presentation.dispose()
Access a Connector
Retrieve the first connector shape added to a slide.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Connector, Presentation, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
slide.getShapes().addConnector(ShapeType.BentConnector2, 0, 0, 100, 100)
# Access the first connector on the slide.
connector = None
for index in range(slide.getShapes().size()):
shape = slide.getShapes().get_Item(index)
if isinstance(shape, Connector):
connector = shape
break
finally:
presentation.dispose()
Remove a Connector
Delete a connector from the slide.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
connector = slide.getShapes().addConnector(ShapeType.BentConnector2, 0, 0, 100, 100)
slide.getShapes().remove(connector)
finally:
presentation.dispose()
Reconnect Shapes
Attach a connector to two shapes by assigning start and end targets.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
shape1 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 0, 0, 50, 50)
shape2 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 50, 50)
connector = slide.getShapes().addConnector(ShapeType.BentConnector2, 0, 0, 100, 100)
connector.setStartShapeConnectedTo(shape1)
connector.setEndShapeConnectedTo(shape2)
finally:
presentation.dispose()