VDF常见问题整理(五十):如何在VectorDraw Developer Framework中导出文件?
VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。该库还支持许多矢量和栅格输入和输出格式,包括本地PDF和SVG导出。
点击立即下载VectorDraw Developer Framework
本文将会介绍如何在VectorDraw Developer Framework中导出文件,将会主要介绍如何导出具有背景色的SVG文件和在txt文件中如何导出xyz坐标。
如何导出具有背景色的SVG文件?
问:
是否可以导出背景颜色不同于白色的SVG文件?
答:
这可以通过一些代码行来指示VDF组件在OnDrawBackground事件中使用调色板的背景色,例如:
// the form conatins a vdFramedControl and a Button
bool 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 finished
private void button1_Click(object sender, EventArgs e)
{
vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;
doc.Open(@"C:\test\simple1.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:\test\svg1.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坐标?
问:
如何将图形中线和折线的x,y,z数据导出到txt文件中?
答:
VDF无法自动执行此功能,但是从加载到VDF组件中的任何图形中导出此txt文件非常容易。请参见下面的代码:
private void button1_Click(object sender, EventArgs e)
{
vdDocument doc = vdFramedControl.BaseControl.ActiveDocument;
doc.New();
doc.Open(@"c:\test\MyModel Layout_1.0.dxf");
using (StreamWriter writer = new StreamWriter(doc.FileName+".txt")) //export c:\test\MyModel 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文件中。
以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。
热门文章推荐:
=======================================================
如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系咨询相关问题。
关注慧聚IT微信公众号 ???,了解产品的最新动态及最新资讯。

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线