As far as I understand, these are the document coordinates of the center of the screen (ore the viewport, not 100% sure).I want to use them and for now I am trying to place a dot at that point.This however is failing very badly - probably due to unit conversion.
How is it that - with an A4 document (the default) zoomed to page width, my namedview is:
<sodipodi:namedview xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" id="namedview1" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:showpageshadow="2" inkscape:pageopacity="0.0" inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" inkscape:zoom="1.4501687" inkscape:cx="396.85039" inkscape:cy="561.31402" inkscape:window-width="1862" inkscape:window-height="1016" inkscape:window-x="58" inkscape:window-y="27" inkscape:window-maximized="1" inkscape:current-layer="layer1"/>and therefore cx and cy are respectively 396.85039 and 561.31402?
<sodipodi:namedview xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" id="namedview1" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:showpageshadow="2" inkscape:pageopacity="0.0" inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" inkscape:zoom="1.4501687" inkscape:cx="396.85039" inkscape:cy="561.31402" inkscape:window-width="1862" inkscape:window-height="1016" inkscape:window-x="58" inkscape:window-y="27" inkscape:window-maximized="1" inkscape:current-layer="layer1"/>
396.85039
561.31402
Try this instead
def draw_dot(self, center): from inkex import Circle circle = Circle() circle.set('r', 5) circle.set('cx', center[0]) circle.set('cy', center[1]) self.svg.get_current_layer().append(circle)
namedview = self.svg.namedview draw_dot(self, namedview.center)
or maybe:
#Unit conversions conversions = { 'in': 96.0, 'pt': 1.3333333333333333, 'px': 1.0, 'mm': 3.779527559055118, 'cm': 37.79527559055118, 'm': 3779.527559055118, 'km': 3779527.559055118, 'Q': 0.94488188976378, 'pc': 16.0, 'yd': 3456.0, 'ft': 1152.0, '': 1.0, # Default px } namedview = self.svg.namedview draw_dot(self, namedview.center) namedview_element = self.svg.xpath('//sodipodi:namedview')[0] inkscape_cx = namedview_element.get('inkscape:cx') inkscape_cy = namedview_element.get('inkscape:cy') conversion_factor = conversions[self.svg.unit] cx = float(inkscape_cx) / conversion_factor cy = float(inkscape_cy) / conversion_factor draw_dot(self, [cx, cy])
As far as I understand, these are the document coordinates of the center of the screen (ore the viewport, not 100% sure).
I want to use them and for now I am trying to place a dot at that point.
This however is failing very badly - probably due to unit conversion.
How is it that - with an A4 document (the default) zoomed to page width, my namedview is:
<sodipodi:namedview xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" id="namedview1" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:showpageshadow="2" inkscape:pageopacity="0.0" inkscape:pagecheckerboard="0" inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" inkscape:zoom="1.4501687" inkscape:cx="396.85039" inkscape:cy="561.31402" inkscape:window-width="1862" inkscape:window-height="1016" inkscape:window-x="58" inkscape:window-y="27" inkscape:window-maximized="1" inkscape:current-layer="layer1"/>
and therefore cx and cy are respectively
396.85039
and561.31402
?Try this instead
or maybe: