Free Support Forum - aspose.com

Adding property to my shapes in java

Hi we recently purchased the library . It seems to have good capability and we are excited .
We need an assistance on how to set custom properties to drawn shapes in java.
Is there any code sample we can refer to ?.
Well the main problem we face is we were able to add the property but the values dos not show up
Prop prop4 = new Prop();
prop4.setName(“ip_flagN”);
prop4.getLabel().setValue(“IP flagL”);
prop4.getValue().setVal(“IPFLagV”);
shape.getProps().add(prop4);

the property is added but the prop4.getValue().setVal(“IPFLagV”); does not show the value on the window.
Thank you.

@Groum

Thanks for contacting support.

Would you kindly share your sample Diagram file along with complete sample code snippet that you have tried so far. We will test the scenario in our environment and address it accordingly.

import com.aspose.diagram.*;

public class Assets {

String dirPath2 = "C:/Users/user001/Downloads/Mydesign.vssx";

void assetdraw() {
    try {

        Diagram dg = new Diagram(dirPath2);
        Page pg = dg.getPages().getPage("Page-1");


        long shId = dg.addShape(2.0, 7, .65, .8, "Rectangle", 0);
        pg.getShapes().getShape(shId).setName("Rectangle");

        Shape Rectangle = pg.getShapes().getShape("Rectangle");

        for (Shape shape : (Iterable<Shape>) pg.getShapes()) {


            if (shape == Rectangle) {

                Prop prop2 = new Prop();
                prop2.setName("Name");
                prop2.getLabel().setValue("Entity_Type");
                prop2.getValue().setVal("Server");


                Prop prop3 = new Prop();
                prop3.setName("Hostname");
                prop3.getLabel().setValue("HostName");
                prop3.getValue().setVal("median");

                Prop prop4 = new Prop();
                prop4.setName("ip_flag");
                prop4.getLabel().setValue("system_data");
                prop4.getValue().setVal("system");

                Prop prop5 = new Prop();
                prop5.setName("flag");
                prop5.getLabel().setValue("Indicator");
                prop5.getValue().setVal("True");

                shape.getProps().add(prop2);

                shape.getProps().add(prop3);

                shape.getProps().add(prop4);

                shape.getProps().add(prop5);

            }

            dg.save(  "C:/Users/user001/Downloads/mydrawing.vsdx", SaveFileFormat.VSDX);

        }


    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

This is the code snippet can you recreate the scenario in your environment ?

Hi there I am expecting a support for the above request can I please get assistance, thank you.

@Groum

We apologize for the delayed response.

We were able to notice the issue in our environment and logged an investigation ticket as DIAGRAMJAVA-50690 in our issue tracking system for further investigation on this scenario. We will look into scenario details and share our feedback with you as soon as ticket is resolved. Please spare us little time.

We are sorry for the inconvenience.

1 Like

Hi May I know the estimated time to resolve this issue . We have a time sensitive implementation of the library to a project can you kindly let me know how long it would take.
I also would like to check if there will be any limitation on the number of properties we can add on shape.
I can add the name but the value does not display.

@Groum

We have investigated the ticket and as per the results, please use following code snippet to read the properties of Shape which you added:

for (com.aspose.diagram.Shape eshape : (Iterable<com.aspose.diagram.Shape>) dg.getPages().getPage(0).getShapes()) {
  for(int i= 0;i<eshape.getProps().getCount();i++) {
  // Display information about the shapes                                 
  System.out.println(i);
  System.out.println(eshape.getProps().get(i).getValue().getVal());
 }                   
}

Please note that Aspose.Diagram mimics the behavior of MS Visio and supports similar features. In case you face any issue, please feel free to let us know.

Hi thank you for your response but the problem I had was , to add the properties and display them in the visio.
Can you please assist me on that , how can you add the properties and display them?
Is there any limit on the number of properties ?
if you see my code above I added the properties but they don’t display on visio .

@Groum

Could you kindly share your sample Stencil and output Diagram file with us. We will further proceed to assist you accordingly.

visio.zip (938.6 KB)
I have added sample stencil and out put Diagram file , can you please help us add the properties of the shapes from the program .
and we do not expect any limitation on the no of properties to be added as per Visio diagram

Please let us know how long it would take resolve the issue thank you.

@Groum

Thanks for sharing sample files.

Please note that there is no limit on the number of properties to be added to Shape using Aspose.Diagram. In order to see the properties in MS Visio, please open the developer options, and you will find the properties. Please check the attached image.

prop.PNG (2.4 KB)

@Groum

Adding more to our previous reply, your earlier shared code snippet was correct to add the properties. Furthermore, if you are facing some issue while adding any property to your diagram, please let us know.

Dear Asad.ali, thank you very much for your assistance , I tried the property value as you mentioned above. here is a sample code I tried.

if (shape == Server2) {
Prop prop2 = new Prop();
prop2.setName(“Entity_Type”);
prop2.getLabel().setValue(“Server”);
prop2.getValue().setVal(“epaysql_ut.mbc.com”);

                               Prop prop3 = new Prop();
                               prop3.setName("Hostname");
                               prop3.getLabel().setValue("Host Name");
                               prop3.getValue().setVal("Controler");

                               Prop prop4 = new Prop();
                               prop4.setName("ip_flag");
                               prop4.getLabel().setValue("System Data Center");
                               prop4.getValue().setVal("IPFLagV");

                               Prop prop5 = new Prop();
                               prop5.setName("Indicator");
                               prop5.getLabel().setValue("Flag");
                               prop5.getValue().setVal("mbc");

                               Prop prop6 = new Prop();
                               prop6.setName("Priority");
                               prop6.getLabel().setValue("Priority");
                               prop6.getValue().setVal("6");


                               shape.getProps().add(prop2);

                               shape.getProps().add(prop3);

                               shape.getProps().add(prop4);

                               shape.getProps().add(prop5);

                               shape.getProps().add(prop6);

                           }

Only the last property that has numeric value is getting displayed properly, but the rest of them with string value are displayed as 0 value, which is not what I added .
Is there any formatting that we have to use to add string value ? as I can see the method accepts string argument even the numeric value is added inside double quote .
I have seen in some of the discussion in the forum the following method being used .
prop2.getFormat().setValue(" xxxx") is it something I have to use ?
if so how do I use it ?
Is there any documentation that I can use for a reference in the future when using the methods in the library.
for example we would like to try check the compact tree drawing as well is there any library documentation we can access ?
I have attached the screen shot of the above code out put.
Property_Mapping.PNG (3.1 KB)

@Groum

Would you also share the Diagram file with us which was generated using above code snippet. Also, please share the stencil file that you have used.

Hi Asad Ali ,
Thank you for your support , I have attached the stencil and the diagram generated by the above code snippet.
Please kindly help us get this thing resolved as soon as possible. We have a time sensitive project where we would like to use the library .
Can you please help me get also a referral document about the API’s.Drawing.zip (760.5 KB)

@Groum

In order to set the string values and show them in Shape properties in Visio, please set unit using following code snippet.

prop.getValue().getUfev().setUnit(MeasureConst.STR);

Furthermore, you may find Developer Guide and examples over following link:

In case you have further inquiry, please feel free to let us know.

Thank you Asad Ali!

Hi again, I used connector shape from visio two connect to shapes and I added a text on it.
The text is centered on the connector icon.
how do I move the connector text position
connectors.get(counter2).getText().getValue().add(new Txt(" depends")
the above line adds text on the connectors shape but I want change it position from center to beginning