翻譯|使用教程|編輯:黃竹雯|2018-12-03 10:25:28.000|閱讀 281 次
概述:本系列教程整理了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@fc6vip.cn