70000965 Change order of objects

Article 70000965
Type Wish
Product WebJS
Version 7009
Date Added 12/15/2016
Fixed 7.7010.0.6 (12/16/2016)
Submitted by Shave Cawser

Summary

Is it possible to change the draw order of objects?

Solution

In version 7010.0.6 new methods GetEntityPosition , SetEntityPosition was added in vdcanvas control
int GetEntityPosition(object entity, object collection) ;
Returns the entity's (zero based)position inside the collection it belongs to.or -1 for no success
"entity" : An object reference to find its position
"collection" : Optional. A collection where the entity belongs. If not defined the ActiveLayout entities is used. If entity does not belongs to the collection the function returns -1.


int SetEntityPosition(object entity,int pos, object collection) ;
Change the entity position inside the passed collection
"entity" : An object reference
"pos" :
An integer(zero based) to new position, if pos <0 move the entity to the begin of the collection.if >= collection.length move it at the end
The entity that was previous in pos move to pos+1 if passed entity was after pos -or to pos-1 if passed entity was before pos .
"collection" : A collection where the entity belongs. If not defined the ActiveLayout entities is used. If entity does not belongs to the collection the function returns -1.
returns : New position of the passed entity or -1 for no success

Example:
        
        vdcanvas.SetActiveHatchProperties(vdcanvas.createNewHatchProperties('solid', vdConst.colorFromString("byblock"), vdConst.colorFromString("255,255,255")));//solid white circle
        var c0 = vdcanvas.AddCircle([0, 0, 0], 5);
        vdcanvas.SetActiveHatchProperties(vdcanvas.createNewHatchProperties('solid', vdConst.colorFromString("byblock"), vdConst.colorFromString("255,0,0")));//solid red circle
        var c1 = vdcanvas.AddCircle([1, 1, 0], 5);
        vdcanvas.SetActiveHatchProperties(vdcanvas.createNewHatchProperties('solid', vdConst.colorFromString("byblock"), vdConst.colorFromString("0,255,0")));//solid green circle
        var c2 = vdcanvas.AddCircle([2, 0, 0], 5);
        vdcanvas.SetActiveHatchProperties(vdcanvas.createNewHatchProperties('solid', vdConst.colorFromString("byblock"), vdConst.colorFromString("0,0,255")));//solid blue circle
        var c3 = vdcanvas.AddCircle([3, 1, 0], 5);
        //move the blue circle to the posistion of red circle (red circle will be placed just after blue)
        vdcanvas.SetEntityPosition(c3, vdcanvas.GetEntityPosition(c1));
        //-or-
        //move blue circle to start of the active layout entities collection
        vdcanvas.SetEntityPosition(c3, 0);
        //-or-
        //move white circle at the end of active layout entities collection
        vdcanvas.SetEntityPosition(c0, 100000/*enough bigger that entities length in active layout collection*/);
        

Send comments on this topic.