70001164 How can i find an attribute by its tag value

Article 70001164
Type HowTo
Product WebJS
Date Added 9/4/2017 12:00:00 AM
Fixed 7.7012.0.5 (9/4/2017 12:00:00 AM)
Submitted by VectorDraw Team

Summary

How can i find an attribute by its tag value and change the display value

Solution

Suppose that we have a vdInsert with attribute(s)

Example 1: (search for an attribute with tag = "test1" for example)


           var entity = vdrawobj.GetEntityFromPoint(e.xPix, e.yPix);
            if (!entity || !entity.Attributes ) return;//NOTE the selected entity must be a vdInsert with Attributes
            for (var i = 0; i < entity.Attributes.Items.length; i++) {
                var attrib = entity.Attributes.Items[i];
                if (attrib.TagString == "test1") {
                        alert("attrib has been found");
                    }
                }
            }

 Example 2: (get the attribute value by passing the TagString)
            var attribvalue = vdrawobj.GetAttribValue("test1", entity);
            if (attribvalue) alert(attribvalue);


 Example 3: (Change the attribute value)
            vdrawobj.SetAttribValue("test1", "NewValue 1", entity);
            setTimeout(vdcanvas.redraw);//redraw  the scene to see the change of attrib value

Send comments on this topic.