%%PageItemTitle%%

VectorDraw Web Library

JsPropertiesExtractor Send comments on this topic.
AddXProperty Method
See Also  Example
vdWebLibrary Namespace > vdrawObj Class : AddXProperty Method
entity
The entity to add the new XProperty. It should be a valid vdraw object added in the document.
name
A string representing the name of the XProperty.
propValue
The value of the XProperty. Valid values for this are of Boolean, Number or String type. Also one lever arrays(not arrays withing arrays) of these types.
Adds a new XProperty to the passed entity.

Syntax

JScript 
public function AddXProperty( 
   entity : Object,
   name : String,
   propValue : Object
) : Object;

Parameters

entity
The entity to add the new XProperty. It should be a valid vdraw object added in the document.
name
A string representing the name of the XProperty.
propValue
The value of the XProperty. Valid values for this are of Boolean, Number or String type. Also one lever arrays(not arrays withing arrays) of these types.

Return Value

Returns the created XProperty or null if the function failed.

Example

Here is an example where we search in mousedown event for a specific XProperty of an entity and if we find it we change it’s value,if not we add a new one.
C#Copy Code
  
function _vdmousedown(e) { 
   var entity = e.target.GetEntityFromPoint(e.xPix, e.yPix); 
   if (entity.XProperties === undefined) {// in case there are not any XProperties we add the new that I want 
       var newExProp = vdcanvas.AddXProperty(entity, 'name1', 5.0); 
   } 
   else { 
       for (var i = 0; i < entity.XProperties.Items.length; i++) {//search for the XProperty we want by it’s name 
           if (entity.XProperties.Items[i].Name == "name1") { 
               var xprop = vdcanvas.GetXProperty(entity, "name1");//If we find the XProperty name that we search for, we change its value  
               xprop.PropValue = 'newValue';                      
           } 
           else { 
               if (newExProp) return; 
               var newExProp = vdcanvas.AddXProperty(entity, 'name1', 5.0); // if we didn’t find the Xproperty that we were searching for in the XProperties of the entity,we add a new one                       
           } 
       } 
   } 
}

See Also