Skip to content

Commit

Permalink
Merge pull request #9830 from Roy-043/Draft-Add-macOS-paths-to-import…
Browse files Browse the repository at this point in the history
…DWG.py

Draft: Add macOS paths to importDWG.py
  • Loading branch information
yorikvanhavre committed Jun 28, 2023
2 parents 28f8abd + f20ea86 commit 095ad1f
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/Mod/Draft/importDWG.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def export(objectslist, filename):
def get_libredwg_converter(typ):
"""Find the LibreDWG converter.
It searches the FreeCAD parameters database, then searches the OS search path
on Linux and Windows systems. There are no standard installation paths.
It searches the FreeCAD parameters database, then searches the OS search path.
There are no standard installation paths.
`typ` is required because LibreDWG uses two converters and we store only one.
Expand All @@ -161,25 +161,24 @@ def get_libredwg_converter(typ):
path = os.path.dirname(path) + "/" + typ + os.path.splitext(path)[1]
if os.path.exists(path) and os.path.isfile(path):
return path
elif platform.system() == "Linux":
for sub in os.getenv("PATH").split(":"):
path = sub + "/" + typ
if os.path.exists(path) and os.path.isfile(path):
return path
elif platform.system() == "Windows":
for sub in os.getenv("PATH").split(";"):
for sub in os.getenv("PATH").split(os.pathsep):
path = sub.replace("\\", "/") + "/" + typ + ".exe"
if os.path.exists(path) and os.path.isfile(path):
return path
else: # for Linux and macOS
for sub in os.getenv("PATH").split(os.pathsep):
path = sub + "/" + typ
if os.path.exists(path) and os.path.isfile(path):
return path

return None


def get_oda_converter():
"""Find the ODA converter.
It searches the FreeCAD parameters database, then searches for common
paths on Linux and Windows systems.
It searches the FreeCAD parameters database, then searches for common paths.
Parameters
----------
Expand All @@ -199,26 +198,29 @@ def get_oda_converter():
if "ODAFileConverter" in path: # path set manually
if os.path.exists(path) and os.path.isfile(path):
return path
elif platform.system() == "Linux":
path = "/usr/bin/ODAFileConverter"
if os.path.exists(path) and os.path.isfile(path):
return path
elif platform.system() == "Windows":
odadir = os.path.expandvars("%ProgramFiles%\\ODA").replace("\\", "/")
if os.path.exists(odadir):
for sub in os.listdir(odadir):
path = odadir + "/" + sub + "/" + "ODAFileConverter.exe"
if os.path.exists(path) and os.path.isfile(path):
return path
elif platform.system() == "Linux":
path = "/usr/bin/ODAFileConverter"
if os.path.exists(path) and os.path.isfile(path):
return path
else: # for macOS
path = "/Applications/ODAFileConverter.app/Contents/MacOS/ODAFileConverter"
if os.path.exists(path) and os.path.isfile(path):
return path

return None


def get_qcad_converter():
"""Find the QCAD converter.
It searches the FreeCAD parameters database, then searches for common
paths on Linux and Windows systems.
It searches the FreeCAD parameters database, then searches for common paths.
Parameters
----------
Expand All @@ -237,15 +239,17 @@ def get_qcad_converter():

if "dwg2dwg" in path: # path set manually
pass
elif platform.system() == "Windows":
path = os.path.expandvars("%ProgramFiles%\\QCAD\\dwg2dwg.bat").replace("\\", "/")
elif platform.system() == "Linux":
# /home/$USER/opt/qcad-3.28.1-trial-linux-qt5.14-x86_64/dwg2dwg
path = os.path.expandvars("/home/$USER/opt")
for sub in os.listdir(path):
if "qcad" in sub:
path = path + "/" + sub + "/" + "dwg2dwg"
break
elif platform.system() == "Windows":
path = os.path.expandvars("%ProgramFiles%\\QCAD\\dwg2dwg.bat").replace("\\", "/")
else: # for macOS
path = "/Applications/QCAD.app/Contents/Resources/dwg2dwg"

if os.path.exists(path) and os.path.isfile(path):
return path
Expand Down

0 comments on commit 095ad1f

Please sign in to comment.