4D v16.3

SVG SET ATTRIBUTE

Home

 
4D v16.3
SVG
SVG SET ATTRIBUTE

SVG SET ATTRIBUTE 


 

SVG SET ATTRIBUTE ( {* ;} pictureObject ; element_ID ; attribName ; attribValue {; attribName2 ; attribValue2 ; ... ; attribNameN ; attribValueN} {; *}) 
Parameter Type   Description
Operator in If specified, pictureObject is an object name (string) If omitted, pictureObject is a variable
pictureObject  Picture in Object name (if * specified) or Variable or field (if * omitted)
element_ID  Text in ID of element where one or more attributes are set
attribName  String in Attribute to be specified
attribValue  String, Longint in New value of attribute
Operator in If passed = modify internal DOM tree of SVG image (variable only)

The SVG SET ATTRIBUTE command is used to modify the value of an existing attribute in the SVG rendering tree of a displayed image or in the internal DOM tree of an image. 

If you pass the optional * parameter, you indicate that the pictureObject parameter is an object name (string). In this case, the command applies to the parameters of the rendered image attached to the object (note that the parameters and therefore the rendered image of the object are only created if the SVG SET ATTRIBUTE command is called at least once).
If you do not pass the * parameter, you indicate that the pictureObject parameter is a variable or a field. Therefore, you pass a variable (object variable only) or field reference instead of a string. In this case, the command applies to the rendered images of all the objects that use the variable or the field.

By default, modifications made by this command apply only to the rendered images; they are not stored in the data source (internal DOM tree) and are lost when the picture is erased by programming or when the form is closed. However, you can transfer these changes into the internal DOM tree of the image when the pictureObject parameter references a variable: you just need to pass the second * as the last parameter. This lets you keep the modifications made on the fly. 

Notes:

  • Transferring modifications into the internal DOM tree is not possible when the pictureObject parameter references an object.
  • To be able to transfer modifications, the SVG variable must have been created from a DOM document (with DOM EXPORT TO VAR). If the SVG variable was created from a file, when you pass the second * parameter, the command does nothing and an error is generated because, in this case, the data source does not contain a modifiable DOM document.
  • To change the data source of an SVG image, you can also use the XML DOM commands or the MissingRef provided by 4D.

The element_ID parameter is used to specify the ID ("id" or "xml:id" attribute) of the element whose attribute(s) you want to modify.

In the attribName and attribValue parameters, pass, respectively, the attribute to set and its value (as variables, fields or literal values). You can pass as many attribute/value pairs as you want. 

The SVG SET ATTRIBUTE command is used to modify (but not to add or delete) most of the SVG attributes, such as, for instance, 'fill', 'opacity', 'font-family', and so on. For a complete definition of the SVG attributes, please refer to the reference documents available on the Internet, for example: http://www.w3.org/TR/SVG11/attindex.html. The rendered image is updated immediately; the modifications are transferred on to the child elements for inherited styles. 

Note that for technical reasons, the attributes of certain elements as well as certain attributes cannot be modified. The following table lists the elements that can be modified, and those that cannot, as well as the attributes that cannot be modified:

Elements whose attributes can be modified

svgRestrictions :
- "width" and "height" cannot be modified(1)
- "viewBox" can only be modified if "width" and "height" are specified in the original document
g
defs
use
filterRestriction: fe_xxx child elements cannot be modified
circle
ellipse
line
polyline
polygon
path
rect
text, tspan, textAreaThe specific "4d-text" attribute is used to modify the text of a "text", "tspan" or "textArea" element (see the example)
Image

Elements whose attributes cannot be modified

linearGradient, radialGradient, Stop, solidColor, marker, symbol, clipPath, filter et les éléments commençant par fe, style, patternThis group designates all the elements that can be referenced or contained in an element that can be referenced. This means that it is not possible, for example, to redefine the attributes of a gradient (but it is possible to change the gradient used). Similarly, to change a black color marker to a red marker, it is necessary to define both markers in the SVG document (one black and one red) and to select one of them. It is not possible either for example to modify the color of a rectangle if its parent is a symbol or marker element

Attributes that cannot be modified

id or xml:id
lang or xml:lang
class or xml:class
width, heightConcerns the attributes of the 'svg' element only(1)

(1) These attributes cannot be modified because they define and structure the resulting image. The width and height attributes of the svg element are used to define the initial dimensions of the picture in 4D and these dimensions must remain constant after the picture is created (it is however possible to modify the dimensions of the resulting picture with the TRANSFORM PICTURE command of 4D).

You can also refer to the description of the SVG GET ATTRIBUTE command to see the list of 4D attributes that are reserved and dedicated to animation.

If you attempt to modify the attribute of an element that is not supported or one of its child elements, the command does nothing and no error is generated.

If the command is not executed in the context of a form or if an invalid pictureObject is passed, the OK variable is set to 0. If the command has been executed correctly, it is set to 1.

Example  

Modification of the contents of a Text type element:

 SVG SET ATTRIBUTE(*;picture_object_name;text_element_ID;"4d-text";"This is a text")

Note: There is no namespace in order that the attribute could be used in a CSS style sheet without risk of conflict.



See also 

SVG GET ATTRIBUTE

 
PROPERTIES 

Product: 4D
Theme: SVG
Number: 1055

The OK variable is changed by the command

 
HISTORY 

Created: 4D v12
Modified: 4D v12.3

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)