Creating VSD with stencil included using custom shapes

Finding this product very frustrating and lack of examples something that might drive us away from purchasing this product.

I’m trying to create a VSD file that includes a custom stencil. The only way I can get the stencil to be included in the diagram is to use the vst in the Diagram constructor or use an existing blank VSD that is using that template. I then have to run the AddMaster command for every one of my shapes (only showing a couple of the ones I need). This seems kind of inefficient since the original diagram I am opening should have those shapes available. In either case, it seems that if I am going to save it as a VDX file, it adds one shape on the page and the other shape is not even on the page (note that I am using the Layout options). The connection runs off the page. If I save it as png, it works fine, although I would prefer if it would use the background from the Sample.vsd that I am using as a base file. Let me know if additional code would be helpful here. Hard to paste code here so I won’t worry about formatting.

Note that the end solution will consist of a UI that allows the user to select different types of infrastructure where clicking next would generate an image file that can be displayed to the user on the web page. If they need to make further customizations to their architecture, they can download the vsd file, which would contain the custom stencil so what the user inputs can be understood by a process when they upload that same file after changes to read any changes they made manually to persist those changes to a database. So creating a vsd with the stencil is very important, but I also need for the vsd to build correctly. One other thing I noticed is that I always get a warning opening the file in Visio.

string visioStencil = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\MH Template.vst";

Diagram diagram = new Diagram(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Sample.VSD", LoadFileFormat.VSD);

diagram.AddMaster(visioStencil, “SharePoint”);

diagram.AddMaster(visioStencil, “SQL”);

diagram.AddMaster(visioStencil, “Dynamic connector”);

long rectangleId = diagram.AddShape(

pinX, pinY, width, height, “SharePoint”, pageNumber);

//Set the new shape’s properties

Aspose.Diagram.Shape shape = diagram.Pages[pageNumber].Shapes.GetShape(rectangleId);

shape.Name = “test1”;

shape.Line.LineColor.Value = “7”;

shape.Line.LineWeight.Value = 0.03;

shape.Fill.FillBkgnd.Value = “1”;

shape.Fill.FillForegnd.Value = “3”;

shape.Fill.FillPattern.Value = 31;

pinY = 6.5;

long starId = diagram.AddShape(

pinX, pinY, width, height, “SQL”, pageNumber);

//Set the star shape’s properties

shape = diagram.Pages[pageNumber].Shapes.GetShape(starId);

shape.Name = “test2”;

shape.Line.LineColor.Value = “#ff0000”;

shape.Line.LineWeight.Value = 0.03;

shape.Fill.FillBkgnd.Value = “#ff00ff”;

shape.Fill.FillForegnd.Value = “#0000ff”;

shape.Fill.FillPattern.Value = 31;

Aspose.Diagram.Shape connector1 = new Aspose.Diagram.Shape();

long connecter1Id = diagram.AddShape(connector1, “Dynamic connector”, 0);

diagram.Pages[0].ConnectShapesViaConnector(rectangleId, ConnectionPointPlace.Bottom,

starId, ConnectionPointPlace.Top, connecter1Id);

LayoutOptions flowChartOptions = new LayoutOptions();

flowChartOptions.Direction = LayoutDirection.TopToBottom;

flowChartOptions.SpaceShapes = 1;

diagram.Layout(flowChartOptions);

//Save the diagram

diagram.Save(“Diagram1.vdx”, SaveFileFormat.VDX);

Also, note that the number of shapes and types of shapes would be completely dynamic as well as the connection. Here it is more of a POC. I really need to get this to work correctly before we can consider purchasing this product.

OK… I figured it out and I have not seen this listed anywhere, but maybe this will help.


Create your document like Base.vsd with the shapes you need adding the shapes to the Document Stencil. Doing that will load the masters collection with those shapes so you don’t need to worry about them. The document stencil is like a custom stencil so an additional stencil is not necessary. Just goes along with the document.

And to do the background, I did this where Vertical Gradient is a shape in the document stencil. It should be added first before any other shapes.

Aspose.Diagram.Shape background = new Aspose.Diagram.Shape();
diagram.AddShape(background, “Vertical Gradient”, 0);

Hi

Thank you for contacting support.

ctcottrell:

I’m trying to create a VSD file.

Well, you can load a VSD file to the diagram object, but you can’t save diagrams as VSD. It is not supported. We have already logged this feature under ticket id DIAGRAMNET-50017 in our issue tracking system. Your request has also been linked to this issue and you will be notified as soon as it is fixed. At the moment, you can save as XML (VDX, VSX and VTX), image or PDF formats etc.

ctcottrell:

I’m trying to create a VSD file that includes a custom stencil. The only way I can get the stencil to be included in the diagram is to use the vst in the Diagram constructor or use an existing blank VSD that is using that template. I then have to run the AddMaster command for every one of my shapes (only showing a couple of the ones I need). This seems kind of inefficient since the original diagram I am opening should have those shapes available.

Please note that you can include masters from a custom stencil as follows:

// load stencil
Diagram stencil = new Diagram("MH Template.vst");
// load diagram
Diagram diagram = new Diagram("Sample.vsd");
// iterate through stencil's masters
foreach (Master master in stencil.Masters)
{
 // add master
 diagram.AddMaster(@"MH Template.vst", master.Name);
}

After this, you just need to call an AddShape method to add any shape by its name.

ctcottrell:

it seems that if I am going to save it as a VDX file, it adds one shape on the page and the other shape is not even on the page (note that I am using the Layout options). The connection runs off the page. If I save it as png, it works fine.

Please share your stencil file and source VSD diagram in this forum thread. We’ll take a closer look and guide you accordingly.

ctcottrell:

although I would prefer if it would use the background from the Sample.vsd that I am using as a base file.

In order to set the background of the page, you can set a background page by “Page.BackPage” property.

Please feel free to let us know in case of any comments or questions.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.

The issues you have found earlier (filed as DIAGRAMNET-50017) have been fixed in this update. This message was posted using Bugs notification tool by philip.zhou