-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvgConverter.js
29 lines (22 loc) · 876 Bytes
/
svgConverter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function tinkerCadSVGtoRDWorksSVG(fileId) {
var file = DriveApp.getFileById(fileId);
var svgFile = XmlService.parse(file.getBlob().getDataAsString());
var svg = svgFile.getRootElement();
var elements = svg.getChildren();
for(var i=0; i< elements.length;i++){
if(elements[i].getName() == "path"){
var pathAttr = elements[i].getAttributes();
elements[i].setName("g");
var newPath = XmlService.createElement("path",svg.getNamespace());
for(var j=0;j< pathAttr.length;j++){
elements[i].removeAttribute(pathAttr[j].getName());
newPath.setAttribute(pathAttr[j].getName(), pathAttr[j].getValue());
}
newPath.removeAttribute("xmlns");
elements[i].addContent(0,newPath);
}
}
var newFile = file.makeCopy();
newFile.setContent(XmlService.getPrettyFormat().format(svgFile))
return newFile
}