VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。该库还支持许多矢量和栅格输入和输出格式,包括本地PDF和SVG导出。
VectorDraw web library (javascript)是一个矢量图形库。VectorDraw web library (javascript)不仅能打开CAD图纸,而且能显示任何支持HTML5标准平台上的通用矢量对象,如Windows,安卓,iOS和Linux。无需任何安装,VectorDraw web library (javascript)就可以运行在任何支持canvas标签和Javascript的主流浏览器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。
一. 选择XRef的实体
问:查找光标下显示的实体的最佳方法是什么?
答:附加的XRef文档在图形中用vdInserts视为vdBlocks。因此,当您附加外部参考文件时,会在文档中添加一个块并插入此块。在vdfCAD中,如果打开图形并单击附加的XRef,您将看到vdInsert对象。
您可以使用以下代码获取您单击的内部实体(vdInsert):
object ret = vdFramedControl1.BaseControl.ActiveDocument.ActionUtility.getUserPoint();
if (ret is VectorDraw.Geometry.gPoint)
{
VectorDraw.Geometry.gPoint p1 = vdFramedControl1.BaseControl.ActiveDocument.World2PixelMatrix.Transform(ret as VectorDraw.Geometry.gPoint);
Point location = new Point((int)p1.x, (int)p1.y);
// This code will return the xREF as vdInsert
VectorDraw.Professional.vdPrimaries.vdFigure fig = vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.GetEntityFromPoint(location, vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.Render.GlobalProperties.PickSize, false);
if (fig != null)
{
fig.HighLight = true;
fig.Invalidate();
MessageBox.Show("Figure is a : " + fig.ToString());
fig.HighLight = false;
fig.Invalidate();
}
// This code will return the inner entity, this is what you want
VectorDraw.Professional.vdPrimaries.vdFigure outerfig; // this should be the xREF vdInsert
VectorDraw.Geometry.Matrix matr = new VectorDraw.Geometry.Matrix();
VectorDraw.Professional.vdPrimaries.vdFigure innerfig = vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.GetInnerEntityFromPoint(out matr, out outerfig, location, vdFramedControl1.BaseControl.ActiveDocument.ActiveLayOut.Render.GlobalProperties.PickSize, false);
if (innerfig != null && outerfig != null)
{
innerfig.HighLight = true; //This is the inner entity you want.
innerfig.Invalidate();
MessageBox.Show("Figure is a : " + innerfig.ToString() + " contained in " + outerfig.ToString());
innerfig.HighLight = false;
innerfig.Invalidate();
}
}
二. 将LineType Penstyle设置为Render
问:如何更改渲染对象的线型(solid,dashdot等)?我知道vdLineType可以在Vdraw.BaseControl.ActiveDocument.LineTypes中选择,但我找不到渲染线类型的类似集合。
答:在空项目中添加一个调用cmdLine“user”和VDScrollable控件的按钮。添加OnActionDraw事件处理程序,并在ActiveDocument_OnActionDraw中使用如下代码:
void ActiveDocument_OnActionDraw(object sender, object action, bool isHideMode, ref bool cancel)
{
if (!(action is VectorDraw.Actions.ActionGetRefPoint)) return;
VectorDraw.Actions.BaseAction act = action as VectorDraw.Actions.BaseAction;
VectorDraw.Geometry.gPoint refpoint = act.ReferencePoint;
VectorDraw.Geometry.gPoint currentpoint = act.OrthoPoint;
// Draw the circle using vdCircle object
VectorDraw.Professional.vdFigures.vdCircle circle = new VectorDraw.Professional.vdFigures.vdCircle();
circle.SetUnRegisterDocument(vdSC.BaseControl.ActiveDocument);
circle.setDocumentDefaults();
circle.LineType = vdSC.BaseControl.ActiveDocument.LineTypes.DPIDashDotDot; // The Linetype here
circle.Center = VectorDraw.Geometry.gPoint.MidPoint(refpoint, currentpoint);
circle.Radius = circle.Center.Distance3D(refpoint);
circle.Draw(act.Render);
// OR you can use the Render.Draw....
act.Render.PushPenstyle(Color.Red, 0.1d, vdSC.BaseControl.ActiveDocument.LineTypes.FindName("CENTER").GetgrLineType());
act.Render.DrawLine(sender, new VectorDraw.Geometry.gPoint(0, 0, 0), currentpoint);
act.Render.PopPenstyle(); // THIS IS NECESSARY after every push
}
三. 使用打印机导出到光栅和PDF / SVG / EMF / HPGL文件
问:如何使用打印机导出到光栅JPG / BMP / TIF / GIF和PDF / SVG / EMF / HPGL文件?
答:在版本6010及更高版本中,vdPrinter对象可用于将整个图形或部分图形导出为栅格(BMP JPG GIF TIF)和PDF,SVG,HPGL和EMF文件。下面是C#中可用于此的示例代码:
private void button1_Click(object sender, EventArgs e)
{
// Except for EMF, the same can be done with PDF, BMP, JPG, SVG, HPG (HPGL)
// From version 6010 and above the printer can be used in order to export an area or the whole drawing in a
// raster format (BMP, JPG), PDF, SVG, or HGPL
#region create simple drawing
//create a simple drawing
vdFC.BaseControl.ActiveDocument.New();
vdFC.BaseControl.ActiveDocument.CommandAction.CmdBox3d(new VectorDraw.Geometry.gPoint(10, 10), 10, 12, 14, 10);
vdFC.BaseControl.ActiveDocument.CommandAction.CmdCircle(new VectorDraw.Geometry.gPoint(3, 3), 5.0d);
#endregion
#region save as EMF the Extends using fixed EMF width
//save as EMF the Extends using fixed EMF width
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrinterName = "c:\\test_extends.emf"; // or PDF bmp jpg svg
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution=96; //Screen DPI
VectorDraw.Geometry.Box Extends= vdFC.BaseControl.ActiveDocument.ActiveLayOut.Entities.GetBoundingBox(true,true);
int EMFwidth = 500; //fixed width
int EMFheight = (int) (EMFwidth * Extends.Height/Extends.Width); // keep propotions
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.paperSize = new Rectangle(0, 0, (int)(EMFwidth * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution), (int)(EMFheight * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution));
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintExtents();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintScaleToFit();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintOut();
#endregion
#region save as EMF the screen using fixed EMF height
//save as EMF the screen using fixed EMF height
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrinterName = "c:\\test_screen.emf"; // or PDF bmp jpg svg
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution = 96; //Screen DPI
VectorDraw.Geometry.Box screen_Box = new VectorDraw.Geometry.Box();
double screen_width = vdFC.BaseControl.ActiveDocument.ActiveLayOut.PixelSize * vdFC.BaseControl.Width;
double screen_height = vdFC.BaseControl.ActiveDocument.ActiveLayOut.ViewSize;
screen_Box.AddPoint(vdFC.BaseControl.ActiveDocument.ActiveLayOut.ViewCenter - new VectorDraw.Geometry.gPoint(screen_width / 2.0d, screen_height / 2.0d));
screen_Box.AddPoint(vdFC.BaseControl.ActiveDocument.ActiveLayOut.ViewCenter + new VectorDraw.Geometry.gPoint(screen_width / 2.0d, screen_height / 2.0d));
EMFheight = 500; // this is fixed
EMFwidth = (int)(EMFheight * screen_width / screen_height); //keeping the propotion
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.paperSize = new Rectangle(0, 0, (int)(EMFwidth * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution), (int)(EMFheight * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution));
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintWindow = screen_Box; // Here the code can be changed so
// the user can select a rectangle in screen and this area is saved to file.
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintScaleToFit();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintOut();
#endregion
#region call the PrintPreview in order the user to select the area to export to file
// call the PrintPreview in order the user to select the area to export to file
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrinterName = "*.emf"; // Using *.emf or *.pdf etc the print dialog will prompt a dialog to input the file name
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution = 96; //Screen DPI
EMFwidth = 500; //fixed width
EMFheight = 500; // and height
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.paperSize = new Rectangle(0, 0, (int)(EMFwidth * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution), (int)(EMFheight * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution));
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintExtents();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintScaleToFit();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.InitializePreviewFormProperties(true, true, false, false);
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.CenterDrawingToPaper();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.DialogPreview();
#endregion
}
使用VDF Wrapper ActiveX(vdraw.ocx)和VectorDraw.Geometry.tlb以及VectorDraw.Professional.tlb,您可以使用以下代码执行相同操作:
Private Sub Command1_Click()
Dim doc As VectorDraw_Professional.vdDocument
Dim box As Variant
Dim EMFwidth As Long
Dim EMFheight As Long
Dim extends As New VectorDraw_Geometry.box
Set doc = VDraw1.ActiveDocument.WrapperObject
doc.ActiveLayOut.Printer.PrinterName = App.Path + "\10165.emf"
doc.ActiveLayOut.Printer.Resolution = 96
extends.AddBox doc.ActiveLayOut.entities.GetBoundingBox(True, False)
extends.Transformby doc.World2ViewMatrix
extends.AddWidth doc.ActiveLayOut.Render.PixelSize * CDbl(0.5)
EMFwidth = 1000
EMFheight = CLng(EMFwidth * extends.Height / extends.Width + 0.5)
doc.ActiveLayOut.Printer.SelectPaper "CUSTOM"
doc.ActiveLayOut.Printer.MARGINS.Top = 0
doc.ActiveLayOut.Printer.MARGINS.Bottom = 0
doc.ActiveLayOut.Printer.MARGINS.Left = 0
doc.ActiveLayOut.Printer.MARGINS.Right = 0
doc.ActionLayout.Printer.Update
VDraw1.ActiveDocument.ActiveLayOut.Printer.ActivePaperWidth = CLng(100# * CDbl(EMFwidth) / CDbl(doc.ActiveLayOut.Printer.Resolution))
VDraw1.ActiveDocument.ActiveLayOut.Printer.ActivePaperHeight = CLng(100# * CDbl(EMFheight) / CDbl(doc.ActiveLayOut.Printer.Resolution))
Set doc.ActiveLayOut.Printer.PrintWindow = extends
doc.ActiveLayOut.Printer.PrintScaleToFit
doc.ActiveLayOut.Printer.PrintOut
End Sub
未完待续......