Inkscape and dxf files

Inkscape is a really nice open-source vector graphics program. The latest version as of this writing is 0.46. In the architectural design workflow it’s nice to use such programs for drawings presentations etc. The default installation of inkscape is able to save to dxf but can’t open dxf files. There are 2 methods of importing dxf files into inkscape.

Method A: dxf2svg extension

There seems to be an extension included with inkscape for importing dxf files, but it depends on a dxf2svg executable which is nowhere to be found. At the inkscape wiki there is a link to a sourceforge projet but the zip file there is corrupted and of no good use. The only way to get the dxf2svg executable is by compiling through the cvs sources and placing the resulting dxf2svg program in your PATH (ie /usr/bin/dxf2svg).

[More details on howto compile later]

The pros of this method is that it’s simple and that it automatically translates dxf layers to svg layers and imports the drawing in it’s real dimensions so scaling is easy.

The cons of this method is that it doesn’t support lots of entities from dxf like for example hatch or text. Also it doesn’t retain colors in the result svg.

Method B: kabeja dxf2svg

The alternative method for importing dxf files in inkscape is called kabeja and it’s another sourceforge project that uses java to convert from dxf to svg. The latest version of kabeja is 0.4. The problem with kabeja is that the inkscape extension package they have doesn’t work out-of-the-box with inkscape 0.46. With a little bit of tweaking you can get it to work properly. Here’s how:

Download kabeja from here.

Note: download the binary, this howto uses the “pure” java version not the .NET extension

Extract the file somewhere

Edit the file called kabeja inside the inkscape-extension folder and append “$2” at the end of the 3rd line like this:

java -jar  $KABEJA_HOME/kabeja-dxf2svg.jar "$1" "$2"

Save the file and give it executable permissions (ie right-click->Properties->Permissions->”allow executing file as a program” )

As sudo copy all the files from the inkscape-extension folder  to /usr/share/inkscape/extensions

Now, fire up Inkscape and test it by IMPORTING a dxf file. This is crucial. Do not open the dxf file, import it. The difference is that if you open it then it will be scaled to fit the default page size and scaling to a specific scale (ie 1:50, 1:100) will be more difficult.

Note: dxf 2000 or r14 work well i don’t know about other versions.

Note: you need to have sun-java6-jre installed. Search for sun-java in synaptic.

To import the dxf file under scale you need the “magic number”. On import the units are translated to pixels. This is confusing. Inkscape uses 90dpi resolution as specified by the svg standard. With some simple math (for metric drawings) you get the number 35.433070866. Now depending on the units you used when drawing the dxf you will have to scale the imported geometry in multiples of this number. For example a dxf with 1unit=1meter will have to be scaled by 3543.307% to be under 1:100 scale in inkscape. (Usually, you scale to 1:100 which is a convenient scale and then scale to he desired one. To scale under inkscape you can use the transformations dialog (Shift+Ctrl+M).

One thing you’ll notice is that the  resulting svg file has no separate layers for the imported objects. Wouldn’t it be nice to have your layer structure imported to inkscape so as to work with your drawings more efficiently? Here comes I to the rescue. I’ve written a small extension for inkscape 0.46 that fixes layers for kabeja-imported dxf files. you need to apply this effect right after importing the dxf, without deselecting the imported geometry. There are two files:

fix_layers.py:

#!/usr/bin/env python

import inkex

class GroupsToLayers(inkex.Effect):

    def __init__(self):
        # Call base class construtor.
        inkex.Effect.__init__(self)

    def effect(self):
        root=self.document.getroot()
        selected = self.selected
        for id, node in selected.iteritems():
            if node.tag == inkex.addNS('g','svg'):
                layername = id[3:]
                node.set(inkex.addNS("groupmode","inkscape"),"layer")
                node.set(inkex.addNS("label","inkscape"),layername)
                root.append(node)

effect = GroupsToLayers()
effect.affect()

fix_layers.inx:

<inkscape-extension>
    <_name>Fix Kabeja Layers</_name>
    <id>org.alxarch.filter.fixlayers</id>
    <dependency type="executable" location="extensions">fix_layers.py</dependency>
    <dependency type="executable" location="extensions">inkex.py</dependency>
    <effect>
        <object-type>all</object-type>
        <effects-menu>
            <submenu _name="Examples"/>
        </effects-menu>
    </effect>
    <script>
        <command reldir="extensions" interpreter="python">fix_layers.py</command>
    </script>
</inkscape-extension>

Copy paste to gedit and get the appropriate names for the files. Put them into /usr/share/inkscape/extensions/ folder. Now open inkscape again, open a dxf file and go to Effects->Examples->Fix Kabeja Layers. After a bit your svg file has all the layers the dxf file had.

Enjoy!

AutoCad 2000 in wine HOWTO

Introduction

This was troubling me for a couple of years…

It IS posible to have a fully functional autocad 2000 in linux running under wine. It needs some tricks to get it working. I learned all these answers through trial and error and since i haven’t found any howtos for the process i decided to write one. I have tested the method described here on my systems and it works. One thing to notice is that i am refering only to the autocad 2000 version, not 2000i, not 2002 just 2000. Later versions of autocad might install with some similar way under wine but from my tests they do not work well and do crash A LOT. If you also follow the tips and trics post, autocad 2000 will prove more than enough for at least 2d CAD work. For 3d i suggest you head over to www.blender.org and get yourself a real 3d modelling application. From my personal experience 3d modelling in autocad SUCKS big time, especially for my line of duty which is architectural design. That said lets get on with the howto but not without a big fat warning:

WARNING! If you have other programs running under wine do a backup of your /home/<username>/.wine folder before proceeding. If you mess up your wine drive you could lose other wine programs you have already worked hard to install. For example on a terminal do:

$ cp -Rp ~/.wine ~/wine-bak

[EDIT:The short version is removed. The short version had some issues during the installation that messed up textediting in acad.]

Installation

First we need to install wine. Go to System->Administration->Synaptic Package Manager and search and install wine (preferably using the up-to-date wine repositories)

Then to make things easy for us we will use a Graphical User Interface that helps us manage our wine installation. It’s called wine doors and you can get it here. Install the package and go to Applications->Wine->Wine doors.

The first screen needs a name and asks if we have a valid windows license to which we reply “Yes, unfortunately we do” regardless of whether we do have one or not. (maybe your auntie has one, does this count?). Wine doors will connect to the internet and kindly install some basic packages to our wine installation.

NOTE: During this time it may seem as it has crashed. Be Patient! It will get on with it eventually. If not see troubleshooting.

The second screen will be a list of available applications to install in your wine installation. From this long list we will pick the following (one by one):

  • Anything that looks like a font (Andale, Trebuchet, Tahoma etc)
  • The DCOM98 package
  • The Microsoft Foundation Classes 4 package
  • The Native Rich Text Editor Support 30 package

Click Apply and wait patiently for wine doors to download and install all of the above.

Ok now with the prerequisites installed we can finally launch the acad installation. Go to the folder where the installation files are (did someone say torrent or is it just my ears?) and right click on the SETUP.EXE and select to run it with wine windows emulator. If the installer doesn’t start or complains about the windows version and quits then refer to the troubleshooting section.

At this point you should have your serial number and cd-key handy and go through the installation screens up to the point of choice of an installation type. Here you select compact install. Other options cause trouble (see troubleshooting). Ok next stop is the select text editor screen. Here you can browse to and select c:\windows\notepad.exe if it’s not allready selected. A few clicks later and if everything went well you have autocad 2000 installed on your wine drive and a nice icon on the linux desktop. Last step for the installation is to restart wine so registry changes fall in place gracefully. Open wine-dors again and go to File->Reboot Wine.

Double-click the acad icon placed on your Desktop to fire up autocad for the first time. If it opens it will ask you to activate it, do that and close it. If not then refer to the troubleshooting section.

Ok the next step AFTER ACTIVATION is to install some service packs and driver upgrades for autocad 2000.

[The good thing about old programs is that software companies DID release bugfixes back then and didn’t force you to upgrade to a more buggy, extra needless features, wanna be word-like release of the program (i.e. AutoCad 2009 a.k.a. OMG! is this office?).]

There are two service packs for autocad 2000 and a driver update for the opengl driver. First get the installers from here, here and here.  A reader (thanks tyk) suggested that you should install also an update for plotting. Run them in the logical order, service pack 1, service pack 2 , 3d driver update and plotting update.

NOTE: The service packs exe files are winzip self-extractable archives. You need to run them once, extract and then run the extracted Setupex.exe file. By default they are extracted in /home/<<USERNAME>>/.wine/drive_c/windows/temp folder

At this point you should have a mostly-functional autocad 2000 on your linux machine. The final trick is to use the script provided below to workaround some issues. Copy the text into an empty text file in gedit and save it somewhere in your home folder with an “.sh” extension, for example /home/<username>/acad.sh . Give it executable permissions by right click on the file and: Properties->Permissions->allow execution as a program. The only thing left to do is change the wine-generated icon on the desktop to point to this file (right-click->properties->launcher->command->/home/<username>/acad.sh).

That wasn’t so hard now was it? Don’t forget to read through the tips and tricks post to tweak your old autocad 2000 to be more productive.

The Script

This little script is needed to run autocad for two reasons three reasons:

  1. For some reason if you maximize the acad window and exit the program it will never open up again. This happens because of s registry key that saves the window size on exit and if it’s larger than the screen bounds, acad crashes. The script deletes the registry key restoring the default (almost maximized) ssize for the acad window.
  2. If you need to read and write text containing characters other than basic latin you need to change the locale setting for wine to the language you want. I need greek text so i used the el_GR.UTF-8 locale. You need to have the corresponding language pack installed (System->Administration->Language Support).
  3. After every wine upgrade the PATH registry key gets reset (at least in my machines) this results in a broken autocad.Autocad needs some dlls in the Common Files directory and it won’t start if “C:\Program Files\Common Files\Autodesk Shared” is not in the PATH. This script makes sure that it’s there.

To change the locale for wine just change the LC_ALL=”<locale_alias>” in the script below with the language of your choice or, if you don’t want support for other languages, just delete the LC_ALL=”el_GR.UTF-8″ part. Remember to change the username.

#! /bin/bash

##CHANGE TO POINT TO YOUR WINE INSTALLATION
export WINEPREFIX="/home/alxarch/.wine"

#Only needed if you want to write in your locale
export LC_ALL="el_GR.UTF-8"

# When autocad closes the size of the application window
# is stored in this key. If it was maximized when closed,
# it will not be able to open again.(on some windows managers)
# so it's easier to just delete this key on startup

regedit /D HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R15.0\\ACAD-1:409\\FixedProfile\\Application\ Window

# After a wine upgrade the PATH variable is unset for
# some reason. Autocad needs some dlls in the Common
# Files directory and it won't start if "C:\Program Fi
# les\Common Files\Autodesk Shared" is not in the PATH
# So we extract the key, using sed, we first remove it
# from PATH (if it exists) and then prepend it to PATH.
# This way Autocad won't break upon wine upgrades

regedit /E /tmp/path.reg HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session\ Manager\\Environment

sed \
-e 's/;;//' \
-e 's/C:\\\\Program\ Files\\\\Common\ Files\\\\Autodesk\ Shared//' \
-e 's/^\"PATH\"=\"/&C:\\\\Program\ Files\\\\Common\ Files\\\\Autodesk\ Shared;/' \
/tmp/path.reg > /tmp/correct.reg

regedit /tmp/correct.reg

rm /tmp/path.reg

rm /tmp/correct.reg

wine "C:\Program Files\ACAD2000\acad.exe"

Troubleshooting

If some installer doesn’t run (it happens to me in ubuntu hardy) you should issue the comand

$ sudo sysctl -w vm.mmap_min_addr=0

If the installer is complaining about the windows version you have to run the wine configuration tool (winecfg) and select windows 2000 as the default version.

In the installer, selecting the compact install option is the safest bet. As of wine 9.61 you are able to complete the installation by choosing custom install option (in earlier versions of wine it crashed). This is usefull if you want the express tools and the internet components. Database and VBA still crash the installer. I don’t know about other options. Proceed with caution. The best way is to install with compact option and then re-run the installer and select to add features.

If, after installation, autocad won’t launch you will need to tweak the registry of wine a bit. Regedit, find the key

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Session Manager\Enviroment\PATH

and append (without quotes):

“;C:\Program Files\Common Files\Autodesk Shared”

This way it will find all required DLLs.

If the script doesn’t run make sure you have given it executable permissions, make sure you have replaced the usename and check the text in gedit so as not to have copied html code from the browser or other strange symbols (i.e. curly quotes “„ instead of straight ones ” ).

The tips and tricks section has moved to a seperate post in order to keep this howto small and to the point. If your installation succeeded then go to the tips and tricks post to learn how to use your acad linux installation efficiently, working around some issues especially with the viewport performance.

Hope i’ve been of help to you,

Alex.