VDF常见问题整理(五十):如何在VectorDraw Developer Framework中导出文件?

点击立即下载VectorDraw Developer Framework


如何导出具有背景色的SVG文件/strong>

问:

是否可以导出背景颜色不同于白色的SVG文件/span>

答:

这可以通过一些代码行来指示VDF组件在OnDrawBackground事件中使用调色板的背景色,例如:

// the form conatins a vdFramedControl and a Buttonbool isOnSVGSave = false; // use this global boolean in the form and make it true just before saving the SVG and then again to false after save is finishedprivate void button1_Click(object sender, EventArgs e){    vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;    doc.Open(@"C:testsimple1.vdml"); // open a test file    doc.Palette.Background = Color.LightYellow; // change the background color    doc.Palette.Forground = Color.DarkSlateGray; // and the foreground color..........    isOnSVGSave = true; //set this flag to true before saving SVG    doc.OnDrawBackground += new vdDocument.DrawBackgroundEventHandler(doc_OnDrawBackground); // enable the event    doc.SaveAs(@"c:testsvg1.svg"); // save the SVG    doc.OnDrawBackground -= new vdDocument.DrawBackgroundEventHandler(doc_OnDrawBackground); // disable the event    isOnSVGSave = false;//set this flag back to false after saving SVG}void doc_OnDrawBackground(object sender, vdRender render, ref bool cancel){    if (isOnSVGSave && render!=null && render is RenderFormats.SvgRender) // check that is on "save" and render is SvgRender    {        cancel = true; // you need to pass this as tru        render.Clear(vdFramedControl.BaseControl.ActiveDocument.Palette.Background); // clear the render and use the Palette’s Background color!    }}   

在txt文件中如何导出xyz坐标/strong>

问:

如何将图形中线和折线的x,y,z数据导出到txt文件中br>

答:

VDF无法自动执行此功能,但是从加载到VDF组件中的任何图形中导出此txt文件非常容易。请参见下面的代码:

private void button1_Click(object sender, EventArgs e){    vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;    doc.New();    doc.Open(@"c:testMyModel Layout_1.0.dxf");     using (StreamWriter writer = new StreamWriter(doc.FileName+".txt")) //export c:testMyModel Layout_1.0.dxf.txt file containing the points of lines and polylines only    {        foreach (vdFigure item in doc.Model.Entities)        {            if (item != null && item is vdLine)            {                writer.WriteLine("vdLine " + (item as vdLine).StartPoint.ToString() + " " + (item as vdLine).EndPoint.ToString());            }            if (item != null && item is vdPolyline)            {                writer.Write("vdPolyline ");                foreach (Vertex item2 in (item as vdPolyline).VertexList)                {                    writer.Write(item2.AsgPoint().ToString() + " ");                }                writer.WriteLine(" ");            }        }    }}

您所需要做的就是循环文档中的所有对象(线,折线等),获取它们的x,y,z值,然后使用StreamWriter将它们写入txt文件中。


以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。

热门文章推荐:

  • 如何排除GroundSurface对象的三角形区域/strong>

  • 复杂自定义对象的入门指南

=======================================================

如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系在线客服>>咨询相关问题。

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年1月1日
下一篇 2020年1月1日

相关推荐

发表回复

登录后才能评论