Hi Peter,

I think what might work best is to create a “starter” SVG object with all the 
<defs> contained within. I’ll save it to disk and load as needed.

Then when I extract the <g> I’ll insert the <g> into that sag doc and it should 
work.

In this case I have over 120 glyphs (sag images) that I preload and convert 
into base 64 that are part of the <def>

Then I reuse as needed.

Anyway, I’ll have to play with these very good ideas you suggested and see how 
far I get. No play time until early next week.

Appreciate,
John…


> 
> Hi Peter,
> 
> Ah yes thanks, I tend to forget that an SVG doc is in XML format.
> 
> Sometimes the solution winds up being so simple in 4D.
> 
> If the SVG doc uses <defs> for displaying various glyphs in the <g> object I 
> would assume that I need to also bring those into the doc?
> 
> 
> Yes, then you need to handle that as well. What I do is parse properties of 
> objects that are copied - like "mask", "fill" or "clip-path" properties - if 
> they contain "url(id)" value,  and if 'url' is used, I 1. find defs element 
> with given id, 2. move it to target as well and 3. change id of defs and 
> value of url to new, unique value (alternatively you could check if defs with 
> given 'id' was already moved and not move it.)
> 
> If you have control over how are SVG generated, you can make sure that defs 
> are included within the same group, and make sure all defs have unique id's. 
> Then you just copy the group. I did not have control over SVG, so had to use 
> more complex approach.
> 
> Peter Bozek
> 
> Appreciate,
> John…
> 
> 
> > Just use a XML commands and copy the node to another SVG files. AS SVG 
> > files are XML documents, you can use any XML DOM commands to manipulate SVG 
> > files.
> > 
> > Something like 
> > $group:=DOM Find XML element by ID(oldSVGImage;$groupID)
> > If (OK=1)
> >   $newEl:=DOM Append XML element(newSVGImage;$group)
> > end if
> > 
> > Peter Bozek
> > 
> > On Fri, Feb 28, 2020 at 5:08 PM John J Foster via 4D_Tech 
> > <[email protected] <mailto:[email protected]> 
> > <mailto:[email protected] <mailto:[email protected]>>> wrote:
> > Hi All,
> > 
> > I have an SVG Doc which contains many <g> grouped objects. Each group has a 
> > unique ID (name).
> > 
> > Sometimes I’d like to click on a part of the document, corresponding to a 
> > grouped object, and have it sent to the clipboard or saved as a png. Just 
> > the part of the document clicked on.
> > 
> > Is there a technique to easily extract a <g> object into it’s own SVG doc 
> > so I can save just the selected group as an png?
> > 
> > Yes, I could redraw each object that was selected but like to save that 
> > time if it’s possible.
> > 
> > Thanks,
> > John…
> 

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to