VDF常见问题整理(二十二):如何解决操作过程中的小问题

VectorDraw Developer Framework试用版下载


    在使用任何软件过程中都不可避免的会遇到一些问题,VectorDraw Developer Framework(VDF)也是同样的,本篇文章就将会解决几个我们使用过程的小问题。

怎么解决缺少SHX字体,文件打开缓慢的问题/strong>

问:

    我在使用过程中,由于缺少SHX字体,文件打开缓慢,这种情况怎么解决/p>

答:

    绘图使用一些.SHX字体文件作为默认VDF搜索路径中不存在的vdTextStyles,如果缺少,这会导致这种现象。因为在这些文本样式中,默认情况下,这些字体文件将替换为Arial TrueType字体,因为Arial的字符过多且Arial的复杂性,这些字符要花费更多的时间来计算其图形表示形式。

    为了加快此速度,绘图所使用的shx字体文件必须存在于VDF搜索路径中(例如,在绘图文件夹中-or-在vdDocument.SupportPath中定义的文件夹中-或- 应用程序的路径)。

     如果没有这些SHX字体文件,则还可以覆盖应用程序中的OnNoFileFind事件,以便用始终存在于应用程序路径中的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 handlerbool 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("rn Can not find file: " + fileName);            doc.Prompt(null);        }


如何清除已删除的布局或块项目/strong>

问:

    如何清除已删除的布局或块项目/p>

答:

    在下面,我们创建了两个不同的示例,说明如何从布局或块中清除已擦除的项目。

    示例1:清除已删除的活动布局项目。

 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:清除块中已擦除的项目

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


如何获取要复制或移动的对象/strong>

问:

    我想在复制/移动动作结束之前获取要复制或移动的对象的新位置,以便在新位置有效的情况下进行一些计算。如何执行此操作/p>

答:

    当动作为ActionGetTranfromSelection时,可以使用OnActionDraw事件,并使用动作的GetMatrix并检查诸如以下的对象:

       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         }     } }

活动激活时如何使用鼠标中键进行平移

问:

活动激活时如何使用鼠标中键进行平移/p>

答:

    您可以通过使用vdmoudown和vdmouseup事件来执行此操作,因为要这样做,您必须在要平移时暂停活动操作,然后将其恢复到当前命令。一旦使用鼠标中键进行平移,而不是使用左键完成命令,就可能发生这种情况。

    在下面,您可以看到一个示例:

  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();                                     }

    对于以上问答,如果您有任何的疑惑都可以在评论区留言,我们会及时回复。此系列的问答教程我们会持续更新,如果您感兴趣,可以多多关注本教程。

热门文章推荐:

如何排除GroundSurface对象的三角形区域/strong>

复杂自定义对象的入门指南

点击此处还有VectorDraw Developer Framework的demo示例等着你来体验哦!


    如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系在线客服>>咨询相关问题。

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年9月6日
下一篇 2019年9月6日

相关推荐

发表回复

登录后才能评论