Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ImportC2D.zip
Binary file not shown.
15 changes: 9 additions & 6 deletions c2d_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
(at your option) any later version.
"""
import inkex
from StringIO import StringIO
from io import StringIO
from math import sin,cos,pi
from lxml import etree
import json
import optparse
import sys

class ImportC2D:
""" Import a Carbide Create C2D file and process it into an SVG."""
Expand All @@ -27,14 +30,14 @@ class ImportC2D:
def __init__(self,c2d_file,as_paths):
""" Load a C2D file and process it into an SVG. """
self.as_paths = as_paths
self.SubElement = inkex.etree.SubElement
self.SubElement = etree.SubElement

with open(c2d_file,'r') as f:
c2d = json.load(f)

width = c2d['DOCUMENT_VALUES']['WIDTH']
height = c2d['DOCUMENT_VALUES']['HEIGHT']
self.svg = inkex.etree.parse(StringIO(
self.svg = etree.parse(StringIO(
'<svg xmlns="http://www.w3.org/2000/svg" width="{0}mm" '
'height="{1}mm" viewBox="0 0 {0} {1}"/>'.format(width,height)))

Expand Down Expand Up @@ -452,7 +455,7 @@ def c2d_curve(self,x,y,point_types,points,handles_1,handles_2):
return self.path(path_data)

if __name__ == '__main__':
parser = inkex.optparse.OptionParser(usage="usage: %prog [-p] C2Dfile",
parser = optparse.OptionParser(usage="usage: %prog [-p] C2Dfile",
option_class=inkex.InkOption)
parser.add_option('-p', '--as_paths', action='store',
help='Import all objects as paths.', default=False)
Expand All @@ -463,7 +466,7 @@ def c2d_curve(self,x,y,point_types,points,handles_1,handles_2):
parser.add_option('--inputhelp', action='store')
parser.add_option('--textwarning', action='store')
parser.add_option('--helptext', action='store')
(options, args) = parser.parse_args(inkex.sys.argv[1:])
(options, args) = parser.parse_args(sys.argv[1:])

# The File/Import... dialog only allows importing a single file at a time,
# and the fully-qualified filename is passed as the first positional
Expand All @@ -473,4 +476,4 @@ def c2d_curve(self,x,y,point_types,points,handles_1,handles_2):
# An Inkscape input extension does whatever it needs to do with the input
# file and then writes an SVG to stdout. Inkscape takes this as input and
# creates a new layer out of the contents of the SVG.
c2d.svg.write(inkex.sys.stdout)
c2d.svg.write(sys.stdout.buffer)