how to get property of a selected element
function getProperty(selection) {
console.log(selection.items[0].height); //prints 256
}
the code gives selected element property
but
function getProperty(selection) {
console.log(Object.keys(selection.items[0])); //prints [ '_childrenList' ]
}
doesn’t include height property
how to get all property of a selected element ?
Hi @prasanta
Getting all the properties of a node, unfortunately, isn’t possible. The reason behind this is that Object.keys()
(and similar functions) only consider an object’s “own” properties (added directly to the object), but not the ones coming from the class (prototype, etc.).
Therefore, you could only manually create a script that returns the properties of a node by checking its type (and using the documentation), things like hasOwnProperty()
, Object.keys()
or JSON.stringify()
unfortunately won’t work.
If you only need it for personal reference, I suggest using the documentation or (for autocompletion) the typescript definitions (see Adding autocompletion and linting in editors and IDEs) .
4 Likes
any idea how i can do it ?
Basically, you first need to detect the node’s type (for some node types, you can e.g. do this with const {Text} = require('scenegraph'); if (yourNode instanceof Text) { /* Do stuff here */ }
).
Then, you’ll need to create a new object containing all the properties this type owns according to the documentation:
return {
text: yourNode.text,
// [...]
textStyles: yourNode.textStyles
}
This – as you can see – is a very tedious (since manual) process (and I don’t think there is an alternative way right now). Therefore, it might be useful to know the use case you have (since I was part of the Beta team and therefore already know a few developers, I might be able to help by knowing some alternative solution somone has come up with). Without the use-case (or at least the general type of use case like “I want to create a JSON covering all the node’s details” – you, of course, don’t need to post any specifics about your project ), this, unfortunately, is all the help I can provide.
3 Likes
any idea where i can get all those property list ?
@prasanta You will need to refer to the scenegraph
section of the API reference (https://adobexdplatform.com/plugin-docs/reference/scenegraph.html) for that.
Best,
Pablo
3 Likes