70001067 ActionDraw event in order to display custom user shapes

Article 70001067
Type Wish
Product WebJS
Version 7010
Date Added 4/24/2017 12:00:00 AM
Fixed 7.7011.0.4 (4/25/2017 12:00:00 AM)
Submitted by Brendan Fry

Summary

ActionDraw event in order to display custom user shapes

Solution

A new event vdActionDraw was added in version 7011.0.4
In this example we calculate and show the distance and the rotation between reference and current point in drawing units
Example:

       vdcanvas.vdActionDraw = _vdActiondraw;
        function _vdActiondraw(action) {
             var ptref = action.ReferencePoint;//get the reference point in world Coordinate System
             if (!ptref || action.actionType != vdConst.ACTION_LINE_WORLD) return;//do nothing if the action is not waiting for a user reference point
             var ptcur = action.CurrentPoint;//get the current mouse location in world Coordinate system
             var dist = vdgeo.Distance3D(ptref, ptcur);//get the distance between reference and current point in drawing units
             var angle = vdgeo.GetAngle(ptref, ptcur);//get the angle counter-clockwise relative to x direction in radians
             if (angle > vdgeo.HALF_PI && angle < vdgeo.VD_270PI) angle += vdgeo.PI;//change the angle to be horizondally readable
             var angledeg = vdgeo.RadiansToDegrees(angle); //convert the angle in degrees
             //create a temporary text and draw it in the center of user raber reference line
             var midpt = vdgeo.MidPoint(ptref, ptcur);
             var txtSize = vdcanvas.GetPixelSize() * 20;
             var textvalue = dist.toFixed(2) + '<' + angledeg.toFixed(2);
             var txt = vdcanvas.AddText(textvalue, txtSize, midpt, vdConst.VdConstHorJust_VdTextHorCenter, vdConst.VdConstVerJust_VdTextVerBottom, angle, false, {});
             txt.PenColor = vdConst.colorFromString("255,0,0");
             vdcanvas.DrawEntity(txt);
        }

Example 2: Place a rectangle on the cursor position and note that this rectangle is not be added in the document so it not be added also in the undo history.It is a temporary figure.


vdcanvas.vdActionDraw = _vdActiondraw;//define the function in the initialize of the canvas
function _vdActiondraw(action) {
           if (action.actionType == vdConst.ACTION_POINT_WORLD || action.actionType == vdConst.ACTION_LINE_WORLD) {// You can check here whatever you want for when to show the rect.I show it when it waiting for a point or a reference point 
               var ptcur = action.CurrentPoint; //get the current mouse location in world Coordinate system
               var rectSize = vdcanvas.GetPixelSize() * 30; // set the size of the rectangle exact 30 pixels so if you zomm in/out the size of the rect will always remains 30 pixels
               var inspt = [ptcur[X] - rectSize / 2, ptcur[Y] - rectSize / 2, ptcur[Z]];// set the insertion point of the rectangle
               var rect = vdcanvas.AddRect2(inspt, rectSize, rectSize, 0.0, false, {}); // add the recr but without draw it and by using '{}' the rect will not be added in the document so neither to undo history             
               vdcanvas.DrawEntity(rect);//draw the rect 
           }
       }

Send comments on this topic.