ITeye博客

使用VisioAutomation.vdx 导出 visio的vdx文件

xustar · 2014-05-19 16:12 · 接口+对接调试 · C# .NET · 编程语言 · Markdown

因为项目需要,开始学习并使用VisioAutomation.vdx,实现代码绘制visio图像。

要求完成一个小的应用程序,提供webservice接口,接收json数据,绘制不同类型的visio图。 因为需要在正式项目中使用涉及visio版权问题,所以服务端是不能安装office visio。寻找了很多资料后决定只能使用VisioAutomation.vdx,绘制vdx文件是比较方便的做法。

架构设计: 封装为 WEB服务,基于REST风格

  • 部署在IIS中
  • 执行POST请求,提交JSON数据源,输出vdx
  • 封装客户端驱动,JAVA语言, JS语言

资料地址:http://visioautomation.codeplex.com/

IDE:VS2010 所使用的包: clipboard2.jpg.png clipboard.jpg.png

需要绘制模具,vss文件。 axDrawingControl1.Document.Application.Documents.OpenEx("Basic_U.vss",(short)Visio.VisOpenSaveArgs.visOpenDocked);

代码,初始方法: string output_filename = @"F:\hhpp1.vdx";

        // First load a starter VDX (a.k.a "the template") - we will build a new VDX from this one
        //var template_dom = System.Xml.Linq.XDocument.Load("F:\\model.vdx");
        var template_dom = System.Xml.Linq.XDocument.Parse(VA.VDX.Elements.Drawing.DefaultTemplateXML);

        // Clean up the template - remove the existing pages
        VA.VDX.VDXWriter.CleanUpTemplate(template_dom);

        // Create a new Drawing based on the template
        var doc = new VA.VDX.Elements.Drawing(template_dom);

         GetPage01_Simple_Fill_Format(doc);

        var w1 = new VA.VDX.Elements.DocumentWindow();
        w1.ShowGrid = false;
        w1.ShowGuides = false;
        w1.ShowConnectionPoints = false;
        w1.ShowPageBreaks = false;
        w1.Page = 0;
        
        doc.Windows.Add(w1);

        // now create a writer object
        var vdx_writer = new VA.VDX.VDXWriter();
        
        // merge the template with the new in-memory drawing and save it to the output fie
        vdx_writer.CreateVDX(doc, template_dom, output_filename);

绘图方法: private VA.VDX.Elements.Page GetPage01_Simple_Fill_Format(VA.VDX.Elements.Drawing doc) { var page = new VA.VDX.Elements.Page(8, 4); doc.Pages.Add(page);

        // find the id of the master for rounded rectangles
        int rounded_rect_id = doc.GetMasterMetaData("Rounded REctAngle").ID;

        // using that ID draw a rounded rectangle at pinpos(4,3)
        var shape1 = new VA.VDX.Elements.Shape(rounded_rect_id, 4, 3);
        page.Shapes.Add(shape1);

        // using that ID draw a rounded rectangle at pinpos(2,2) with size (2.5,2)
        var shape2 = new VA.VDX.Elements.Shape(rounded_rect_id, 2, 2, 2.5, 2);
        page.Shapes.Add(shape2);

        // set the fill properties of the second shape
        shape2.Fill = new VA.VDX.Sections.Fill();
        shape2.Fill.ForegroundColor.Result = 0xff0000;
        shape2.Fill.BackgroundColor.Result = 0x55ff00;
        shape2.Fill.ForegroundTransparency.Result = 0.1;
        shape2.Fill.BackgroundTransparency.Result = 0.9;
        shape2.Fill.Pattern.Result = 40;

        shape1.Line = new VA.VDX.Elements.Line();
        shape1.Line.Weight.Result = 1.0;

        shape1.XForm.Angle.Result = System.Math.PI/4;

        return page;
    }

完成效果图:fs.png

test代码:testVisio.rar

test文件VDX:hhpp1.rar

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。