VDF常見(jiàn)問(wèn)題整理(二十二):如何解決操作過(guò)程中的小問(wèn)題
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫(kù)。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
在使用任何軟件過(guò)程中都不可避免的會(huì)遇到一些問(wèn)題,VectorDraw Developer Framework(VDF)也是同樣的,本篇文章就將會(huì)解決幾個(gè)我們使用過(guò)程的小問(wèn)題。
怎么解決缺少SHX字體,文件打開(kāi)緩慢的問(wèn)題?
問(wèn):
我在使用過(guò)程中,由于缺少SHX字體,文件打開(kāi)緩慢,這種情況怎么解決?
答:
繪圖使用一些.SHX字體文件作為默認(rèn)VDF搜索路徑中不存在的vdTextStyles,如果缺少,這會(huì)導(dǎo)致這種現(xiàn)象。因?yàn)樵谶@些文本樣式中,默認(rèn)情況下,這些字體文件將替換為Arial TrueType字體,因?yàn)锳rial的字符過(guò)多且Arial的復(fù)雜性,這些字符要花費(fèi)更多的時(shí)間來(lái)計(jì)算其圖形表示形式。
為了加快此速度,繪圖所使用的shx字體文件必須存在于VDF搜索路徑中(例如,在繪圖文件夾中-or-在vdDocument.SupportPath中定義的文件夾中-或- 應(yīng)用程序的路徑)。
如果沒(méi)有這些SHX字體文件,則還可以覆蓋應(yīng)用程序中的OnNoFileFind事件,以便用始終存在于應(yīng)用程序路徑中的SHX文件替換未引用的SHX字體文件,如下所示:
//In this example we substitute all unreferenced shx files with txt.shx which must exist in the drawing folder or in the application path. .... doc.OnNoFileFind += new vdDocument.NoFileFindEventHandler(ActiveDocument_OnNoFileFind); // add the event handler bool fontSubstitute = false; // a “public” variable to avoid recursion of event .... void ActiveDocument_OnNoFileFind(object sender, ref string fileName, ref bool success) { //Substitute shx font files with existing txt.shx font file. if (!fontSubstitute && fileName.EndsWith(".shx")) { fontSubstitute = true;//set it to true in order not to have recursion success = doc.FindFile("txt.shx", out fileName); fontSubstitute = false; if (success) return; } doc.Prompt("\r\n Can not find file: " + fileName); doc.Prompt(null); }
如何清除已刪除的布局或塊項(xiàng)目?
問(wèn):
如何清除已刪除的布局或塊項(xiàng)目?
答:
在下面,我們創(chuàng)建了兩個(gè)不同的示例,說(shuō)明如何從布局或塊中清除已擦除的項(xiàng)目。
示例1:清除已刪除的活動(dòng)布局項(xiàng)目。
var tempCol = []; var activelayout = vdcanvas.GetActiveLayout(); for (var k = 0; k < activelayout.Entities.Items.length; k++) { var fig = vdcanvas.GetEntityItem(activelayout.Entities.Items[k]); if (!fig.Deleted) tempCol.push(activelayout.Entities.Items[k]);//If not an item is Deleted we push it in our tempCol } activelayout.Entities.Items = tempCol;//update the active layout entities with the tempCol
示例2:清除塊中已擦除的項(xiàng)目
var tempCol = []; var blk = vdcanvas.AddBlock("myblock");//let's say that the block we want to update is the 'blk' for (var k = 0; k < blk.Entities.Items.length; k++) { var fig = vdcanvas.GetEntityItem(blk.Entities.Items[k]); if (!fig.Deleted) tempCol.push(blk.Entities.Items[k]);//If not an item is Deleted we push it in our tempCol } blk.Entities.Items = tempCol;//update the block entities with the tempCol
如何獲取要復(fù)制或移動(dòng)的對(duì)象?
問(wèn):
我想在復(fù)制/移動(dòng)動(dòng)作結(jié)束之前獲取要復(fù)制或移動(dòng)的對(duì)象的新位置,以便在新位置有效的情況下進(jìn)行一些計(jì)算。如何執(zhí)行此操作?
答:
當(dāng)動(dòng)作為ActionGetTranfromSelection時(shí),可以使用OnActionDraw事件,并使用動(dòng)作的GetMatrix并檢查諸如以下的對(duì)象:
void doc_OnActionDraw(object sender, object action, bool isHideMode, ref bool cancel) { if (action != null && action is VectorDraw.Professional.CommandActions.ActionGetTranfromSelection) { VectorDraw.Professional.CommandActions.ActionGetTranfromSelection trans = action as VectorDraw.Professional.CommandActions.ActionGetTranfromSelection; vdSelection sel = trans.Layout.Document.Selections.FindName("VDRAW_PREVIOUS_SELSET");// sel contains the object that are moved/copied/rotated etc. if (sel == null || sel.Count == 0) return; // this.Text = sel.Count.ToString(); /// for debugging Matrix mat = trans.GetMatrix(); // this is the matrix that is applied to the source object by the action foreach (vdFigure item in sel) { vdFigure tempfig = item.Clone(item.Document) as vdFigure; // get a coly of this object being transformed (copied/moved etc) tempfig.Transformby(mat); // transform this with the action’s GetMatrix // this tempfig is the temporary figure rendered by action copy/move etc // using this tempfig object you can do your calid position check, using bounding box etc } } }
活動(dòng)激活時(shí)如何使用鼠標(biāo)中鍵進(jìn)行平移
問(wèn):
活動(dòng)激活時(shí)如何使用鼠標(biāo)中鍵進(jìn)行平移?
答:
您可以通過(guò)使用vdmoudown和vdmouseup事件來(lái)執(zhí)行此操作,因?yàn)橐@樣做,您必須在要平移時(shí)暫?;顒?dòng)操作,然后將其恢復(fù)到當(dāng)前命令。一旦使用鼠標(biāo)中鍵進(jìn)行平移,而不是使用左鍵完成命令,就可能發(fā)生這種情況。
在下面,您可以看到一個(gè)示例:
var vdcanvas = vdmanager.AttachCanvas('canvas'); vdcanvas.vdmousedown = _vdmousedown; //set to the initialize page load vdcanvas.vdmouseup = _vdmouseup; vdcanvas.ActiveAction().PanMouseButton = vdConst.MouseMiddleButton; // set the middle mouse button for panning procedure function _vdmousedown(e) { var code = e.mousebutton; //get the mouse button code if (code === 2)vdcanvas.ActiveAction().Pause(); // middle mouse code is 2 } function _vdmouseup(e) { //resume the action when finishing the panning var code = e.mousebutton; if (code === 2)vdcanvas.ActiveAction().Resume(); }
對(duì)于以上問(wèn)答,如果您有任何的疑惑都可以在評(píng)論區(qū)留言,我們會(huì)及時(shí)回復(fù)。此系列的問(wèn)答教程我們會(huì)持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
熱門(mén)文章推薦:
如何排除GroundSurface對(duì)象的三角形區(qū)域?
點(diǎn)擊此處還有VectorDraw Developer Framework的demo示例等著你來(lái)體驗(yàn)哦!
如果您對(duì)想要購(gòu)買(mǎi)正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關(guān)問(wèn)題。
關(guān)注慧聚IT微信公眾號(hào) ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。