Inkscape.org
Creating New Extensions explode a path
  1. #1
    FrankI4466 FrankI4466 @FrankI4466

    Hi,

    I don't quite understand what a cubic super path is, anyone explain it to me?

    I am trying to explode a complex path into some "simple" lines and curves. Is there a function that does this?

    Thanks

  2. #2
    Hum Hum @Hum

    Hi. Do you mean to break a path apart or into sub-paths?

    Such as "mini" paths that are portions of the original path?

  3. #3
    Polygon Polygon @Polygon🌶

    I already tried to help here: https://inkscape.org/forums/francais/cubic-super-path/

    but I don´t seem to understand neither what he needs nor what a "cubic super path" is. I already suggested to break at nodes and "Path->Break apart" afterwards. Maybe he want s to write an extension.

  4. #4
    Aero Aero @Aero◻️

    Detailed Description

    Inkscape: inkex.paths.CubicSuperPath Class Reference

     

  5. #5
    FrankI4466 FrankI4466 @FrankI4466
    *

    Thank's for your help.

    After many search i think cubic super path transform path into bezier curves with 2 modifications points.

    ken10001000

    Hi. Do you mean to break a path apart or into sub-paths?

    Such as "mini" paths that are portions of the original path?

    yes what I want are mini paths. The original path being cut in line and curves, circle or bezier or something else but a line.

  6. #6
    inklinea inklinea @inklinea⛰️

    Select Path

    Press N   - Node tool

    Press Ctrl + A  - Select all nodes

    Press Shift + B  - Break apart path at selected nodes

    Press Ctrl + Shift + K  - Break apart path

  7. #7
    Hum Hum @Hum
    *

    Inklinea is right and so is Polygon who tried to tell you about this breaking apart steps.

    I would only add that after pressing N to access the Node Tool, you can select any particular node(s) you wish

     You do not have to select all the nodes, which will break apart every "portion" of the original path into separate "mini"paths.

    And -This next portion may be more than you want to know, but there is also an extension which can added to Inkscape called "Split and Break Bezier at t" which allows a user to break their path at certain percentages or distances

     I find it useful. See this link for more details.

    https://inkscape.org/forums/tutorials/split-and-break-bezier-at-t-extension/

     

  8. #8
    Hum Hum @Hum

    Please see this also. I added a few details (graphics) to a previous "tip" topic.

    https://inkscape.org/forums/tutorials/tip-break-apart-a-path-into-individual-sub-paths/?c=52934#c52934

  9. #9
    FrankI4466 FrankI4466 @FrankI4466

    Thank's to all but my purpose is not to do but how to code. Sorry to don't explain in the first post but we are in " creating an extension ".

  10. #10
    Hum Hum @Hum

    Well, perhaps my details will help someone out there.

    It might be helpful to me and others if in the future you simply state you desire help to create an extension. Along with details about that extension request.

  11. #11
    Kaalleen Kaalleen @Kaalleen

    If I understand you correctly you wish to break a path apart with the existing nodes as break points. You could use cubic super paths for that, but not necessarily need to. Here an example how this could work (it's not the nicest code though, but I hope you can use it to get your job done):

    import inkex
    
    
    class ToSubPaths(inkex.EffectExtension):
    
        def effect(self):
            for element in self.svg.selection.filter(inkex.Group, inkex.PathElement, inkex.Circle, inkex.Ellipse, inkex.Rectangle):
                # groups: iterate through descendants
                if isinstance(element, inkex.Group):
                    for shape_element in element.descendants().filter(inkex.PathElement, inkex.Circle, inkex.Ellipse, inkex.Rectangle):
                        self.replace_with_subpaths(shape_element)
                else:
                    self.replace_with_subpaths(element)
    
        def replace_with_subpaths(self, element):
            # get info about the position in the svg document
            parent = element.getparent()
            index = parent.index(element)
    
            # get style and remove fill, the new elements are strokes
            style = element.style
            if not style('stroke', None):
                style['stroke'] = style('fill', None)
            style['fill'] = 'none'
    
            # path
            path = element.path.to_non_shorthand()
    
            # generate new elements from sub paths
            for start, end in zip(path[:-1], path[1:]):
                if isinstance(end, inkex.paths.ZoneClose):
                    end = inkex.paths.Line(path[0].x, path[0].y)
                start = start.end_point(None, None)
                start = inkex.paths.Move(start.x, start.y)
                segment_path = inkex.Path([start, end])
                new_element = inkex.PathElement(d=str(segment_path),
                                                style=str(style),
                                                transform=str(element.transform))
                parent.insert(index, new_element)
    
            # remove the original element
            parent.remove(element)
    
    
    if __name__ == '__main__':
        ToSubPaths().run()

     

  12. #12
    FrankI4466 FrankI4466 @FrankI4466

    Thank's kalleen but i think it's for an old version of inkex.

  13. #13
    inklinea inklinea @inklinea⛰️

    Seems to work perfectly for me in Inkscape 1.2.2 :)

    Thanks Kaaleen - very cool

    I just zipped the .inx and .py 

    If anyone else wants to use it - thanks.

  14. #14
    inklinea inklinea @inklinea⛰️
    *

    Video: [ Edit - I just noticed when you mouse hover over the video it says 'to_subpath by inklinea', that's something the forum upload has added as a tooltip. I have not changed any code in the extension ]

    To Subpath
  15. #15
    FrankI4466 FrankI4466 @FrankI4466

    You're right.

    I had tried to include it in my extension and there it does not work. But if i use it alone then it works.

    So there is something that I don't understand in the use of inkex help.

    If I search on getparent I only get answers in deprecated. Why ?

    https://inkscape.gitlab.io/extensions/documentation/search.html?q=getparent

  16. #16
    Kaalleen Kaalleen @Kaalleen

    This is part of lxml https://lxml.de/apidoc/lxml.etree.html#lxml.etree._Element

  17. #17
    FrankI4466 FrankI4466 @FrankI4466

    Thank's