翻译|使用教程|编辑:黄竹雯|2018-12-03 10:25:28.000|阅读 223 次
概述:本系列教程整理了VectorDraw 最常见问题,教程整理的很齐全,非常适合新手学习,希望对大家有一定的帮助!
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
相关链接:
VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。该库还支持许多矢量和栅格输入和输出格式,包括本地PDF和SVG导出。
【VectorDraw Developer Framework最新版下载】
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等等)中。
【VectorDraw web library (javascript)最新版下载】
一. 在用户绘制命令后计算和绘制某些实体
问:如何在用户绘制命令后计算和绘制一些实体?例如,我想绘制2条线,这些线将代表用户使用cmdCircle等自动命令绘制的圆的半径和直径。
答:cmdCircle(以及几乎所有命令动作)如果成功与否则返回布尔值,因此在cmdCircle返回true后,您可以将最后添加的实体添加到实体集合(这将是您的用户绘制的圆圈)并获取中心点和半径。使用这些值,您可以计算两个点,并添加/绘制直径尺寸或直线。例如,请参阅下面的代码(C#VS2005):
private void button2_Click(object sender, EventArgs e) { VectorDraw.Professional.vdObjects.vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument;//ask the user to draw the circle bool cir_success=doc.CommandAction.CmdCircle(null, null); if (cir_success) { // cmdCircle is successful VectorDraw.Professional.vdFigures.vdCircle circ = (VectorDraw.Professional.vdFigures.vdCircle) doc.ActiveLayOut.Entities[doc.ActiveLayOut.Entities.Count - 1]; if (circ == null) return; VectorDraw.Geometry.gPoint pt_center = new VectorDraw.Geometry.gPoint(circ.Center);// got the circle and its properties double radius = circ.Radius; //calculate the points @ 45, 135 and 225 degrees VectorDraw.Geometry.gPoint pt_45 = pt_center.Polar(VectorDraw.Geometry.Globals.HALF_PI/2.0d, radius); VectorDraw.Geometry.gPoint pt_225 = pt_center.Polar(5.0d*VectorDraw.Geometry.Globals.HALF_PI/2.0d, radius); VectorDraw.Geometry.gPoint pt_135 = pt_center.Polar(3.0d * VectorDraw.Geometry.Globals.HALF_PI / 2.0d, radius); // draw the lines VectorDraw.Professional.vdFigures.vdLine line = new VectorDraw.Professional.vdFigures.vdLine();//diameter "blue" line line.SetUnRegisterDocument(doc); line.setDocumentDefaults(); line.StartPoint = pt_45; line.EndPoint = pt_225; line.PenColor.FromSystemColor(Color.Blue); doc.ActiveLayOut.Entities.AddItem(line); line.Invalidate(); line = new VectorDraw.Professional.vdFigures.vdLine();//radius "red" line line.SetUnRegisterDocument(doc); line.setDocumentDefaults(); line.StartPoint = pt_center; line.EndPoint = pt_135; line.PenColor.FromSystemColor(Color.Red); doc.ActiveLayOut.Entities.AddItem(line); line.Invalidate(); } }
二. 使用View3D“VROT”而不更改旋转中心
问:我正在尝试将旋转点固定到图形中某个对象的最后一个顶点。现在,如果我保持在“白色旋转圆”之外,则旋转操作按预期起作用,即线的终点保持在图中心的固定位置。但是,如果我在圆圈内移动,那么“固定”点会移动。这不是我正在寻找的行为。我需要“目标”点保持在图纸的中心。我怎样才能做到这一点?
答:在6017版本中,可以使用新功能以按您希望的方式旋转视图。您必须像在项目中一样设置视图(矩阵)和视图中心,而不是调用View3D“VROT”,您将调用包装器的新方法。例如(粗体变化):
Private Sub cmdRotate_Click() Dim SecClipNear As vdrawI5.vdSectionClip Dim SecClip As vdrawI5.vdSectionClips Dim Origin As vdrawI5.vdxyz Dim Direction As vdrawI5.vdxyz Dim Layout As vdrawI5.vdLayout SetAnglesAndTargetPointToModelRenderer VDraw, 0, 0, 0, -25988.0391, -34608.9102, 781.0027 VDraw.ActiveDocument.ActiveLayOut.ViewCenter = Array(0, 0, 0) Dim doc As VectorDraw_Professional.vdDocument Set doc = VDraw.ActiveDocument.WrapperObject ''''''VDraw.CommandAction.View3D "VROT" ' don't use this, but use : doc.ActionUtility.getUserDynamicRotEx False 'this, which is the new method End Sub Public Sub SetAnglesAndTargetPointToModelRenderer(MCAD As VDrawLib5.VDraw, dblRotation As Double, dblDip As Double, dblTwist As Double, dblOrigX As Double, dblOrigy As Double, dblOrigZ As Double) Dim vMatrix As New VectorDraw_Geometry.Matrix ' Build Matrix with the angle rotations and Translations done vMatrix.IdentityMatrix vMatrix.TranslateMatrix_2 -dblOrigX, -dblOrigy, -dblOrigZ vMatrix.RotateZMatrix VDrawGeo_Globals.DegreesToRadians(-dblRotation) vMatrix.RotateXMatrix VDrawGeo_Globals.DegreesToRadians(-dblDip) vMatrix.RotateZMatrix VDrawGeo_Globals.DegreesToRadians(360 - dblTwist) ' Set Matrix to document which influence the Model Space MCAD.ActiveDocument.WrapperObject.World2ViewMatrix = vMatrix MCAD.Redraw MCAD.CommandAction.RegenAll End Sub
新函数是getUserDynamicRotEx,它接受一个布尔值。有了这个布尔值,它就像希望的那样工作,而传递真实它就像View3D“VROT”(和getUserDynamicRot)一样工作。
/// <summary> /// Starts a dynamic rotate action so the user can rotate the active layout in 3D. /// </summary> /// <param name="changeView">Defines if the Target point of View matrix and ViewCenter are changed at the start of the Action.</param> /// <returns>Returns a status code indicating the success of the action.</returns> StatusCode getUserDynamicRotEx(bool changeView);//6017 60000964
三. 在HTML VBScript中使用FilterSelect
问:我不能使用FilterSelect或其他需要VDF对象的方法作为HTML VBScript中的参数。
答:此问题是一个“常见”问题,而不是FilterSelect的特定问题,适用于需要VDF对象的所有方法(如vdLine,vdLayer,vdBlock等)。在VBScript中,所有变量都是Objects / Variants,所以当一个函数需要一个特定的VDF对象(比如需要一个vdFilterObject对象的FilterSelect)时,它就不会工作并且会出现这样的错误。例如代码:
Set myFilter = VDraw.ActiveDocument.Selections.CreateFilter(myTypes, myLayers) Set gripselset = VDraw.ActiveDocument.Selections.FilterSelect("GRIPSELSET", myFilter) will raise an error. While the code : Set gripselset = VDraw.ActiveDocument.Selections.FilterSelect("GRIPSELSET", VDraw.ActiveDocument.Selections.CreateFilter(myTypes, myLayers)) will work fine (as we pass to the FilterSelect the output of the CreateFilter which is an object)
为了绕过它,必须使用WrapperObject,它的类型默认为Object(而不是 vd ...... something..object .. 对象,如vdFilterObject对象)。所以上面的代码应该改为:
Set myFilter = VDraw.ActiveDocument.Selections.CreateFilter(myTypes, myLayers) ' create the filter Set gripselset = VDraw.ActiveDocument.Selections.add( "GRIPSELSET") ' add the GRIPSELSET selection in document's selection gripselset.WrapperObject.FilterSelect myFilter.WrapperObject ' call the FilterSelect of the WrapperObject passing the myFilter.WrapperObject which is an OBJECT type.
注意:如果您尝试使用AddItem将VDF对象添加到集合,则会遇到同样的问题,例如:
Dim circ1 Set circ1 = VDraw.ActiveDocument.entities.AddCircle(Array(0, 0, 0), 5) gripselset.AddItem(circ1)
相反,你应该使用如下代码:
Dim circ1 Set circ1 = VDraw.ActiveDocument.entities.AddCircle(Array(0, 0, 0), 5) gripselset.WrapperObject.AddItem circ1.WrapperObject
四. 隐藏用户的特定XRref文件
问:是否可以延迟外部参照的加载,直到我的程序有机会决定哪些应该显示或不显示?据我所知,当图形文件及其所有附件已加载并转换时,将调用afterOpenDocument函数。我们希望能够为某些用户隐藏某些文件。
答:您可以通过设置为隐藏XRef文件的vdInserts(即vsBlocks)来完成此操作。请检查以下代码:(在空项目中添加vdFramed控件和打开图纸的按钮)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { vdFramedControl1.BaseControl.ActiveDocument.Open(@"C:\321\xref\master.vdml"); } private void Form1_Load(object sender, EventArgs e) { vdFramedControl1.BaseControl.ActiveDocument.OnAfterOpenDocument += new VectorDraw.Professional.vdObjects.vdDocument.AfterOpenDocument(ActiveDocument_OnAfterOpenDocument); } void ActiveDocument_OnAfterOpenDocument(object sender) { VectorDraw.Professional.vdObjects.vdDocument doc = (VectorDraw.Professional.vdObjects.vdDocument)sender; if (doc == null) return; //something gone bad ?!?! if (doc.TopMostDocumet != doc) return; //do not run the code below for the xrefs but only for the "Master" drawing //Create a selection VectorDraw.Professional.vdCollections.vdSelection selset = new VectorDraw.Professional.vdCollections.vdSelection("Myselset"); selset.SetUnRegisterDocument(vdFramedControl1.BaseControl.ActiveDocument); //Create a filter VectorDraw.Professional.vdObjects.vdFilterObject filter = new VectorDraw.Professional.vdObjects.vdFilterObject(); //Add vdInsert to select all polylines filter.Types.AddItem("vdInsert"); //Apply the filter. After this the selection will contain the selected polylines. selset.FilterSelect(filter); foreach (VectorDraw.Professional.vdFigures.vdInsert ins in selset) { if ((ins.Block.ExternalReference.FileName == @"C:\321\xref\circle1.vdml") || (ins.Block.ExternalReference.FileName == @"C:\321\xref\rect1.vdml")) // here check what xrefs you don't want to show { ins.visibility = VectorDraw.Professional.vdPrimaries.vdFigure.VisibilityEnum.Invisible;// here "set to invisible the xrefs" ins.Update(); } } } } }
未完待续~大家想看到VectorDraw产品的其他系列教程吗,留言告诉我们你的想法和建议,或许在下一篇文章中你的疑问就可以得到解答了~
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn