We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copy Shape from one Visio File to another

Hello


I am currently using Aspose diagram 5.7.0 java unlicencsed version.

I need to confirm if we could perform following action in above mentioned version of aspose diagram:
1. Create a new page in the DestinationDoc.vsd
2. Copy shapes from one page of the SourceDocument.vsd into the new page that is created above.

Also if we Can we copy the GROUP (TypeValue) shape type from SourceDocument to our DestinationDocument.


Regards
Shubhi

Hi Shubhi,

Thank you for contacting support. Please note, we recommend our users get a temporary license for Aspose APIs evaluation purposes. We offer 30 day temporary license.

Please download the latest version of Aspose.Diagram API and apply a valid license. Please refer to the following help topics: Applying a License for Aspose.Diagram for Java library, Download Aspose.Diagram for Java API

After applying a valid license, please use the sample codes as narrated there: Copy shape from one Visio file to another Visio file, Copy a Visio page into another Diagram and Insert a new blank page into a Visio drawing

Please note, “add” method of the ShapeCollection class allows to add group shape too. We hope, this helps. Please let us know in case of any confusion or questions.

Hello Imran

Thanks for your reply .I tried copying a GROUP shape using following snippet:

Diagram newDiagram = new Diagram();
int MaxPageId = GetMaxPageID(newDiagram);
Diagram srcVisio=new Diagram(“E:\Practice\asposeprac\asposeDiagram\Drawing3vsd.vsd”);
String pageName=“Page-1”;

// Initialize a new page object
Page newPage = new Page();
// Set name
newPage.setName(“new page”);
// Set page ID
newPage.setID(MaxPageId + 1);
// Add a new blank page
newDiagram.getPages().add(newPage);
// remove first empty page
newDiagram.getPages().remove(newDiagram.getPages().get(0));

// add all masters from the source Visio diagram
MasterCollection originalMasters = srcVisio.getMasters();
for (Master master : (Iterable) originalMasters) {
newDiagram.addMaster(srcVisio, master.getName());
}

// get the page object from the original diagram
Page SrcPage = srcVisio.getPages().getPage(pageName);
Shape shapeNew=null;

for(Shape shape:(Iterable)srcVisio.getPages().getPage(pageName).getShapes()){
if(shape.getType()==TypeValue.GROUP /*&&shape.getName().equalsIgnoreCase(groupName)*/){
shapeNew=shape;
break;
}
}
[//shapeNew.setName](https://shapenew.setname/)(“New Shape”);
shapeNew.setID(15);
shapeNew.setType(TypeValue.GROUP);
ShapeCollection ss=newDiagram.getPages().getPage(MaxPageId+1).getShapes();
ss.add(shapeNew);
newDiagram.save(“Temp111.vdx”, SaveFileFormat.VDX);

But it is saving a blank page ,shape is not getting displayed in VDX Output. Kindly confirm if it is correct way of adding GROUP type shapes.

Also I need to confirm when iam trying to save newDiagram in other formats such as PDF/HTML they are coming empty shape is not getting shown in it . Is there any way to directly save newDiagram to other formats rather than saving it to VDX.

Regards

Shubhi

Hi Shubhi,


Thank you for sharing a sample code. In the last part of the code, you’re assigning a group shape to a new shape object and then setting its type and id (as 15). You must calculate the maximum available shape id of the Visio page and also set shape name and id (maxshapeid + 1). In the reference of the maximum shape id, please check the GetMaxShapeID method which is available in the sample code there. Since please modify your sample code accordingly and let us know if it works perfectly. Otherwise, please provide us the zip file of your source Visio diagram in this forum thread. We’ll investigate and reply you appropriately.

Aspose.Diagram API allows to save Visio diagrams in the PDF and HTML file formats. Please refer to the following help topics: Export Visio Diagram to PDF and Export Visio Diagram to HTML

Hello Imran please find the updated snippet :


License license = new License();
license.setLicense(“Aspose.Diagram.lic”);
Diagram newDiagram = new Diagram();
int MaxPageId = GetMaxPageID(newDiagram);
Diagram srcVisio=new Diagram(“E:\Practice\asposeprac\asposeDiagram\DemoGroup.vsdx”);
String pageName=“Page-1”;
// Initialize a new page object
Page newPage = new Page();
// Set name
newPage.setName(“new page”);
// Set page ID
newPage.setID(MaxPageId + 1);

// Add a new blank page
newDiagram.getPages().add(newPage);
// remove first empty page
newDiagram.getPages().remove(newDiagram.getPages().get(0));

// add all masters from the source Visio diagram
MasterCollection originalMasters = srcVisio.getMasters();
for (Master master : (Iterable) originalMasters) {
newDiagram.addMaster(srcVisio, master.getName());
}
// get the page object from the original diagram
Page SrcPage = srcVisio.getPages().getPage(pageName);
Shape shapeNew=null;
for(Shape shape:(Iterable)srcVisio.getPages().getPage(pageName).getShapes()){
if(shape.getType()==TypeValue.SHAPE ){
shapeNew=shape;
break;
}
}
shapeNew.setName(“New Shape”);
shapeNew.setID(GetMaxShapeID(SrcPage));
shapeNew.setType(TypeValue.SHAPE);
ShapeCollection ss=newDiagram.getPages().getPage(MaxPageId+1).getShapes();
ss.add(shapeNew);

newDiagram.save(“Temp111.pdf”, SaveFileFormat.PDF);
Problems Still Existent:
1) With this I am able to get group shape in VDX format only(For GROUP shape only) but it is not visible fully .Only one character (Text) within that shape is visible .Also Shape outlining is not coming.
Do i need to set other properties for it?

2)On saving newDiagram to HTML ((in SHAPE as well as GROUP) )format I get following exception :

java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0
at java.awt.image.SampleModel.(SampleModel.java:126)
at java.awt.image.ComponentSampleModel.(ComponentSampleModel.java:146)
at java.awt.image.PixelInterleavedSampleModel.(PixelInterleavedSampleModel.java:87)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:641)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:278)
at java.awt.image.BufferedImage.(BufferedImage.java:384)
at com.aspose.diagram.b.a.b.a.(Unknown Source)
at com.aspose.diagram.b.a.b.a.(Unknown Source)
at com.aspose.diagram.kd.a(Unknown Source)
at com.aspose.diagram.kd.a(Unknown Source)
at com.aspose.diagram.Diagram.save(Unknown Source)
at com.aspose.diagram.Diagram.save(Unknown Source)
at CopyShape.main(CopyShape.java:63)

3) On saving newDiagram to PDF format (in SHAPE as well as GROUP) I get the blank PDF , Attaching the PDF named as Temp111.pdf. that is saved.

Kindly let me know if I made mistake in above mentioned snippet.

Regards
Shubhi



Hi Shubhi,

Thank you for the details.
shubhi15sood:
1) With this I am able to get group shape in VDX format only(For GROUP shape only) but it is not visible fully .Only one character (Text) within that shape is visible .Also Shape outlining is not coming.
Do i need to set other properties for it?
Please note, the Shape element contains an element called Text, which contains the characters of the text and special elements (cp, pp, tp, and fld) that mark the end of one run and the beginning of the next. The Char element contains the formatting attributes for the shape's text, such as font, color, text style, case, position relative to the baseline, and point size.

It appears as when you assigned group shape to the new shape object, it does not transform char settings properly. Please extract group shape and don't assign it to the new shape object. Just change the group shape id, name and type and then pass it to the "add" method of the ShapeCollection class of the new diagram object. We suspect that the shape's text is available but not visible due to the setting of characters.
shubhi15sood:
2)On saving newDiagram to HTML ((in SHAPE as well as GROUP) )format I get following exception :

java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0
at java.awt.image.SampleModel.(SampleModel.java:126)
at java.awt.image.ComponentSampleModel.(ComponentSampleModel.java:146)
at java.awt.image.PixelInterleavedSampleModel.(PixelInterleavedSampleModel.java:87)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:641)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:278)
at java.awt.image.BufferedImage.(BufferedImage.java:384)
at com.aspose.diagram.b.a.b.a.(Unknown Source)
at com.aspose.diagram.b.a.b.a.(Unknown Source)
at com.aspose.diagram.kd.a(Unknown Source)
at com.aspose.diagram.kd.a(Unknown Source)
at com.aspose.diagram.Diagram.save(Unknown Source)
at com.aspose.diagram.Diagram.save(Unknown Source)
at CopyShape.main(CopyShape.java:63)

3) On saving newDiagram to PDF format (in SHAPE as well as GROUP) I get the blank PDF , Attaching the PDF named as Temp111.pdf. that is saved.

If you're not using the latest version of Aspose.Diagram for Java 5.7.0, then please make sure to add the reference of the latest Aspose.Diagram library in your application project and check if it resolves above problems. Otherwise, we require your source Visio diagram and exact sample code to replicate these issues on our side. We'll investigate and reply you appropriately.

Hello Imran

Thanks for your reponse.
After making changes suggested by you for Copying group shape without creating new object of shape I have mage follwing changes in my snippet :
License license = new License();
license.setLicense(“Aspose.Total.Java.lic”);
Diagram newDiagram = new Diagram();
int MaxPageId = GetMaxPageID(newDiagram);
Diagram srcVisio=new Diagram(“E:\Practice\asposeprac\asposeDiagram\DemoGroup.vsdx”);
String pageName=“Page-1”;
// Initialize a new page object
Page newPage = new Page();
// Set name
newPage.setName(“new-page”);
// Set page ID
newPage.setID(MaxPageId + 1);

// Add a new blank page
newDiagram.getPages().add(newPage);
// remove first empty page
newDiagram.getPages().remove(newDiagram.getPages().get(0));

// add all masters from the source Visio diagram
MasterCollection originalMasters = srcVisio.getMasters();
for (Master master : (Iterable) originalMasters) {
newDiagram.addMaster(srcVisio, master.getName());
}
// get the page object from the original diagram
Page SrcPage = srcVisio.getPages().getPage(pageName);
for(Shape shape:(Iterable)srcVisio.getPages().getPage(pageName).getShapes()){
if(shape.getType()==TypeValue.GROUP){
shape.setID(GetMaxShapeID(SrcPage));
shape.setName(“Group Shape”);
shape.setType(TypeValue.GROUP);
newDiagram.getPages().getPage(“new-page”).getShapes().add(shape);
newDiagram.save(“Temp111.vdx”, SaveFileFormat.VDX);
break;
}
}

but still when I save this object to VDX format it is showing me only one Chartacter within my shape also no Styling of Shapes are coming in Temp111.VDX document.

Kindly let me know the way to resolve this issue .

Also I wish to inform you that I am using Aspose.Diagram for Java 5.7.0, with licence .

Other Problems Faced:

1) Fill style of the normal shapes are not getting copied in VDX format.
2) While saving the newDiagram in different formats such as PDF/HTML I am still getting blank document for normal shapes as well as Group shapes.

File Attachments:
  • CopyShape.txtcode that i am using to copy shapes as well as Group shape.
  • Temp111.PDF after saving newDiagram to PDF getting blank document


Regards
Shubhi Sood

Hi Shubhi,


Thank you for the details. Please provide us your source Visio diagram (DemoGroup.vsdx) for testing purposes in this forum thread. It’ll help us to replicate the issue on our side. We’ll investigate and reply you accordingly.

Hello Imran

PFA DemoGroup.rar file contaning my source Visio drawing.
Also find the Temp111…vdx file that gets generated after copying group type shape.


Regards
Shubhi

Hi Shubhi,


Thank you for posting Temp11.rar file. You have not attached DemoGroup.rar file yet. Please recheck and attach it again. You can also send us this file through the email as narrated there. We’ll start investigating further and share our findings with you once the source VSDX file is available to us.

Hello Imran


Please find attached DemoGroup.vsdx Attachment withi DemGroup.rar file.

Regards
Shubhi

Hi Shubhi,


Thank you for sharing the source VSDX file.
shubhi15sood:
2)On saving newDiagram to HTML ((in SHAPE as well as GROUP) )format I get following exception :

java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0
at java.awt.image.SampleModel.(SampleModel.java:126)
at java.awt.image.ComponentSampleModel.(ComponentSampleModel.java:146)
at java.awt.image.PixelInterleavedSampleModel.(PixelInterleavedSampleModel.java:87)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:641)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:278)
at java.awt.image.BufferedImage.(BufferedImage.java:384)
at com.aspose.diagram.b.a.b.a.(Unknown Source)
at com.aspose.diagram.b.a.b.a.(Unknown Source)
at com.aspose.diagram.kd.a(Unknown Source)
at com.aspose.diagram.kd.a(Unknown Source)
at com.aspose.diagram.Diagram.save(Unknown Source)
at com.aspose.diagram.Diagram.save(Unknown Source)
at CopyShape.main(CopyShape.java:63)
We’re sorry to share with you that we could not reproduce this error message. Please confirm, are you using the latest version of Aspose.Diagram for Java 5.7.0? This latest version saves diagram in the HTML format but display only an empty page. We managed to replicate the problems as follows:

DIAGRAMJAVA-50234 - [Output format VDX] Group Shape is not displayed properly
DIAGRAMJAVA-50235 - [Output format HTML] Can’t place a group shape from another Visio diagram
DIAGRAMJAVA-50236 - [Output format PDF] Can’t place a group shape from another Visio diagram

Your post has also been linked to these issues. We’ll keep you informed regarding any available updates. We’re sorry for the inconvenience caused.

Hello


Could you please let me know the solution for following problems faced while copying shapes from one visio diagram to other :


1) Fill style of the normal shapes are not getting copied in VDX format.
2) While saving the newDiagram in different formats such as PDF/HTML I am still getting blank document for normal shapes as well as Group shapes.

Also kindly let me know the status of above bogs logged in relation to Group Shapes.

Regards
Shubhi

Hi Shubhi,


Thank you for the details. We’re working over your query and will get back to you soon.

Hi Shubhi,
Thank you for being patient.
shubhi15sood:
1) Fill style of the normal shapes are not getting copied in VDX format.
We have logged a separate ticket id DIAGRAMJAVA-50238 for the fill style issue. This issue has also been linked to this forum thread. We'll let you know once a significant progress has been made in this regard. We're sorry for the inconvenience cause.
shubhi15sood:
2) While saving the newDiagram in different formats such as PDF/HTML I am still getting blank document for normal shapes as well as Group shapes.
You're right. When we removed the check of group shape and imported all the shapes from the source diagram, even then it saves an empty page in PDF and HTML formats. We've logged comment against the ticket ids DIAGRAMJAVA-50235 and DIAGRAMJAVA-50236.
shubhi15sood:
Also kindly let me know the status of above bogs logged in relation to Group Shapes.
We have just been identified above problems. Our product team requires little time to investigate them. We'll let you know once we have some available updates.

Hello Imran

Is there any update on this issue as I am stuck and could not perform further tasks.

Regards
Shubhi

Hi Shubhi,


Thank you for the inquiry. Unfortunately, the linked issue ids are pending for the analysis and not resolved yet. We have asked to the product team to take a look at your issue shortly. We’ll let you know once an update is available from them.

Hi Shubhi,


Thank you for being patient. We have a good news for you that the issue id DIAGRAMJAVA-50236 has now been resolved. If there is no issue in the QA phase, then this fix will be included in the next version of Aspose.Diagram for Java 5.9.0. We’ll inform you via this forum thread as soon as the new release is published.

Hi Shubhi,


Thank you for being patient. We have a good news for you that the issue id DIAGRAMJAVA-50235 has now been resolved. If there is no issue in the QA phase, then this fix will be included in the next version of Aspose.Diagram for Java 5.9.0. We’ll inform you via this forum thread as soon as the new release is published.

Hi Shubhi,


Thank you for being patient. We have a good news for you that the issue ids DIAGRAMJAVA-50234 and DIAGRAMJAVA-50238 have now been resolved. If there is no issue in the QA phase, then their fixes will be included in the next version of Aspose.Diagram for Java 5.9.0. We’ll inform you via this forum thread as soon as the new release is published.