이 문서에서는 Python에서 ORG 차트를 만드는 방법을 설명합니다. 시스템 설정, 단계별 프로세스 및 실행 가능한 코드 샘플을 포함하여 Python에서 조직도 생성기를 개발하는 방법을 안내합니다. 또한 조직도를 사용자 지정하고 VSDX 또는 VSD 형식으로 내보낼 수도 있습니다.
Python에서 ORG 차트를 만드는 단계
- ORG 차트를 생성하기 위해 Aspose.Diagram을 시스템에 설정
- Diagram 클래스의 인스턴스를 생성하고 샘플 스텐실에서 마스터 셰이프 로드
- 필요한 셰이프를 추가하고 서로 다른 노드 간의 연결 삽입
- LayoutOptions 클래스를 사용하여 다양한 차트 속성을 설정하고 ORG 차트 렌더링
위의 단계는 Python에서 조직도 생성기를 개발하는 워크플로우를 설명합니다. 먼저 시스템을 설정하고 샘플 스텐실 파일에서 마스터 셰이프를 로드합니다. 그런 다음 조직도의 대상 셰이프와 연결을 추가한 후, 최종적으로 출력 다이어그램을 생성합니다.
Python에서 ORG 차트 생성기 만들기 코드
import aspose.diagram | |
from aspose.diagram import * | |
path = "C://" | |
# Load masters from any existing diagram, stencil or template | |
visioStencil = path + "BasicShapes.vss" | |
rectangleMaster = "Rectangle" | |
connectorMaster = "Dynamic connector" | |
pageNumber = 0 | |
width = 1.0 | |
height = 1.0 | |
pinX = 4.25 | |
pinY = 9.5 | |
# Define values to construct the hierarchy | |
listPos = ["0", "0:0", "0:1", "0:2", "0:3", "0:4", "0:5", "0:6", "0:0:0", "0:0:1", "0:3:0", "0:3:1", "0:3:2", "0:6:0", "0:6:1"] | |
# Define a dictionary to map the string name to long shape id | |
shapeIdMap = {} | |
# Create a new diagram | |
diagram = Diagram(visioStencil) | |
diagram.pages[pageNumber].page_sheet.page_props.page_width.value = 11.0 | |
for orgnode in listPos: | |
# Add a new rectangle shape | |
rectangleId = diagram.add_shape(pinX, pinY, width, height, rectangleMaster, pageNumber) | |
pinX += 1 | |
pinY += 1 | |
# Set the new shape's properties | |
shape = diagram.pages[pageNumber].shapes.get_shape(rectangleId) | |
shape.text.value.add(Txt(orgnode)) | |
shape.name = orgnode | |
shapeIdMap[orgnode] = rectangleId | |
# Create connections between nodes | |
for orgName in listPos: | |
lastColon = orgName.rfind(':') | |
if lastColon > 0: | |
parentName = orgName[:lastColon] | |
shapeId = shapeIdMap[orgName] | |
parentId = shapeIdMap[parentName] | |
connector1 = Shape() | |
connecter1Id = diagram.add_shape(connector1, connectorMaster, pageNumber) | |
diagram.pages[pageNumber].connect_shapes_via_connector(parentId, manipulation.ConnectionPointPlace.RIGHT, | |
shapeId, manipulation.ConnectionPointPlace.LEFT, connecter1Id) | |
# Auto layout CompactTree chart | |
compactTreeOptions = autolayout.LayoutOptions() | |
compactTreeOptions.layout_style = autolayout.LayoutStyle.COMPACT_TREE | |
compactTreeOptions.direction = autolayout.LayoutDirection.DOWN_THEN_RIGHT | |
compactTreeOptions.enlarge_page = False | |
diagram.pages[pageNumber].layout(compactTreeOptions) | |
# Save diagram | |
diagram.save("ORGchart_out.vsdx", SaveFileFormat.VSDX) |
이 코드 스니펫은 Python에서 조직도 빌더를 만드는 기능을 보여줍니다. 하지만 셰이프의 개수나 순서, 커넥터 방향 및 위치 등을 조정하여 개선할 수 있습니다. 또한 부모 셰이프 ID 및 기타 속성을 조작하여 노드 셰이프 및 연결을 맞춤 설정할 수도 있습니다.
이 빠른 가이드를 통해 Python에서 조직도 제작기를 만드는 방법을 배웠습니다. Visio 다이어그램을 처음부터 생성하는 방법에 관심이 있다면, Python에서 Visio 다이어그램 만들기 문서를 참고하세요.