Working plugin!

parent 8b00b61f
# Python3
__pycache__/
# Eclipse+PyDev
.project
.pydevproject
\ No newline at end of file
[submodule "CadIntegrationUtils"]
path = CadIntegrationUtils
url = https://github.com/thopiekar/CadIntegrationUtils.git
Subproject commit 03045ca1e9f0d91c709f64ae3d7242e7dbad2c89
# Copyright (c) 2016 Thomas Karl Pietrowski
# built-ins
import os
import platform
# Uranium
from UM.Logger import Logger # @UnresolvedImport
from UM.i18n import i18nCatalog # @UnresolvedImport
# CIU
from .CadIntegrationUtils.CommonCLIReader import CommonCLIReader # @UnresolvedImport
i18n_catalog = i18nCatalog("FreeCADPlugin")
class FreeCADReader(CommonCLIReader):
def __init__(self):
super().__init__("FreeCAD")
self._supported_extensions = [".FCStd".lower(),
]
self.scanForAllPaths()
def areReadersAvailable(self):
return bool(self._readerForFileformat)
def exportFileAs(self, options, quality_enum = None):
Logger.log("d", "Exporting file: %s", options["tempFile"])
cmd = 'FreeCADCmd'
cmd = [cmd,
os.path.join(os.path.split(__file__)[0],
"scripts",
"convertIntoSTL.py"
),
'--',
options["foreignFile"],
options["tempFile"],
]
self.executeCommand(cmd, cwd = os.path.split(options["foreignFile"])[0])
# Copyright (c) 2016 Thomas Karl Pietrowski
# Uranium
from UM.Platform import Platform # @UnresolvedImport
from UM.Logger import Logger # @UnresolvedImport
from UM.i18n import i18nCatalog # @UnresolvedImport
i18n_catalog = i18nCatalog("FreeCADPlugin")
def getMetaData():
return {
"plugin": {
"name": i18n_catalog.i18nc("@label", "FreeCADPlugin"),
"author": "Thomas Karl Pietrowski",
"version": "0.1.0",
"description": i18n_catalog.i18nc("@info:whatsthis", "Gives you the possibility to open *.FCStd files."),
"api": 3
},
"mesh_reader": [
{
"extension": "FCStd",
"description": i18n_catalog.i18nc("@item:inlistbox", "FreeCAD file")
},
]
}
def register(app):
if Platform.isWindows() or Platform.isLinux() or Platform.isOSX():
from . import FreeCADReader # @UnresolvedImport
return {"mesh_reader": FreeCADReader.FreeCADReader()}
else:
Logger.logException("i", "Unsupported OS!")
return {}
{
"name": "FreeCAD integration",
"author": "Thomas Karl Pietrowski",
"version": "0.0.1",
"api": 4,
"description": "Help to open OpenSCAD files directly in Cura."
}
import os
import sys
import FreeCAD
import Part
import Mesh
in_fn, out_fn = sys.argv[-2:]
part_object = FreeCAD.open(in_fn)
all_objs_names = part_object.Objects
__objs__ = []
for obj_name in all_objs_names:
if obj_name.ViewObject:
if obj_name.ViewObject.isVisible():
__objs__.append(obj_name)
else: # <Part::PartFeature>
__objs__.append(obj_name)
Mesh.export(__objs__, out_fn)
\ No newline at end of file
# built-ins
import os
import sys
import subprocess
# OS dependent
if sys.platform == "win32":
import winreg
class Test():
def __init__(self):
self._supported_extensions = [".FCStd".lower(),
]
self._additional_paths = None
self.scanForAllPaths()
def executeCommand(self, command, cwd = os.path.curdir):
environment_with_additional_path = os.environ.copy()
if self._additional_paths:
environment_with_additional_path["PATH"] = os.pathsep.join(self._additional_paths) + os.pathsep + environment_with_additional_path["PATH"]
print("i", "Executing command: {}".format(command))
p = subprocess.Popen(command,
cwd = cwd,
env = environment_with_additional_path,
shell = True,
)
p.wait()
def scanForAllPaths(self):
self._additional_paths = []
if sys.platform == "win32":
for file_extension in self._supported_extensions:
path = self._findPathFromExtension(file_extension)
print("d", "Found path for {}: {}".format(file_extension, path))
if path:
self._additional_paths.append(path)
def _findPathFromExtension(self, extension):
file_class = winreg.QueryValue(winreg.HKEY_CLASSES_ROOT, extension)
file_class = winreg.QueryValue(winreg.HKEY_CLASSES_ROOT, os.path.join(file_class,
"shell",
"open",
"command",
)
)
file_class = file_class.split("\"")
while "" in file_class:
file_class.remove("")
file_class = file_class[0]
path = os.path.split(file_class)[0]
if os.path.isdir(path):
return path
return
def exportFileAs(self, foreign, stl):
print("d", "Exporting file: {}".format(stl))
cmd = r'FreeCADCmd'
cmd = [cmd,
#os.path.join(os.curdir,
# "scripts",
# "convertIntoSTL.py"
# ),
#'--',
#foreign,
#stl,
]
self.executeCommand(cmd, cwd = os.path.split(foreign)[0])
t = Test()
t.exportFileAs("test.FCStd", "test.stl")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment