新手入門必看:VectorDraw 常見問題整理大全(十四)
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。該庫還支持許多矢量和柵格輸入和輸出格式,包括本地PDF和SVG導(dǎo)出。
【VectorDraw Developer Framework最新版下載】
VectorDraw web library (javascript)是一個(gè)矢量圖形庫。VectorDraw web library (javascript)不僅能打開CAD圖紙,而且能顯示任何支持HTML5標(biāo)準(zhǔn)平臺(tái)上的通用矢量對(duì)象,如Windows,安卓,iOS和Linux。無需任何安裝,VectorDraw web library (javascript)就可以運(yùn)行在任何支持canvas標(biāo)簽和Javascript的主流瀏覽器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。
【VectorDraw web library (javascript)最新版下載】
一. 在用戶繪制命令后計(jì)算和繪制某些實(shí)體
問:如何在用戶繪制命令后計(jì)算和繪制一些實(shí)體?例如,我想繪制2條線,這些線將代表用戶使用cmdCircle等自動(dòng)命令繪制的圓的半徑和直徑。
答:cmdCircle(以及幾乎所有命令動(dòng)作)如果成功與否則返回布爾值,因此在cmdCircle返回true后,您可以將最后添加的實(shí)體添加到實(shí)體集合(這將是您的用戶繪制的圓圈)并獲取中心點(diǎn)和半徑。使用這些值,您可以計(jì)算兩個(gè)點(diǎn),并添加/繪制直徑尺寸或直線。例如,請(qǐng)參閱下面的代碼(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”而不更改旋轉(zhuǎn)中心
問:我正在嘗試將旋轉(zhuǎn)點(diǎn)固定到圖形中某個(gè)對(duì)象的最后一個(gè)頂點(diǎn)?,F(xiàn)在,如果我保持在“白色旋轉(zhuǎn)圓”之外,則旋轉(zhuǎn)操作按預(yù)期起作用,即線的終點(diǎn)保持在圖中心的固定位置。但是,如果我在圓圈內(nèi)移動(dòng),那么“固定”點(diǎn)會(huì)移動(dòng)。這不是我正在尋找的行為。我需要“目標(biāo)”點(diǎn)保持在圖紙的中心。我怎樣才能做到這一點(diǎn)?
答:在6017版本中,可以使用新功能以按您希望的方式旋轉(zhuǎn)視圖。您必須像在項(xiàng)目中一樣設(shè)置視圖(矩陣)和視圖中心,而不是調(diào)用View3D“VROT”,您將調(diào)用包裝器的新方法。例如(粗體變化):
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
新函數(shù)是getUserDynamicRotEx,它接受一個(gè)布爾值。有了這個(gè)布爾值,它就像希望的那樣工作,而傳遞真實(shí)它就像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對(duì)象的方法作為HTML VBScript中的參數(shù)。
答:此問題是一個(gè)“常見”問題,而不是FilterSelect的特定問題,適用于需要VDF對(duì)象的所有方法(如vdLine,vdLayer,vdBlock等)。在VBScript中,所有變量都是Objects / Variants,所以當(dāng)一個(gè)函數(shù)需要一個(gè)特定的VDF對(duì)象(比如需要一個(gè)vdFilterObject對(duì)象的FilterSelect)時(shí),它就不會(huì)工作并且會(huì)出現(xiàn)這樣的錯(cuò)誤。例如代碼:
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,它的類型默認(rèn)為Object(而不是 vd ...... something..object .. 對(duì)象,如vdFilterObject對(duì)象)。所以上面的代碼應(yīng)該改為:
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對(duì)象添加到集合,則會(huì)遇到同樣的問題,例如:
Dim circ1 Set circ1 = VDraw.ActiveDocument.entities.AddCircle(Array(0, 0, 0), 5) gripselset.AddItem(circ1)
相反,你應(yīng)該使用如下代碼:
Dim circ1 Set circ1 = VDraw.ActiveDocument.entities.AddCircle(Array(0, 0, 0), 5) gripselset.WrapperObject.AddItem circ1.WrapperObject
四. 隱藏用戶的特定XRref文件
問:是否可以延遲外部參照的加載,直到我的程序有機(jī)會(huì)決定哪些應(yīng)該顯示或不顯示?據(jù)我所知,當(dāng)圖形文件及其所有附件已加載并轉(zhuǎn)換時(shí),將調(diào)用afterOpenDocument函數(shù)。我們希望能夠?yàn)槟承┯脩綦[藏某些文件。
答:您可以通過設(shè)置為隱藏XRef文件的vdInserts(即vsBlocks)來完成此操作。請(qǐng)檢查以下代碼:(在空項(xiàng)目中添加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(); } } } } }
未完待續(xù)~大家想看到VectorDraw產(chǎn)品的其他系列教程嗎,留言告訴我們你的想法和建議,或許在下一篇文章中你的疑問就可以得到解答了~