How to draw circles in an extension

Asked by inductiveload

Hi, I'm trying to write an extension for Inkscape in Python. Part of this script involves drawing a circle, and I can't find any information on how do do this anywhere. I want to draw a proper circle, not a path. I know the radius and centre position. Is this the right place to ask this?

Thanks,

John

Question information

Language:
English Edit question
Status:
Solved
For:
Inkscape Edit question
Assignee:
No assignee Edit question
Solved by:
John Cliff
Solved:
Last query:
Last reply:
Revision history for this message
Best John Cliff (johncliff) said :
#1

<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>

    * The cx and cy attributes define the x and y coordinates of the center of the circle. If cx and cy are omitted, the circle's center is set to (0, 0)
    * The r attribute defines the radius of the circle

Revision history for this message
John Cliff (johncliff) said :
#2

inkscape may convert it back to a path tho when it gos back through inkscape, not sure.

Revision history for this message
inductiveload (inductiveload) said :
#3

Thanks, that put me on the right track. For anyone else trying to do this, this seems to work:

#make a group
        t = 'translate(' + str( self.view_center[0] ) + ',' + str( self.view_center[1] ) + ')'
        g_attribs = {inkex.addNS('label','inkscape'):'InvGear' + str( teeth ),
                   'transform':t }
        g = inkex.etree.SubElement(self.current_layer, 'g', g_attribs)

#put the circle in
        style = { 'stroke': '#000000', 'fill': 'none' }
        circ_attribs = {'style':simplestyle.formatStyle(style), 'id':'BaseCircle', 'sodipodi:cx':'0', 'sodipodi:cy':'0',
        'sodipodi:rx':str(base_radius), 'sodipodi:ry':str(base_radius), 'sodipodi:type':'arc'}
        gear = inkex.etree.SubElement(g, inkex.addNS('path','svg'), circ_attribs )

This put the circle 'BaseCircle' into the group 'InvGearXX'.

Revision history for this message
inductiveload (inductiveload) said :
#4

Thanks John Cliff, that solved my question.