70001097 How can i highlight a vdInsert

Article 70001097
Type HowTo
Product WebJS
Date Added 6/7/2017 12:00:00 AM
Fixed 7.7012.0.1 (6/7/2017 12:00:00 AM)
Submitted by Daniel Borquaye

Summary

What I want to achieve is when hovering over these they should become highlighted, or even better, a solid hatch is drawn inside. But I think this is not possible as this is a vdInsert rather than a standard shape like rect.

Solution

The vdInsert object can not be highlighted so insted of this we create a new rectangle in the size of
the bounding box of the block and we highlight this rectangle.
Below is an example where we load a vds file using AddBlockFromFile(ccc.vds) method and we create a new
block(aaa).
After that we call the vdmousemove and vdmouseout methods which we need in order when cursor is above
the rectangle which contains the block,the rectangle will be highlighted.And using the vdmouseout method
when the cursor it out of the area of the rectangle,the rectangle will not be highlighted any more.



var lastSelectedEntity = null;//Keep the entity in a variable function _vdmousemove(e) { if (vdcanvas.ActiveAction().IsStarted()) return;// We check tha action in case another action has been started var entity = e.target.GetEntityFromPoint(e.xPix, e.yPix);// Found the entity above the cursor if (entity == lastSelectedEntity) return; lastSelectedEntity = entity; if (entity != null && entity._t == vdConst.vdInsert_code && entity.BlockRef && entity.BlockRef.Name == "aaa") {//if the entity is the block that we want var minpt = [entity.BoundingBox[0], entity.BoundingBox[1], entity.BoundingBox[2]];//The lowest left corner of the boundingBox var maxpt = [entity.BoundingBox[3], entity.BoundingBox[4], entity.BoundingBox[5]]; //The upper right corner of the boundingBox var rect = vdcanvas.AddRect(minpt, maxpt, false, {});//We draw a rectangle in the size of the bounding box of the block //rect.HatchProperties = vdcanvas.createNewHatchProperties("solid", vdConst.colorFromString("byblock"), vdConst.colorFromString("255,0,0,50")); rect.HatchProperties = vdcanvas.createNewHatchProperties("u20", vdConst.colorFromString("255,255,255,50"), vdConst.colorFromString("255,255,255,255"), 1, vdgeo.DegreesToRadians(45));//We add hatch properties to the rect vdcanvas.Refresh(); vdcanvas.ActionDrawEntities([rect]);//We draw the rect } else { vdcanvas.ActionDrawEntities(null); } } function _vdmouseout(e) {//Incase cursor is out of the canvas if (!lastSelectedEntity) return; lastSelectedEntity = null; vdcanvas.ActionDrawEntities(null); } function test() { var blk = vdcanvas.AddBlockFromFile("ccc.vds", "aaa", true);//We load the block from ccc.vds vdcanvas.AddBlockSymbol("aaa", [0, 0, 0], 1, 0, true, null);//We draw the block vdcanvas.zoomExtents(); vdcanvas.redraw(); vdcanvas.vdmousemove = _vdmousemove; vdcanvas.vdmouseout = _vdmouseout;//Incase cursor is out of the canvas }

Send comments on this topic.