Inkscape.org
Beyond the Basics Clear Styles from Selected Shapes
  1. #1
    Paddy_CAD Paddy_CAD @Paddy_CAD

    Does anyone know of an extension that removes the style attribute from every object in a selection? I want it to (optionally?) recurse into groups and subgroups.

    When I move or paste objects in my drawing, I want them to inherit the style of the destination layer. However, Inkscape applies the source layer style to the object, overriding the destination layer style.

    I often use Inkscape as a proto-CAD application (hence the user name, I suppose) to edit imported pdf and dxf files. Shapes are differentiated by line weights, fill colour, opacity, dash patterns, etc. My habit is to apply styles to parent layers which are then inherited by the unstyled child objects within. I can delete style attributes from a single object using the XML Editor but this is tedious for large selections.

  2. #2
    inklinea inklinea @inklinea⛰️

    As you probably know, there are 3 sources in svgs for "styling" properties to be stored:

    Attributes (old school) ----- fill="black" stroke="red"

    style attribute properties ----- style="fill:black;stroke:red;"

    classes ----- class="blackAndRed"

    Do you want the option to nuke any or all of them, with options to recurse ? 

  3. #3
    Tyler Durden Tyler Durden @TylerDurden

    Setting the selected objects to unset before moving does not satisfy the goal?

     

     

    Unsetgroups
  4. #4
    Paddy_CAD Paddy_CAD @Paddy_CAD
    *

    @inklinea: Option 2 is Inkscape's styling strategy and that's what I want to delete. Recursion into groups and tspans is the preferred behaviour.

    @TylerDurden: When you copy-paste an unstyled child object from a styled layer or group, Inkscape assigns the source group style to the pasted object inside the target group. Presumably this is intentional behaviour so that the pasted object has the same visual appearance as the original. I want to discard the source layer style and inherit the target layer style.

    In this example, none of the objects has a style attribute. Layers, however, have a style attribute with stroke and fill and font definitions. [Move to Layer...] or [Copy] [Paste] adds a style attribute to the pasted or moved object. Deleting this style attribute renders the object with the parent layer style.

  5. #5
    Tyler Durden Tyler Durden @TylerDurden

    I was presuming that the unset objects would originate in a non-styled layer and then get moved to a styled layer. 

  6. #6
    Darren Hawkshaw Darren Hawkshaw @dhawkshaw
    *

    Hi @Paddy_CAD

    I built a really quick and dirty extension that strips ALL style attributes, pretty much as my first attempt at an extension -- I tend to use inkscape to build fairly simple stuff that ends up as inlined svg on web pages, styled by external css, so my workflow is to strip all styling before exporting to plain svg. It's only about half a dozen lines. Not sure if that would be useful as a starting point, but also how best to post it in here ?

    Darren

  7. #7
    Darren Hawkshaw Darren Hawkshaw @dhawkshaw

    I've just zipped my extension directory up - maybe that will help you ?

    Darren

  8. #8
    inklinea inklinea @inklinea⛰️
    *

    I've had a look.

    The extension strips the style attribute from every element in the svg.

    I think PaddyCad wants it to be a bit more specific, just children or all descendants of a specific selected element.

    [ Well done on writing your first extension btw :) ]

     

  9. #9
    Darren Hawkshaw Darren Hawkshaw @dhawkshaw

    Thanks @inklinea, yep it was purely to scratch my own particular workflow itch from a while ago so it's definitely not refined -- just thought it might be useful as a starting point.

    Just an extra, gotta say a big thanks to you for your flatten extension that resolves transforms, it makes my cleanup and stripdown process soooo much easier 😀

  10. #10
    Aero Aero @Aero◻️

    Maybe moving the style attributes from the groups (layers) into a style element will help when copying, pasting and using move to layer.

     

    Layer Styles 2
  11. #11
    Paddy_CAD Paddy_CAD @Paddy_CAD

    Thanks Aero, problem solved. I'm awarding you a shamrock!

    The source and destination layers belong to different CSS classes and are formatted accordingly. Layers have no style attribute of their own so copy-paste takes no object style to the destination layer.

Inkscape Inkscape.org Inkscape Forum Beyond the Basics Clear Styles from Selected Shapes