Group objects by block in SVG output

1
Chris Smith
8/5/2016 12:54 AM

Hi,

Just wondering if it's possible to group path objects by their owning block reference in SVG output?

Also, is there a way to add a custom id to each exported object?

(Use case is that i'd like to be able to select a whole block reference and relate graphics to aspatial data in a web application)

Cheers,
Chris

Wout
8/8/2016 1:10 PM

Hi Chris,

Entities are converted to polylines in the order they are encountered in the DXF/DWG file (but SORTENTS may change the order). But CadLib creates no group structures in the SVG output.

There is the possibility to tag SVG elements by use of the SvgExporter.WriteSvgXmlElementAttributes. This is a delegate with the following signature:

C# Code:
public delegate void XmlWriteDelegate(XmlTextWriter w, DxfEntity entity)

So you can add your own attributes to the SVG output.

- Wout

Chris Smith
8/9/2016 4:25 AM

Thanks Wout!

Would the grouping thing be something we could add in a subclass?

I guess ideally we'd like to write DxfBlocks as <defs><g id="<block name>">...</g>...</defs> and then <use ....> elements for each DxfInsert.

A fallback would be just to put groups around the elements of each DxfInsert. Perhaps we could do this by overriding BeginInsert / EndInsert and writing an extra tag?

Cheers,
Chris

khoa.ho
5/8/2019 7:47 PM

Hi,

Do you have any new progress on this topic? I would like to see if CadLib can export DxfBlock as SVG symbol and use symbol link for each DxfInsert.

Thanks.

Wout
5/8/2019 10:57 PM

Hi,

It's not possible to do this, because colors, line types and line weights of the entities in the block may vary depending on the insert.

- Wout

Chris Smith
5/9/2019 12:08 AM

Hi Wout,

It looks like this kind of thing might be possible these days with CSS variables (eg: https://tympanus.net/codrops/2015/07/16/styling-svg-use-content-css/ )

Looks complex tho.

Cheers,
Chris

khoa.ho
5/9/2019 1:42 PM

Hi Wout,

Can we export an individual entity DxfEntity to a SVG group? Then we can export DxfBlock to a SVG symbol and use SVG links for each DxfInsert.

Thank you.

Wout
5/9/2019 4:16 PM

I explained already why it won't work in general, see above.

- Wout

Chris Smith
5/9/2019 10:30 PM

Hi Khoa

Just to expand on exactly what makes this difficult...

Graphics within AutoCAD blocks can have either fixed styles or "ByLayer" or "ByBlock" styles. Eg, for any given element inside a block, it might take its color form the color of the layer that it is on in the target drawing or it might take is color from the coloraturas of the block when it's inserted.

In contrast SVG allows you to have styles inside a symbol or on the use of the symbol but styles the use of a symbol override styles on the inner graphics.

In the link I added the other day, there's a method to use CSS style variables to work around the way that styles inherit however it would be super complex to generate that programmatically.

Just for context, we have an existing system which uses SVG with <symbol> and <use> to try to recreate DWGs in SWVG however the output looks like a very rough approximation of the equivalent DWG due to these limitations.

Re my original request, I guess the hope to group elements together (even if just with a <g>) was to support highlighting all the graphics that are part of the same symbol when you mouse over them. I think we could get this via the SvgExporter.WriteSvgXmlElementAttributes method.

In the end we determined that CadLib-generated SVGs were too big to transmit as replacements for our existing SVG writer (mostly because of the duplicated symbol graphics) so we ended up generating PNGs and sending those instead. The downside is that we have to re-query the server to do hit testing.

Cheers,
Chris

1