diff --git a/src/Mod/Draft/draftobjects/hatch.py b/src/Mod/Draft/draftobjects/hatch.py index 8de4cadb30..d21011b8ea 100644 --- a/src/Mod/Draft/draftobjects/hatch.py +++ b/src/Mod/Draft/draftobjects/hatch.py @@ -30,6 +30,7 @@ import FreeCAD as App from draftgeoutils.general import geomType from draftobjects.base import DraftObject from draftutils import gui_utils +from draftutils.messages import _err from draftutils.translate import translate @@ -85,12 +86,37 @@ class Hatch(DraftObject): or not obj.File \ or not obj.Pattern \ or not obj.Scale \ - or not obj.Pattern in self.getPatterns(obj.File) \ or not obj.Base.isDerivedFrom("Part::Feature") \ or not obj.Base.Shape.Faces: self.props_changed_clear() return + if obj.File[0] == ".": + # File path relative to the FreeCAD file directory. + pat_file = os.path.join(os.path.dirname(obj.Document.FileName), obj.File) + # We need the absolute path to do some file checks. + pat_file = os.path.abspath(pat_file) + else: + pat_file = obj.File + + # File checks: + if not os.path.exists(pat_file): + _err(obj.Label + ": " + translate("draft", "PAT file not found")) + self.props_changed_clear() + return + if not os.path.isfile(pat_file): + _err(obj.Label + ": " + translate("draft", "Specified PAT file is not a file")) + self.props_changed_clear() + return + if os.path.splitext(pat_file)[1].lower() != ".pat": + _err(obj.Label + ": " + translate("draft", "Specified file type is not supported")) + self.props_changed_clear() + return + if not obj.Pattern in self.getPatterns(pat_file): + _err(obj.Label + ": " + translate("draft", "Pattern not found in PAT file")) + self.props_changed_clear() + return + import Part import TechDraw @@ -134,7 +160,7 @@ class Hatch(DraftObject): if obj.Rotation.Value: face.rotate(App.Vector(), App.Vector(0, 0, 1), -obj.Rotation) - shape = TechDraw.makeGeomHatch(face, obj.Scale, obj.Pattern, obj.File) + shape = TechDraw.makeGeomHatch(face, obj.Scale, obj.Pattern, pat_file) if obj.Rotation.Value: shape.rotate(App.Vector(), App.Vector(0, 0, 1), obj.Rotation)