Search code examples
javascriptsvgpaperjs

Paperjs SVG import: How to access group id's


In paperjs I'm importing an SVG file that has elements like this:

<g id="Layer_4">
    <circle fill="#F42700" cx="114.5" cy="249.5" r="50"/>
    <circle fill="#F42700" cx="385.5" cy="249.5" r="50"/>
</g>
<g id="Layer_3">
    <path fill="#8A0055" d="M408,263l-36-0.3V38c0-0.3-..."/>
</g>

Those top level groups are accessible in the parsed SVG as direct children of the created SVG object. But aside from their order, is there any way I can retrieve the original id parameter?


Solution

  • Top level group ids turn into item.name parameters, like:

    paper.project.import("path/to/svg.svg", function (item) {
        console.log(item.firstChild.name)
    }
    

    As per this comment.