Draft: Preliminary DWG support
Using the teigha file converter. Warning, only working on linux at the moment. See mantis issue 1103 to help me porting to other OSes
This commit is contained in:
parent
f815b07144
commit
e3dd8196bd
|
@ -162,3 +162,12 @@ App.addExportType("Autodesk DXF (*.dxf)","importDXF")
|
|||
App.addExportType("Flattened SVG (*.svg)","importSVG")
|
||||
App.addExportType("Open CAD Format (*.oca)","importOCA")
|
||||
|
||||
# DWG support
|
||||
import importDWG
|
||||
if importDWG.getTeighaConvertor():
|
||||
App.addImportType("Autodesk DWG (*.dwg)","importDWG")
|
||||
App.addExportType("Autodesk DWG (*.dwg)","importDWG")
|
||||
else:
|
||||
from DraftTools import translate
|
||||
FreeCAD.Console.PrintMessage(str(translate("draft","Teigha File Converter not found, DWG support will be disabled.\n")))
|
||||
|
||||
|
|
85
src/Mod/Draft/importDWG.py
Normal file
85
src/Mod/Draft/importDWG.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
# -*- coding: utf8 -*-
|
||||
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2009 Yorik van Havre <yorik@uncreated.net> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (GPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
"FreeCAD Draft Workbench - DWG importer/exporter"
|
||||
|
||||
if open.__module__ == '__builtin__':
|
||||
pythonopen = open # to distinguish python built-in open function from the one declared here
|
||||
|
||||
def open(filename):
|
||||
"called when freecad opens a file."
|
||||
teigha = getTeighaConvertor()
|
||||
dxf = convertToDxf(filename)
|
||||
import importDXF
|
||||
doc = importDXF.open(dxf)
|
||||
return doc
|
||||
|
||||
def insert(filename,docname):
|
||||
"called when freecad imports a file"
|
||||
dxf = convertToDxf(filemname)
|
||||
import importDXF
|
||||
doc = importDXF.insert(dxf,docname)
|
||||
return doc
|
||||
|
||||
def export(objectslist,filename):
|
||||
"called when freecad exports a file"
|
||||
import importDXF,os,tempfile
|
||||
outdir = tempfile.mkdtemp()
|
||||
dxf = outdir + os.sep + os.path.splitext(os.path.basename(filename))[0] + ".dxf"
|
||||
importDXF.export(objectslist,dxf)
|
||||
convertToDwg(dxf,filename)
|
||||
return filename
|
||||
|
||||
def getTeighaConvertor():
|
||||
"finds the Teigha Convertor executable"
|
||||
import os,platform
|
||||
if platform.system() == "Linux":
|
||||
teigha = "/usr/bin/TeighaFileConverter"
|
||||
if os.path.exists(teigha):
|
||||
return teigha
|
||||
return None
|
||||
|
||||
def convertToDxf(dwgfilename):
|
||||
"converts a DWG file to DXF"
|
||||
import os,tempfile
|
||||
teigha = getTeighaConvertor()
|
||||
indir = os.path.dirname(dwgfilename)
|
||||
outdir = tempfile.mkdtemp()
|
||||
basename = os.path.basename(dwgfilename)
|
||||
cmdline = teigha + ' "' + indir + '" "' + outdir + '" "ACAD2010" "DXF" "0" "1" "' + basename + '"'
|
||||
print "converting " + cmdline
|
||||
os.system(cmdline)
|
||||
return outdir + os.sep + os.path.splitext(basename)[0] + ".dxf"
|
||||
|
||||
def convertToDwg(dxffilename,dwgfilename):
|
||||
"converts a DXF file to DWG"
|
||||
import os
|
||||
teigha = getTeighaConvertor()
|
||||
indir = os.path.dirname(dxffilename)
|
||||
outdir = os.path.dirname(dwgfilename)
|
||||
basename = os.path.basename(dxffilename)
|
||||
cmdline = teigha + ' "' + indir + '" "' + outdir + '" "ACAD2010" "DWG" "0" "1" "' + basename + '"'
|
||||
print "converting " + cmdline
|
||||
os.system(cmdline)
|
||||
return dwgfilename
|
|
@ -40,6 +40,7 @@
|
|||
<File Id="DraftRcPy" Name="Draft_rc.py" DiskId="1" />
|
||||
<File Id="DraftVecUtilsPy" Name="DraftVecUtils.py" DiskId="1" />
|
||||
<File Id="DraftGeomUtilsPy" Name="DraftGeomUtils.py" DiskId="1" />
|
||||
<File Id="importDWGPy" Name="importDWG.py" DiskId="1" />
|
||||
</Component>
|
||||
<Directory Id="ModDraftLib" Name="draftlibs" FileSource="../../Mod/Draft/draftlibs">
|
||||
<Component Id="CompModDraftLib" Guid="d19c08b0-0747-11de-8c30-0800200c9a66" Win64='$(var.Win_64)' KeyPath="yes">
|
||||
|
|
Loading…
Reference in New Issue
Block a user