Inkscape.org
Creating New Extensions nodes connect other side
  1. #1
    Hiroki-H Hiroki-H @Hiroki-H

    I draw some cad hilbert-based one-loop drawing like this:

    this is dxf format data.

    and I wrote Python program that extract coordinates from svg that is made by InkScape.

    But, this did not work fine.

    all coordinates my python program extracted to csv file and draw x-y graph by excel, connect points of line-to-line are different that I expect like this:

    This seems that connecting points are different, counter-side is connected.

    My python program is extract x,y from svg in turn.

    Please tell me how to determine connecting point, or any other problems?

  2. #2
    inklinea inklinea @inklinea⛰️

    If you have just extracted the coordinates, what has happened to the other svg path commands. 

    For example. L C A H V ? 

    C and A give bezier curves and arcs.

    If you have just extracted the node coordinates and drawn lines, that will give you a polygon only. 

  3. #3
    Hiroki-H Hiroki-H @Hiroki-H

    My svg data is modified, 'Insert new nodes into selected nodes' by 8 times to increase simple coordinates

    and eliminate bezier, spline curves.

    So, this is enough to extract simple x,y coordinates M, L, V, H, not need to sample C, A.

     

  4. #4
    inklinea inklinea @inklinea⛰️

    In Inkscape, select all nodes, and click the highlighted button ( node toolbar ) to check first. 

     

    Screenshot From 2023 11 19 13 10 32
  5. #5
    Hiroki-H Hiroki-H @Hiroki-H

    dear inklinea,

    I tried you suggested, but the result was same.

    The saved svg I edit by Inkscape consists no C, A, only exist M, L, V, H.

    And the important thing I want is the order of coordinates are all arranged to be drawn unicursally.

    The target device is 6-axis robot to trace dxf data.

    This robot only recognize simple x,y,z,rx,ry,rz coordinates, so I must convert curves to a set of fine points.

  6. #6
    inklinea inklinea @inklinea⛰️

    Do you have a copy of the one loop .dxf ? that you can attach ? 

  7. #7
    Hiroki-H Hiroki-H @Hiroki-H
    *

    plz confirm.

    Very unfortunately, it works fine in Illustrator.

    All I want is extract simple fine coordinates without curves.

    Hilbert
  8. #8
    inklinea inklinea @inklinea⛰️

    I was able to create this. 

    Using the node tool, I press ctrl + a to select all nodes in the imported dxf. 

    Then press Shift + J to join all nodes. 

    Then increase the nodes a couple of times.

    In the extension convert to an absolute path, then export nodes at .csv

    ( I have attached the csv ) 

  9. #9
    Hiroki-H Hiroki-H @Hiroki-H

    I confirmed, thanks!!! My problem has gone by your assist. I am very happy.

    I did not know Shift + J command by now. Where is this command? Which icon related?

    A problem of InkScape is, I think, that keyboard shortcuts, tool icons and menu bar functions are disjointed and not integrated

  10. #10
    inklinea inklinea @inklinea⛰️

    Yes, it's part of the Node Tool Toolbar.

    Image attached.

     

    Image 2023 11 23 202413831
  11. #11
    Hiroki-H Hiroki-H @Hiroki-H

    Yes, I have found it.

    And I have one more question.

    > In the extension convert to an absolute path, then export nodes at .csv

    Where is this command?

    I cannot find this.

  12. #12
    inklinea inklinea @inklinea⛰️

    You can use Extensions > Modify Path > To Absolute

    However I wrote a small extension to test your curve.

    def make_abs_node_list(self, element):

            csv_list = []

            path_d_abs = element.path.to_absolute().transform(element.composed_transform())
            csp = path_d_abs.to_superpath()

            for subpath_index in range(len(csp)):
                for node_index in range(len(csp[subpath_index])):
                    x, y = csp[int(subpath_index)][int(node_index)][1]
                    # inkex.errormsg(f'{x},{y}')
                    draw_circle(self, x, y)
                    csv_list.append([x, y])

            return csv_list
            
    The returned list can then be written directly to csv:

    def create_csv(self, csv_list):

        try:
            with open('/home/name/Pictures/points.csv', 'w') as csv_file:

                write = csv.writer(csv_file)
                write.writerows(csv_list)
        except:
            inkex.errormsg('Could not write to csv file !')
            
    (Some of the code above was with help previously from user Kaalleen)

  13. #13
    Hiroki-H Hiroki-H @Hiroki-H

    Thanks inklinea, I successfully extract coordinates from svg to csv by my python program.

    My problem is that I did not know the command of join all nodes at all.

     

  14. #14
    Hiroki-H Hiroki-H @Hiroki-H

    And I'd like to contribute for enhancing InkScape.

    The most important thing I concern is to enhance the speed of 'Insert new node' command.

    How do I contribute for this?

  15. #15
    inklinea inklinea @inklinea⛰️

    https://chat.inkscape.org/channel/team_devel