Can't change shape view

Hello, I am using the latest version of aspose.diagram for Node.js. I’m trying to create a shape with a border and a background color, but these parameters don’t change. I used the next code:

const createMaster = () => {
  const master = new Master();

  master.setID(0);
  master.setName("Rectangle");

  const shape = new Shape();

  shape.setID(0);
  shape.setType(TypeValue.SHAPE);

  shape.getXForm().getPinX().setValue(0);
  shape.getXForm().getPinY().setValue(0);
  shape.getXForm().getWidth().setValue(1);
  shape.getXForm().getHeight().setValue(1);

  shape.getText().getValue().add(new Txt("Shape"));

  shape.getLine().getLineWeight().setValue(0.1);
  shape.getLine().getLineColor().setValue("#000000");

  shape.getFill().getFillForegnd().setValue("#ffffff");
  shape.getFill().getFillBkgnd().setValue("#ffffff");

  master.getShapes().add(shape);

  return master;
};

const createVisio = () => {
  const diagram = new Diagram();
  diagram.Title = "My Visio Diagram";

  diagram.getMasters().add(createMaster());
  diagram.addShape(0, 0, "Rectangle", 0);

  diagram.save("output.vsdx", SaveFileFormat.VSDX);
};

And if the shape does not contain text, it is not created.

shape.png (4.7 KB)

@YeCho
Because no lines have been added after “new shape,” there won’t be any specific shape appearing. Please refer to the following code to first draw a rectangle and then set its style.

        //draw rectangle
        var id = diagram.getPages().get(0).drawRectangle(1, 1, 1, 1);
        var shape = diagram.getPages().get(0).getShapes().getShape(id);
      
        shape.setID(id);
        shape.setType(TypeValue.SHAPE);
      
        shape.getXForm().getPinX().setValue(1);
        shape.getXForm().getPinY().setValue(1);
        shape.getXForm().getWidth().setValue(1);
        shape.getXForm().getHeight().setValue(1);
      
        shape.getText().getValue().add(new Txt("Shape"));
      
        shape.getLine().getLineWeight().setValue(0.1);
        shape.getLine().getLineColor().setValue("#ff0000"); 
        shape.getLine().getLinePattern().setValue(1);  
        shape.getFill().getFillForegnd().setValue("#ff0000");
        shape.getFill().getFillPattern().setValue(1);
        shape.getFill().getFillBkgnd().setValue("#ffffff");
      
        master.getShapes().add(shape);

Thanks.

1 Like