Help with IImageShapeUIModel's

Hi guys, I’m having some issues with programatically setting an IImageShapeUIModel’s images.

After the script runs the element appears on the screen but appears without an image. Manually setting an image afterwards works but I need the script to set the image correctly.

Would really appreciate being pointed in the right direction! Here is my code to try to get it working…

IImageShapeUIModel imageShape = (IImageShapeUIModel) diagramManager.createDiagramElement(technologiesDiagram, IModelElementFactory.instance().createImageShape());
		String imagePath = "/Users/{my_name}/Documents/AppEngine.png";
		imageShape.setImagePath(imagePath);
		imageShape.setEmbeddedPath(imagePath);
		imageShape.setDisplayImagePath(imagePath);
		imageShape.setLinkedFilePath(imagePath);
		imageShape.setMode(IImageShapeUIModel.EMBEDDED);
		
		BufferedImage image = null;
		try {
		    File file = new File(imagePath);
		    image = ImageIO.read(file);
		    imageShape.setImage(image);
		    System.out.println(file.getAbsolutePath());
		} catch (Exception ex) {
		    ex.printStackTrace();
		}
		
		imageShape.setBounds(100, 100, 284, 137);
		
		System.out.println(imageShape.getEmbeddedPath());     //PRINTS SAME AS IMAGEPATH
		System.out.println(imageShape.getDisplayImagePath()); //PRINTS SAME AS IMAGEPATH
		System.out.println(imageShape.getImagePath());        //PRINTS SAME AS IMAGEPATH
		System.out.println(imageShape.getLinkedFilePath());   //PRINTS SAME AS IMAGEPATH
		Image test = imageShape.getImage();
		System.out.println(test.equals((Image) image));       //PRINTS TRUE

In my actual script the url file path as a string is correct I edited it to remove personal information

Hi Luke,

Thank you for your inquiry. I have forwarded your case to our engineers to study. When there is any news, I will let you know.

Best regards,
Jick Yeung

Thank you I appreciate it!

Hi Luke,

The following article provides the information you need:

File imageFile = new File(CreateDiagramImageShapePlugin.PluginDir, "images/vp_logo.png");
imageShape.setImagePath(imageFile.getAbsolutePath());
imageShape.setMode(IImageShapeUIModel.LINKED);

mode = link
imagePath = absolute path of the image file

Hope this helps.

Best regards,
Jick Yeung

Hi Jick

Unfortunately having it as LINKED doesn’t work either and also stops me from manually setting an image on the diagram afterwards.

Are there any other docs you could maybe point me towards?

Thanks,
Luke

Hi Luke,

I am asking our engineers how to insert a linked image and will let you know when there is an answer.

Best regards,
Jick Yeung

Hi Luke,

Could you try to change the first few lines of code as below?

String imagePath = /Users/{my_name}/Documents/AppEngine.png;|
imageShape.setMode(IImageShapeUIModel.EMBEDDED);|
imageShape.setImagePath(imagePath);|

Best regards,
Jick Yeung

Unfortunately that still doesn’t work, it just outputs this…

Is it possible there is a bug somewhere?

Thank you for coming back to me!
Luke

Hi Luke,

Could you zip and send us your files for repeating the problem? You can contact us by submitting a ticket below. Don’t forget to include your file:

Best regards,
Jick Yeung