Draft: dwg support in windows

This commit is contained in:
Yorik van Havre 2013-04-21 23:32:34 -03:00
parent 1eb96db737
commit a22a719cb9
2 changed files with 17 additions and 8 deletions

View File

@ -164,7 +164,7 @@ App.addExportType("Open CAD Format (*.oca)","importOCA")
# DWG support
import importDWG
if importDWG.getTeighaConvertor():
if importDWG.getTeighaConverter():
App.addImportType("Autodesk DWG (*.dwg)","importDWG")
App.addExportType("Autodesk DWG (*.dwg)","importDWG")
else:

View File

@ -29,7 +29,6 @@ if open.__module__ == '__builtin__':
def open(filename):
"called when freecad opens a file."
teigha = getTeighaConvertor()
dxf = convertToDxf(filename)
import importDXF
doc = importDXF.open(dxf)
@ -51,19 +50,29 @@ def export(objectslist,filename):
convertToDwg(dxf,filename)
return filename
def getTeighaConvertor():
"finds the Teigha Convertor executable"
def getTeighaConverter():
"finds the Teigha Converter executable"
import os,platform
teigha = None
if platform.system() == "Linux":
teigha = "/usr/bin/TeighaFileConverter"
if os.path.exists(teigha):
return teigha
elif platform.system() == "Windows":
odadir = "C:\Program Files\ODA"
if os.path.exists(odadir):
subdirs = os.walk(odadir).next()[1]
for sub in subdirs:
t = odadir + os.sep + sub + os.sep + "TeighaFileConverter.exe"
if os.path.exists(t):
teigha = t
if teigha:
if os.path.exists(teigha):
return teigha
return None
def convertToDxf(dwgfilename):
"converts a DWG file to DXF"
import os,tempfile
teigha = getTeighaConvertor()
teigha = getTeighaConverter()
indir = os.path.dirname(dwgfilename)
outdir = tempfile.mkdtemp()
basename = os.path.basename(dwgfilename)
@ -75,7 +84,7 @@ def convertToDxf(dwgfilename):
def convertToDwg(dxffilename,dwgfilename):
"converts a DXF file to DWG"
import os
teigha = getTeighaConvertor()
teigha = getTeighaConverter()
indir = os.path.dirname(dxffilename)
outdir = os.path.dirname(dwgfilename)
basename = os.path.basename(dxffilename)