[Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
clarkitect
Posts: 39
Joined: Sat Sep 19, 2015 1:57 pm

[Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by clarkitect »

The <use> element is super handy and allows referencing external svg files, but it requires an identifier within the target svg. Can we add an id tag to the output from techdraw to allow this to work as is currently possible with the old drawing wb?

I posted about this very effiecient workflow which incorporates the <use> element in this thread titled "using inkscape as the paperspace". I think this is really important in order to integrate inkscape and freecad as far as possible as per issue #3304

I believe all it would take is to wrap the techdraw output in a group with:

Code: Select all

id="Page001"
Using the name of the selected page for export as the group ID probably makes the most sense...

What do we think?

Cheers
Ben
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by wandererfan »

clarkitect wrote: Thu Nov 15, 2018 1:08 am The <use> element is super handy and allows referencing external svg files, but it requires an identifier within the target svg. Can we add an id tag to the output from techdraw to allow this to work as is currently possible with the old drawing wb?
DrawingWB puts a <g id="Viewxxx"> around each View on the exported Page. Do you need id's for each View or 1 for the whole page?
clarkitect wrote: Thu Nov 15, 2018 1:08 am I believe all it would take is to wrap the techdraw output in a group with:

Code: Select all

id="Page001"
Using the name of the selected page for export as the group ID probably makes the most sense...
Much easier to do this in Drawing since it "hand crafts" the Svg code. In TechDraw we call a Qt function that "paints" the current scene to a file as Svg. We'll have to post process the output Svg file to insert group tag(s) with id elements.

I hand-edited the attached TD export file to add a <g id='MyPage'> ....</g> around the body of the code. Is this what you're looking for?
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by Kunda1 »

wandererfan wrote: Thu Nov 15, 2018 2:07 pm I hand-edited the attached TD export file to add a <g id='MyPage'> ....</g> around the body of the code. Is this what you're looking for?
You forgot the attachment ;)
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by wandererfan »

Kunda1 wrote: Thu Nov 15, 2018 5:09 pm You forgot the attachment ;)
Can't seem to attach anything.

Here it is on dropbox.
clarkitect
Posts: 39
Joined: Sat Sep 19, 2015 1:57 pm

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by clarkitect »

wandererfan wrote: Thu Nov 15, 2018 2:07 pm DrawingWB puts a <g id="Viewxxx"> around each View on the exported Page. Do you need id's for each View or 1 for the whole page?
1 for the whole page would be fine in my view. Although having unique IDs for each view would offer very fine grained control. For example you could have different views in techdraw appearing on different layers in inkscape, allowing turning off and on for easier editing.
wandererfan wrote: Thu Nov 15, 2018 2:07 pm I hand-edited the attached TD export file to add a <g id='MyPage'> ....</g> around the body of the code. Is this what you're looking for?
Yes, I've attached the 'paperspace' svg referencing in your file to demonstrate.
wandererfan wrote: Thu Nov 15, 2018 2:07 pm Much easier to do this in Drawing since it "hand crafts" the Svg code. In TechDraw we call a Qt function that "paints" the current scene to a file as Svg. We'll have to post process the output Svg file to insert group tag(s) with id elements.
I see. So is there a way to do this post processing automatically on save? I worry because the drawing wb will eventually be deprecated as I understand, and this is really important functionality to harness the power of inkscape in a good workflow.
Attachments
PaperSpace.svg
(3.01 KiB) Downloaded 54 times
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by wandererfan »

clarkitect wrote: Thu Nov 15, 2018 10:05 pm I see. So is there a way to do this post processing automatically on save? I worry because the drawing wb will eventually be deprecated as I understand, and this is really important functionality to harness the power of inkscape in a good workflow.
Yes, the target would be to do the post processing automagically. Have to look into it before I can say more.

As I understand it, there are no plans (yet?) to remove the DrawingWB, but it is no longer being actively developed.
clarkitect
Posts: 39
Joined: Sat Sep 19, 2015 1:57 pm

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by clarkitect »

wandererfan wrote: Fri Nov 16, 2018 2:34 pm Yes, the target would be to do the post processing automagically. Have to look into it before I can say more.
Automagically :lol: that's a new one. Would be great if so.
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by wandererfan »

clarkitect wrote: Thu Nov 15, 2018 1:08 am I believe all it would take is to wrap the techdraw output in a group with:

Code: Select all

id="Page001"
Using the name of the selected page for export as the group ID probably makes the most sense...
Working in test environment:
PageIdinSvg.png
PageIdinSvg.png (73.16 KiB) Viewed 1825 times

If you're going to be working with Svg pages from multiple FreeCAD documents, should it show documentName+pageName? You could get a bunch of Svg files all with "id=Page".
clarkitect
Posts: 39
Joined: Sat Sep 19, 2015 1:57 pm

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by clarkitect »

That's great! Awesome stuff.
wandererfan wrote: Thu Dec 06, 2018 2:57 pm If you're going to be working with Svg pages from multiple FreeCAD documents, should it show documentName+pageName? You could get a bunch of Svg files all with "id=Page".
I would be inclined to leave it just as page name. That way you can have svg files with the <use> elements already set up, and they can be used as templates for every project, so long as pages are kept with the default page names in FreeCAD. These inkscape files could be stored centrally somewhere for users to download, and it would work without them needing to understand anything about SVG behind the scenes. If a prefix was added for each file name, then a user would need to edit the code of the svg for each project that has a different .fcstd file name. If output from multiple files was needed, then it would be easy enough to rename the page objects within the FreeCAD files to make them unique, and edit the code of the SVG accordingly - but I think this is an uncommon scenario.
User avatar
wandererfan
Veteran
Posts: 6268
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [Improvement] Support <use> element in SVG spec to integrate inkscape with TechDraw output

Post by wandererfan »

clarkitect wrote: Thu Nov 15, 2018 1:08 am The <use> element is super handy and allows referencing external svg files, but it requires an identifier within the target svg. Can we add an id tag to the output from techdraw to allow this to work as is currently possible with the old drawing wb?
Should be available in versions after this git commit 0e26ce1f278.
Post Reply