VDF常见问题整理(三十八):如何插入折线的预定义形状?

VectorDraw Developer Framework试用版下载


问:

    用户如何在不使用预定义块的情况下将预定义的折线形状放置在布局中的某处/p>

答:

示例:

    我们首先使用scriptCommand.rect制作一个矩形(或一条线,一条折线等),然后在rect的回调中调用actionentityadded,它调用了scriptCommand.select,所以现在矩形已经被选中,在select的回调中我们调用moveCallback,所以现在我们可以移动矩形并将其放置在所需位置。

    在scriptCommand.move的回调中,我们调用sclaleCallback,该脚本运行scriptCommand.scale()或scriptCommand.rotate()。缩放或旋转逗 的回调,调用函数actionfinish,在其中更新布局,重新绘制画布,然后将SetActionLineColor(null)恢复为默认值。

 function redo() {            vdcanvas.scriptCommand.redo();            setTimeout(vdcanvas.redraw);       }         function undo() {            vdcanvas.scriptCommand.undo();            setTimeout(vdcanvas.redraw);       }           function polyline() {           //we start the undogroup            vdcanvas.scriptCommand.undogroup('begin');            //create a rect for example with InsertionPoint too far in order not to be draw on screen            vdcanvas.scriptCommand.rect([[2000, 2000, 0], 3.0, 4.0,0], actionentityadded);       }       function actionentityadded(vdrawobj, entity) {            vdrawobj.SetActionLineColor([0, 0, 0, 0]);//set the action line color invisible            vdrawobj.scriptCommand.select([entity], movecallback);//update script select with user entity and call the move command       }       function movecallback(vdrawobj) {            var rect = vdcanvas.scriptCommand.ActiveSelection()[0];            vdcanvas.scriptCommand.move(rect.InsertionPoint, null, sclaleCallback);//call move action with reference the InsertionPoint of rect       }       function sclaleCallback(vdrawobj) {            var rect = vdcanvas.scriptCommand.ActiveSelection()[0];            if (!vdrawobj.ActiveAction().IsCanceled()) {            //vdrawobj.scriptCommand.scale(rect.InsertionPoint, null, actionfinish); //call scale or rotate action with reference the InsertionPoint of rect vdcanvas.scriptCommand.rotate(rect.InsertionPoint,null,actionfinish);            }            else {//user press esc or right-click so the command is canceled               actionfinish(vdrawobj);              }        }        function actionfinish(vdrawobj) {            var rect = vdrawobj.scriptCommand.ActiveSelection()[0];            if (vdrawobj.ActiveAction().IsCanceled()) {//in case action is canceled by the user esc or right click                rect.Deleted = true;//mark the create figure as deleted                vdrawobj.UpdateLayout(); //mark the layout bounds to be updated                 setTimeout(vdrawobj.redraw);//post a redraw in order to clear existing entity draw by the active action            }            vdrawobj.SetActionLineColor(null);//restore action line color to default value.            vdcanvas.scriptCommand.undogroup('close');//Close the undogroup         }

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

热门文章推荐:

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

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


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

标签:

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

上一篇 2019年10月15日
下一篇 2019年10月15日

相关推荐

发表回复

登录后才能评论