Greetings All, I am a newbie trying to evaluate the project (doing proof of concept).
I am building a new diagram from scratch in code and I want the connectors that I create to be straight.
This will create a connector and I can connect it fine but I want the connector to be a straight line. What do I have to do?
Shape connectorShape1 = new Shape();
connectorShape1.getLine().getEndArrow().setValue(4);
connectorShape1.getLine().getLineWeight().setValue(0.01388);
When I tried to use (taken from the example in SetConnectorAppearance.java)
connectorShape1.setConnectorsType(ConnectorsTypeValue.STRAIGHT_LINES);
I get the following exception:
Cannot invoke “com.aspose.diagram.Shape.getGeoms()” because the return value of “com.aspose.diagram.Shape.getMasterShape()” is null
Can someone help?
@richardcromer
Can you please share which example are your using? Please share the link of the document so that we can further proceed to assist you accordingly.
public static void main(String[] args) throws Exception {
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(CreateVisioDiagram.class) + "Diagrams/";
// Create directory if it is not already present.
File file = new File(dataDir);
if (!file.exists())
file.mkdir();
// initialize a new Diagram
List<Node> nodeList = buildNodes();
Diagram diagram = new Diagram();
PageCollection pages = diagram.getPages();
Page firstPage = pages.getPage(0);
int pageId = firstPage.getID();
String stencilsDir = Utils.getStencilsDir();
String masterName = "Circle";
// First, We must add the master to the diagram (from the appropriate stencil file)
diagram.addMaster(stencilsDir + "Basic Shapes.vssx","Circle");
diagram.addMaster(stencilsDir + "Blocks.vssx","Dynamic connector");
int PageIndex = 0;
double width = 1, height = 1, pinX = 3.25, pinY = 9.5;
// Add a new process shape
try {
long nodeId = diagram.addShape(pinX, pinY, width, height, masterName, PageIndex);
long nodeId2 = diagram.addShape(pinX+2, pinY-2, width, height, masterName, PageIndex);
long nodeId3 = diagram.addShape(pinX-2, pinY-2, width, height, masterName, PageIndex);
*** I JUST WANT TO CONFIGURE THE FOLLOWING CONNECTORS AS STRAIGHT LINES ****
// connectorShape2.MAKESTRAIGHTLINE <— That is what I don’t know how to do.
// initialize connector shape
Shape connectorShape1 = new Shape();
connectorShape1.getLine().getEndArrow().setValue(4);
connectorShape1.getLine().getLineWeight().setValue(0.01388);
Shape connectorShape2 = new Shape();
connectorShape2.getLine().getEndArrow().setValue(4);
connectorShape2.getLine().getLineWeight().setValue(0.01388);
// add shape
long connecter1Id = firstPage.addShape(connectorShape1, "Dynamic connector");
long connecter2Id = firstPage.addShape(connectorShape2, "Dynamic connector");
// connect sub-shapes
firstPage.connectShapesViaConnector(nodeId, ConnectionPointPlace.BOTTOM, nodeId2, ConnectionPointPlace.TOP,
connecter1Id);
firstPage.connectShapesViaConnector(nodeId, ConnectionPointPlace.BOTTOM, nodeId3, ConnectionPointPlace.TOP,
connecter2Id);
// save in the VSDX format
diagram.save(dataDir + "CreateDiagram2-out.vsdx", SaveFileFormat.VSDX);
} catch (Exception e)
{
System.out.println(e.getMessage());
}
}
@richardcromer
We only support straight connection lines now.
If you are getting an exception, please share sample files “Basic Shapes.vssx” and “Blocks.vssx” used in your code:
diagram.addMaster(stencilsDir + "Basic Shapes.vssx","Circle");
diagram.addMaster(stencilsDir + "Blocks.vssx","Dynamic connector");
I am not getting any exceptions. The lines are appearing. I just don’t want the connectors to have any bends in them. In other words, I want the connectors to always be a straight. I am building a node/edge graph and the connectors cannot have bends in them. I know that Visio supports that in that.
If it helps I can send a small image of what I am trying to achieve.
@richardcromer
We will surely check it and share the code snippet with you if it is possible to achieve what you require. Can you please share the sample files i.e. Blocks.vssx and Basic Shapes.vssx for our reference? You can also share the screenshot of what you are trying to achieve.