Inkscape.org
Creating New Extensions Getting id's of all paths (unselected)
  1. #1
    DrQt DrQt @DrQt

    I'm able to get id's of selected items with


    for id in self.options.ids:
        inkex.utils.debug(id)

     

    I'm trying to get all path in the scene, but i have id's and not label names

    for node in self.svg:
        if node.label == 'color_fill':
            for shape in node:
                inkex.utils.debug(shape.label)

     

    label works, but I only have id strings.

    I also tried self.svg.xpath('//svg:paths') but i'm having similar trouble.

  2. #2
    inklinea inklinea @inklinea⛰️

    Elements in Inkscape will always have ids, but not always a separate label unless you have renamed them in the object browser.

    my_objects = self.svg.selected
    
    for my_object in my_objects:
        my_id = my_object.label
        my_label = my_object.get('inkscape:label')
        inkex.errormsg(f'ID : {my_id} Label : {my_label}')
  3. #3
    DrQt DrQt @DrQt
    *

    I wasn't able to get that to work.

    The first example here is the id's when all the objects are selected.

    The next two don't seem to work, regardless of selction

    ---------------------------------------------------------------------------

    for id in self.options.ids:
    	inkex.utils.debug(id)
    eye_2_R
    eye_2_L
    mouth_2
    tongue_2
    hair_1_L
    tongue_1
    hair_1_R
    nose_1
    mouth_1
    eye_1_L
    eye_1_R
    robes_1
    hand_1_R
    face_1
    brain
    face_2
    wing_1_L
    halo_2
    wing_2_L
    halo_1
    wing_1_R
    CLIP_angel_1
    CLIP_angel_2
    CLIP_heavens
    CLIP_text_2
    CLIP_text_1
    CLIP_text_3
    CLIP_text_7
    CLIP_text_8
    CLIP_text_4
    CLIP_text_5
    CLIP_text_6
    Untitled 5_2.svg
    /home/me/comics/artwork/crops/dream/dream_04/svg

    ---------------------------------------------------------------------------

    my_objects = self.svg.selected
    
    for my_object in my_objects:
    	my_id = my_object.label
    	my_label = my_object.get('inkscape:label')
    	inkex.errormsg(f'ID : {my_id} Label : {my_label}')
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : robes_1 Label : robes_1
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : wing_2_L Label : wing_2_L
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	ID : None Label : None
    	CLIP_text_2
    	CLIP_text_1
    	CLIP_text_3
    	CLIP_text_7
    	CLIP_text_8
    	CLIP_text_4
    	CLIP_text_5
    	CLIP_text_6
    	Untitled 5_2.svg
    	/home/me/comics/artwork/crops/dream/dream_04/svg

    ---------------------------------------------------------------------------

    for node in self.svg:
    	if node.label == 'color_fill':
    		for shape in node:
    			inkex.utils.debug(shape.get('inkscape:label'))
    None
    None
    None
    None
    None
    wing_2_L
    None
    None
    None
    None
    None
    None
    robes_1
    None
    None
    None
    None
    None
    None
    None
    None
    None
    None
    None
    CLIP_text_2
    CLIP_text_1
    CLIP_text_3
    CLIP_text_7
    CLIP_text_8
    CLIP_text_4
    CLIP_text_5
    CLIP_text_6
    Untitled 5_2.svg
    /home/me/comics/artwork/crops/dream/dream_04/svg

     

  4. #4
    inklinea inklinea @inklinea⛰️

    Whoops sorry, I pasted the wrong piece of code.

    my_objects = self.svg.selected
    
    for my_object in my_objects:
        my_id = my_object.get_id()
        my_label = my_object.label
        inkex.errormsg(f'ID : {my_id} Label : {my_label}')
  5. #5
    DrQt DrQt @DrQt

    Working beautifully, thank you.

Inkscape Inkscape.org Inkscape Forum Creating New Extensions Getting id's of all paths (unselected)