Add pages in visio with aspose python java

Hello

I have purchased aspose.diagram library.

How i try i cannot add new pages to an existing visio document.

I can create new vidio files, change name of active page.

I have tried lots of methods and combinations:

bpmn.getPages().add(sida)

But get this error:

bpmn.getPages().add(sida)
TypeError: No matching overloads found for com.aspose.diagram.PageCollection.add(str), options are:
public int com.aspose.diagram.PageCollection.add(com.aspose.diagram.Page)

Please help me!

Another question about my license:

I am using a Mac.

The following code:

import the License class

from asposediagram.api import License
license = License()
license.setLicense(“Aspose.Diagram.Product.Family.lic”)

Is the license active?

Best Regards

Göran Pettersson

I am working in Python!

@Gope
Thanks for providing us the template code.
Can you please share source Python file along with complete environment details so that we may further investigate to help you out.
Thanks.

Yes,It’s active.

Hello Phillip!

Many thanks!

Will do that tonight!

Br

Göran Pettersson
Grit Consulting AB
Mobil: +46(0)70 728 31 56
E-post: goran.pettersson@gritconsulting.se
Hemsida: www.gritconsulting.se

Hello Philip

Here is an example I use to test to add a page in Visio.
Hope it can help

Göran

#Need to install requests package for python
import requests
import json

import jpype
import inspect
from jpype import java
import asposediagram
jpype.startJVM()
from asposediagram.api import *

import the License class

from asposediagram.api import License
license = License()
license.setLicense(“Aspose.Diagram.Product.Family.lic”)

visiostencil = “bpmn.vsdx”
with open(“bpmn.vsdx”, “rb”) as f:
bpmn = Diagram.createDiagramFromBytes(f.read(), loadOptions=LoadFileFormat.VSDX,LayoutDirection=LightRigDirectionType)

Create the Visual file

Create a filer called SNBPMN.vsdx from a template called BPMN.vsdx

Teh file BPMN.vsdx is a template file that contains the BPMN shapes and a process flow template.

def create_visual_file():
bpmn.save(“SNBPMN.vsdx”, SaveFileFormat.VSDX)
# end of function
#

Create a new page in Visio

Create a new page in the file SNBPMN.vsdx

The page is created from the template BPMN.vsdx

def create_new_page(newpage):

    print (newpage)

   # Create a new page
    # Set the name of the new page
    bpmn.getActivePage().setName(newpage)

    # Add the new page to the collection
    bpmn.getPages().add(newpage) # gives the error

    # Save the Visio diagram
    bpmn.save("SNBPMN.vsdx", SaveFileFormat.VSDX)     

def create_visual_shape():

bpmn.addMaster(visiostencil, "Start Event")
bpmn.addShape(2.0, 2.0, "Start Event", 0)
bpmn.addMaster(visiostencil, "Pool / Lane")
#bpmn.addShape(0.0,0.0, "Pool / Lane", 0)
bpmn.addShape(4.0,2.0, "Gateway", 0)
bpmn.addMaster(visiostencil, "Task")
bpmn.addShape(6.0, 2.0, "Task", 0)

bpmn.save("SNBPMN.vsdx", SaveFileFormat.VSDX)

snbm = create_visual_file()
test =“rrrr”
snbmn = create_new_page(test)
snbmn = create_visual_shape()

@Gope
It looks like you’ve set a pagename , which is a string. Then, you’ve added this string to the page collection. This is the reason for the error.

Please add a page to the collection, for example,

    newPage = Page()
    newPage.setName("new page") //set page's name
    newPage.setID(100) //set page's id
    diagram.getPages().add(newPage) //add page to collection

Hello Asad and Philip

I am quite new working with Aspose. I was not sure which forum was the best to get som help. Philip helped men and I am on track again.

Thanks for all help.

BR

Göran

@Gope
Thanks for following the suggested workaround and good know that your issue is sorted out now.
Please feel free to contact us in case you have further comments or questions.
Thanks.