Method AddXProperty
- Namespace
- vdWebLibrary
- Assembly
- JsPropertiesExtractor.dll
AddXProperty(object, string, object)
Adds a new XProperty to the passed entity.
public object AddXProperty(object entity, string name, object propValue)
Parameters
entityobjectThe entity to add the new XProperty. It should be a valid vdraw object added in the document.
namestringA string representing the name of the XProperty.
propValueobjectThe 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.
Returns
- object
Returns the created XProperty or null if the function failed.
Examples
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.
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
}
}
}
}