file saves with file types that are written in python have missing object or misplaced objects (dxf and hpgl)

Bug #600472 reported by DavidTalmage
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
Wishlist
Alvin Penner

Bug Description

Several of the object types are not exported, some are placed in the wrong place when displayed on viewer or reimported. None of the saves written in python will save this file correctly. All of the internal file saves seem to work correctly.

Problem resides in this excerpt of python code in dxf and hpgl output.py Only 2 of the 5 objects in test.svg are output by this code and one of the two is misplaced relative to the other.

        for layer in self.document.getroot().xpath(layerPath, namespaces=inkex.NSS):
            i += 1
           ...
            nodePath = ('//svg:g[@inkscape:groupmode="layer"][%d]/descendant::svg:path') % i
            for node in self.document.getroot().xpath(nodePath, namespaces=inkex.NSS):
                d = node.get('d')
                if len(simplepath.parsePath(d)):
                    p = cubicsuperpath.parsePath(d)
                    cspsubdiv.cspsubdiv(p, self.options.flat)
                    for sp in p:
                        first = True
                        for csp in sp:
                            cmd = 'PD'
                            if first:
                                cmd = 'PU'
                            first = False
                            self.hpgl.append('%s%d,%d;' % (cmd,(csp[1][0] - x0)*scale,(csp[1][1]*mirror - y0)*scale))

Missing objects are:
text outlines
rectangles with square corners
rectangles with round corners
I believe its in 5 sided polygon which is misplaced
It seems only ovals and line segments are exported correctly

I can't find the dom (document object model) on the internet so I am finding it hard to fix this myself.
A true test would have at least one object of each type that could be created to verify that output file is build correctly.

Revision history for this message
DavidTalmage (david-junk-mail) wrote :
Revision history for this message
DavidTalmage (david-junk-mail) wrote :

problem is in 0.47 version. did not test in other versions

Revision history for this message
DavidTalmage (david-junk-mail) wrote :

bug 60473 seems like same problem

su_v (suv-lp)
tags: added: dxf exporting hpgl
Revision history for this message
Alvin Penner (apenner) wrote :

sounds similar to Bug 585021.
could you try this procedure:
- Edit->Select All
and then use :
- Path->Object to Path
- then, with all objects selected, force a bit of a translation by selecting the entire group and hitting the up arrow once and then hit the down arrow once to return to the original position. If all goes well this should remove the transform elements from the diagram.

When I use this method I get the attached .dxf file which I think contains all the required elements.

Revision history for this message
DavidTalmage (david-junk-mail) wrote :

Thanks for your response and suggestion:
results are as follows: all objects are exported and displayed correctly

I find it to be unacceptable to require my customers to convert objects to paths to get it to work correctly. Not only does it make the text string uneditable, it requires that the user operating my machine to know how to use the program. I am trying to make the user interface very simple for operators of my new machine. Most I am willing to make the operator of my machine do is open file and run an extension.

I want to create a new extension that makes a copy of the file, and then automatically convert it to paths and then move it as you described, then output it to a file. However, I can't find the document or the inkscape object model. Best I have found so far is:
http://inkscape.modevia.com/doxygen/html/ObjectTree.php

I have been programming for 35 years and have written plugins for adobe illusrator and coreldraw. There has to be a way to control the application from a python script.

Can you point me to the correct website or example that might allow me to write the code.

Revision history for this message
Alvin Penner (apenner) wrote :

probably the best source of information is the directory \Inkscape\share\extensions

Revision history for this message
Alvin Penner (apenner) wrote :

- a new output routine to deal with the effects of transform elements has been posted in Bug 600473 comment 6
- https://bugs.launchpad.net/inkscape/+bug/600473/comments/6
- could you indicate whether this resolves the issue for you?
- if there are remaining problems which have not been addressed, would you be willing to file them as separate bug reports?

Changed in inkscape:
status: New → Incomplete
Revision history for this message
DavidTalmage (david-junk-mail) wrote :

test file for for output with dxf or hpgl save.

Revision history for this message
DavidTalmage (david-junk-mail) wrote :

Your new fix fixes misplace objects in dxf output for support types.

It does not fix text output
it does not fix rectangle output
if does not address same problem in hpgl output

If you want to support rectangles I found some buggy code in pathmodifier for converting a rectangle to a path. Here is my corrected code.

    def rectToPath(self,node,doReplace=True):
        if node.tag == inkex.addNS('rect','svg'):
            x =float(node.get('x'))
            y =float(node.get('y'))
            try:
                rx=float(node.get('rx'))
            except:
                rx=0
            try:
                ry=float(node.get('ry'))
            except:
                ry=0
            if rx == 0 and ry != 0:
                rx = ry
            if ry == 0 and rx != 0:
                ry = rx
            w =float(node.get('width' ))
            h =float(node.get('height'))
            d ='M %f,%f '%(x+rx,y)
            d+='L %f,%f '%(x+w-rx,y)
            d+='A %f,%f,%i,%i,%i,%f,%f '%(rx,ry,0,0,1,x+w,y+ry)
            d+='L %f,%f '%(x+w,y+h-ry)
            d+='A %f,%f,%i,%i,%i,%f,%f '%(rx,ry,0,0,1,x+w-rx,y+h)
            d+='L %f,%f '%(x+rx,y+h)
            d+='A %f,%f,%i,%i,%i,%f,%f '%(rx,ry,0,0,1,x,y+h-ry)
            d+='L %f,%f '%(x,y+ry)
            d+='A %f,%f,%i,%i,%i,%f,%f '%(rx,ry,0,0,1,x+rx,y)

            newnode=inkex.etree.Element('path')
            newnode.set('d',d)
            newnode.set('id', self.uniqueId('path'))
            newnode.set('style',node.get('style'))
            nnt = node.get('transform')
            if nnt:
                newnode.set('transform',nnt)
                fuseTransform(newnode)
            if doReplace:
                parent=node.getparent()
                parent.insert(parent.index(node),newnode)
                parent.remove(node)
            return newnode

Revision history for this message
Alvin Penner (apenner) wrote :

    the problem with 'text' svg elements and 'rect' svg elements can be dealt with by selecting these objects and appyling the menu item Path->Object to Path.
    The ideal solution would be if this menu functionality could be called or executed from inside a Python script. However, I do not know how to do that, I do not believe it is possible at the moment.
    Perhaps this could be proposed as a GSoC project someday, since there are quite a number of Python scripts that experience exactly the same problem, this is not unique to the .dxf output routine.

Changed in inkscape:
status: Incomplete → New
Revision history for this message
DavidTalmage (david-junk-mail) wrote :

I don't think you have to convert text to path or rectangles to path in autocad before you save a file in dxf format. A what happens if you want to change the size or roundness of the rectangle after you print it. Or maybe you want to change the font face.

su_v (suv-lp)
Changed in inkscape:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
Alvin Penner (apenner) wrote :

- attached is a new version of hpgl_output.py.
- this version adds support for transform elements in the same way as the dxf output (comment 7)
- as usual, any testing would be welcome...

Revision history for this message
Alvin Penner (apenner) wrote :

sorry, found a bug, here is a better version :

Revision history for this message
Alvin Penner (apenner) wrote :

committed to bzr rev 9689

Revision history for this message
su_v (suv-lp) wrote :

@Alvin - would you consider it save backporting the HPGL export fix for transformations to the 0.48.x branch so that the latest improvements get released with 0.48.1?

The changes are in revision 9689 (transformations, bug #600472).

Revision history for this message
su_v (suv-lp) wrote :

backported to inkscape 0.48.x in r9721

follow-up report for <rect>:
Bug #657289 “[dxf export] add support for basic SVG shapes like <rect>”
<https://bugs.launchpad.net/inkscape/+bug/657289>

Changed in inkscape:
milestone: none → 0.48.1
status: Confirmed → Fix Committed
su_v (suv-lp)
Changed in inkscape:
assignee: nobody → Alvin Penner (apenner)
jazzynico (jazzynico)
Changed in inkscape:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.