Inkscape.org
Creating New Extensions How to read Visio's meta attributes from the element?
  1. #1
    hex mex hex mex @littledemon

    First of all, I need to say that for some reasons it is not possible for me to filter objects based on id 
    Therefore, I need to group objects based on the meta-attributes that Visio has set for them.

    However, I could not get these types of features using xpath. Is it even possible to do this?

    For example, I want to get the object whose v:mID is 100

    <g  v:mID="100" v:index="1" v:groupContext="layer" id="g1579">

    For this, I used the following rule, which unfortunately did not work:
    //*[@v:mID='100']

     

  2. #2
    inklinea inklinea @inklinea⛰️

    can you post a sample visio file ? 

  3. #3
    hex mex hex mex @littledemon

    Yes, of course...

    Test
  4. #4
    inklinea inklinea @inklinea⛰️

    I've only does this a couple of times for hocr files produced by tesseract. I think you need to define the various visio namespaces in your code. 

    This should find all elements which have v:mID='445'

     

    namespaces = {'v': 'http://schemas.microsoft.com/visio/2003/SVGExtensions/'}
    
    document = self.document
    
    element_list = document.iterfind('//*[@v:mID="445"]', namespaces)
    
    inkex.errormsg(element_list)
    
    for item in element_list:
        text = item.tostring().decode('utf-8')
        inkex.errormsg(text)
  5. #5
    hex mex hex mex @littledemon
    *

    this is fabulous ! I appreciate your kindness.
    Is it possible to somehow use this namespace for the get() function when we have an object and for example we need to read its v:cp value . of course, I mean without manipulating the element string.

  6. #6
    inklinea inklinea @inklinea⛰️
    m_id = element.get('{http://schemas.microsoft.com/visio/2003/SVGExtensions/}mID')

    However I don't know how to add that attribute as shorthand for use in get 

     

  7. #7
    inklinea inklinea @inklinea⛰️

    Update ! 

    After asking in Chat - it's a simple as this:

     

    inkex.NSS["v"] = "http://schemas.microsoft.com/visio/2003/SVGExtensions/"
    
    elements = self.svg.xpath('//*')
    for item in elements:
        m_id = item.get('v:mID')
        inkex.errormsg(m_id)
Inkscape Inkscape.org Inkscape Forum Creating New Extensions How to read Visio's meta attributes from the element?