Gope
February 6, 2024, 9:18am
1
Hello
I get problems when Kenneth adding name to shapes in Asbose Diagram for python
code:
def create_visual_shape(shape_sn,shape_name_sn,page_id,xpos_sn,ypos_sn):
bpmn.getPages()
page = Page(page_id)
page.getShapes()
shape = Shape()
page= Page()
page = bpmn.getPages().getPage(page_id)
if shape_sn == "Start Event":
print("Start Event")
bpmn.addMaster(visiostencil, "Start Event")
bpmn.addShape(xpos_sn, ypos_sn, "Start Event", page_id)
page.getActiveShape().setName(shape_name_sn)
get the following:
goranpettersson@iMac Visual code v1 % /usr/local/bin/python3 “/Users/goranpettersson/Documents/Visual code v1/SNAPIV4.py”
First shape in page 11 ATF Suite Start With ID 11 0
Start Event
Traceback (most recent call last):
File “/Users/goranpettersson/Documents/Visual code v1/SNAPIV4.py”, line 407, in
create_visual_shape(“Start Event”,(logic_def[“name”]),page_id,xpos_sn,ypos_sn)
File “/Users/goranpettersson/Documents/Visual code v1/SNAPIV4.py”, line 233, in create_visual_shape
page.getActiveShape().setName(shape_name_sn)
^^^^^^^^^^^^^^^^^^^
AttributeError: ‘com.aspose.diagram.Page’ object has no attribute ‘getActiveShape’
goranpettersson@iMac Visual code v1 %
@Gope
Thanks for the sample code.
Please refer to the following code to set the name of the shape:
shapeId = bpmn.addShape(xpos_sn, ypos_sn, "Start Event", page_id)
shape = page.getShapes().getShape(shapeId)
shape.setName(shape_name_sn)
Thanks.
Gope
February 6, 2024, 11:46am
3
Hello again Philip!
Thanks for the respond!
shapeId = bpmn.addShape(xpos_sn, ypos_sn, "Start Event", page_id)
shape = page.getShapes().getShape(shapeId)
shape.setName(shape_name_sn)
But how do you get the information of the Shape_id. I suppose it is created when the shape is created.
Göran
/usr/local/bin/python3 “/Users/goranpettersson/Documents/Visual code v1/SNAPIV4.py”
goranpettersson@iMac Visual code v1 % /usr/local/bin/python3 “/Users/goranpettersson/Documents/Visual code v1/SNAPIV4.py”
First shape in page 11 ATF Suite Start With ID 11 0
Start Event
Traceback (most recent call last):
File “/Users/goranpettersson/Documents/Visual code v1/SNAPIV4.py”, line 415, in
create_visual_shape(“Start Event”,(logic_def[“name”]),page_id,xpos_sn,ypos_sn)
File “/Users/goranpettersson/Documents/Visual code v1/SNAPIV4.py”, line 217, in create_visual_shape
shape = page.getShapes().getShape(shapeId)
^^^^^^^
NameError: name ‘shapeId’ is not defined. Did you mean: ‘shape’?
goranpettersson@iMac Visual code v1 %
Gope
February 6, 2024, 12:10pm
4
Hello!
Got it! Did not see the ShapeID in the first line of your example!
BR
Göran
@Gope
Yes, We will obtain the shape ID when creating the shape.
In case you have further inquiries or may need any help in future, please let us know by posting a new thread in Aspose.Diagram’ forum.
Thanks.
Gope
February 6, 2024, 3:50pm
6
philip.zhou:
shapeId = bpmn.addShape(xpos_sn, ypos_sn, "Start Event", page_id)
shape = page.getShapes().getShape(shapeId)
shape.setName(shape_name_sn)
The code works fine but no name is presented in the Visio file
image.png (71.2 KB)
Göran
Gope
February 6, 2024, 3:53pm
8
the code
def create_visual_shape(shape_sn,shape_name_sn,page_id,xpos_sn,ypos_sn):
page= Page()
#bpmn.getPages()
#page = Page(page_id)
#page.getShapes()
shape = Shape()
page = bpmn.getPages().getPage(page_id)
if shape_sn == "Start Event":
print("Start Event")
#bpmn.addMaster(visiostencil, "Start Event")
shapeId =bpmn.addShape(xpos_sn, ypos_sn, "Start Event", page_id)
shape = page.getShapes().getShape(shapeId)
shape.setName(shape_name_sn)
#shape.setText("shape_name_sn")
Gope
February 6, 2024, 3:57pm
9
shape.setName(shape_name_sn)
print ("The shapes name: ",shape.getName())
result:
The shapes name: If
@Gope
Please open Visio’s Developer Mode, then select the shape you want to inspect to view properties such as name, ID, and more.
If you want to set the text of a shape, please refer to the following code:
shape.getText().getValue().add(Cp(0))
shape.getText().getValue().add(Txt(“Test shape text”))
//set text font properties
shape.getChars().add(Char())
shape.getChars().get(0).setIX(0)
shape.getChars().get(0).getColor().setValue(“#FFFF00 ”)
shape.getChars().get(0).getSize().setValue(0.16)
Thanks.
Gope
February 7, 2024, 5:42am
11
I checked the stylesheet for the forms. No id or no name was set. I will try your code and respond.
Gope
February 7, 2024, 7:25am
12
Works fine!
Thanks for help!
The only reflection is that start and End shapes displays the text vertically
image.png (7.9 KB)
@Gope
If the text position is incorrect or exceeds the shape,
Please try to set shape’s text width or positon as the following code:
shape.getTextXForm().getTxtWidth().setValue(shape.getXForm().getWidth().getValue())
Thanks.