diff --git a/src/Mod/Draft/Resources/ui/preferences-dxf.ui b/src/Mod/Draft/Resources/ui/preferences-dxf.ui index 45847555b4..ef408b3c10 100644 --- a/src/Mod/Draft/Resources/ui/preferences-dxf.ui +++ b/src/Mod/Draft/Resources/ui/preferences-dxf.ui @@ -584,11 +584,11 @@ If it is set to '0' the whole spline is treated as a straight segment. - Drawing Views will be exported as blocks. + TechDraw Views will be exported as blocks. This might fail for post DXF R12 templates. - Export Drawing Views as blocks + Export TechDraw Views as blocks true diff --git a/src/Mod/Draft/draftfunctions/dxf.py b/src/Mod/Draft/draftfunctions/dxf.py index 5464fa4d34..c5ec52ae69 100644 --- a/src/Mod/Draft/draftfunctions/dxf.py +++ b/src/Mod/Draft/draftfunctions/dxf.py @@ -67,8 +67,7 @@ def get_dxf(obj, direction=None): """ plane = None result = "" - if (obj.isDerivedFrom("Drawing::View") - or obj.isDerivedFrom("TechDraw::DrawView")): + if obj.isDerivedFrom("TechDraw::DrawView"): if obj.Source.isDerivedFrom("App::DocumentObjectGroup"): for o in obj.Source.Group: result += get_dxf(o, obj.Direction) diff --git a/src/Mod/Draft/importDXF.py b/src/Mod/Draft/importDXF.py index 12972bde62..636d4710a6 100644 --- a/src/Mod/Draft/importDXF.py +++ b/src/Mod/Draft/importDXF.py @@ -3474,9 +3474,8 @@ def export(objectslist, filename, nospline=False, lwPoly=False): it will use its `getDXF()` method to provide the DXF information to write into `filename`. - If the list only contains a `'Drawing::FeaturePage'` - or a `'TechDraw::DrawPage'` object it will use `exportPage()` - to produce the DXF file. + If the list only contains a `'TechDraw::DrawPage'` object it will use + `exportPage()` to produce the DXF file. filename : str The path of the new DXF file. @@ -3544,10 +3543,6 @@ def export(objectslist, filename, nospline=False, lwPoly=False): f.write(dxf) f.close() - elif (len(exportList) == 1) and (exportList[0].isDerivedFrom("Drawing::FeaturePage")): - # page: special hack-export! (see below) - exportPage(exportList[0], filename) - elif (len(exportList) == 1) and (exportList[0].isDerivedFrom("TechDraw::DrawPage")): # page: special hack-export! (see below) exportPage(exportList[0], filename) @@ -3818,8 +3813,8 @@ def exportPage(page, filename): Parameters ---------- - page : object derived from 'Drawing::FeaturePage' or 'TechDraw::DrawPage' - A Drawing or TechDraw page to export. + page : object derived from 'TechDraw::DrawPage' + A TechDraw page to export. filename : str The path of the new DXF file. @@ -3897,9 +3892,8 @@ def getViewBlock(geom, view, blockcount): the `getDXF()` method of the `view`. view : page view - A Drawing or TechDraw view which may be of different types + A TechDraw view which may be of different types depending on the objects being projected: - ``'Drawing::FeatureViewPython'`, `'TechDraw::DrawViewDraft'`, or `'TechDraw::DrawViewArch'`. blockcount : int @@ -3937,7 +3931,7 @@ def getViewBlock(geom, view, blockcount): block += "0\nENDBLK\n5\n_handle_\n100\nAcDbEntity\n8\n0\n100\nAcDbBlockEnd\n" insert += "0\nINSERT\n5\n_handle_\n8\n0\n6\nBYLAYER\n62\n256\n2\n" insert += view.Name + str(blockcount) - insert += "\n10\n" + str(view.X) + "\n20\n" + str(-view.Y) + insert += "\n10\n" + str(view.X) + "\n20\n" + str(view.Y) insert += "\n30\n0\n41\n" + str(view.Scale) + "\n42\n" + str(view.Scale) + "\n43\n" + str(view.Scale) insert += "\n50\n" + str(r) + "\n" blockcount += 1 @@ -3948,8 +3942,8 @@ def getViewBlock(geom, view, blockcount): return block, insert, blockcount -def getViewDXF(view, blocks=True): - """Return a DXF fragment from a Drawing view. +def getViewDXF(view): + """Return a DXF fragment from a TechDraw view. Depending on the type of page view, it will try obtaining `geom`, the DXF representation of `view`, @@ -3957,12 +3951,7 @@ def getViewDXF(view, blocks=True): with `getViewBlock(geom, view, blockcount)`, starting with a `blockcount` of 1. - If `view` is a group (`'App::DocumentObjectGroup'`) - it will recursively call itself in a loop `getViewDXF(child)`, - where `child` is a view contained in `view.Group`, - until all children are processed. - - If the `view` is `'Drawing::FeatureViewPart'`, + If the `view` is `'TechDraw::DrawViewPart'`, and if the global variable `dxfExportBlocks` exists, it will create the appropriate strings for `BLOCK` and `INSERT` sections, and increment the `blockcount`. @@ -3972,14 +3961,10 @@ def getViewDXF(view, blocks=True): Parameters ---------- view : App::DocumentObjectGroup or page view - A Drawing or TechDraw view which may be of different types + A TechDraw view which may be of different types depending on the objects being projected: - `'Drawing::FeatureViewPython'`, `'TechDraw::DrawViewDraft'`, `'TechDraw::DrawViewArch'`, - `'Drawing::FeatureViewPart'`, `'Drawing::FeatureViewAnnotation'` - - blocks : bool, optional - It defaults to `True`. Not used? + `'TechDraw::DrawViewPart'`, `'TechDraw::DrawViewAnnotation'` Returns ------- @@ -3994,19 +3979,8 @@ def getViewDXF(view, blocks=True): insert = "" blockcount = 1 - if view.isDerivedFrom("App::DocumentObjectGroup"): - for child in view.Group: - b, e = getViewDXF(child) - block += b - insert += e - - elif view.isDerivedFrom("Drawing::FeatureViewPython"): - if hasattr(view.Proxy, "getDXF"): - geom = view.Proxy.getDXF(view) - block, insert, blockcount = getViewBlock(geom, view, blockcount) - - elif view.isDerivedFrom("TechDraw::DrawViewDraft"): - geom = Draft.getDXF(view) + if view.isDerivedFrom("TechDraw::DrawViewDraft"): + geom = Draft.get_dxf(view) block, insert, blockcount = getViewBlock(geom, view, blockcount) elif view.isDerivedFrom("TechDraw::DrawViewArch"): @@ -4014,41 +3988,36 @@ def getViewDXF(view, blocks=True): geom = ArchSectionPlane.getDXF(view) block, insert, blockcount = getViewBlock(geom, view, blockcount) - elif view.isDerivedFrom("Drawing::FeatureViewPart"): - r = view.Rotation - if r != 0: - r = -r # fix rotation direction + elif view.isDerivedFrom("TechDraw::DrawViewPart"): import TechDraw - proj = TechDraw.projectToDXF(view.Source.Shape, view.Direction) - if dxfExportBlocks: - # change layer and set color and ltype to BYBLOCK (0) - proj = proj.replace("sheet_layer\n", - "0\n6\nBYBLOCK\n62\n0\n5\n_handle_\n") - block = "0\nBLOCK\n5\n_handle_\n100\nAcDbEntity\n8\n0\n100\nAcDbBlockBegin\n2\n" - block += view.Name + str(blockcount) - block += "\n70\n0\n10\n0\n20\n0\n3\n" + view.Name + str(blockcount) - block += "\n1\n\n" - block += proj - block += "0\nENDBLK\n5\n_handle_\n100\nAcDbEntity\n8\n0\n100\nAcDbBlockEnd\n" - insert += "0\nINSERT\n5\n_handle_\n8\n0\n6\nBYLAYER\n62\n256\n2\n" - insert += view.Name + str(blockcount) - insert += "\n10\n" + str(view.X) + "\n20\n" + str(-view.Y) - insert += "\n30\n0\n41\n" + str(view.Scale) - insert += "\n42\n" + str(view.Scale) + "\n43\n" + str(view.Scale) - insert += "\n50\n" + str(r) + "\n" - blockcount += 1 - else: - proj = proj.replace("sheet_layer\n", "0\n5\n_handle_\n") - insert += proj + for obj in view.Source: + proj = TechDraw.projectToDXF(obj.Shape, view.Direction) + if dxfExportBlocks: + # change layer and set color and ltype to BYBLOCK (0) + proj = proj.replace("sheet_layer\n", + "0\n6\nBYBLOCK\n62\n0\n5\n_handle_\n") + block += "0\nBLOCK\n5\n_handle_\n100\nAcDbEntity\n8\n0\n100\nAcDbBlockBegin\n2\n" + block += view.Name + str(blockcount) + block += "\n70\n0\n10\n0\n20\n0\n3\n" + view.Name + str(blockcount) + block += "\n1\n\n" + block += proj + block += "0\nENDBLK\n5\n_handle_\n100\nAcDbEntity\n8\n0\n100\nAcDbBlockEnd\n" + insert += "0\nINSERT\n5\n_handle_\n8\n0\n6\nBYLAYER\n62\n256\n2\n" + insert += view.Name + str(blockcount) + insert += "\n10\n" + str(view.X) + "\n20\n" + str(view.Y) + insert += "\n30\n0\n41\n" + str(view.Scale) + insert += "\n42\n" + str(view.Scale) + "\n43\n" + str(view.Scale) + insert += "\n50\n" + str(view.Rotation) + "\n" + blockcount += 1 + else: + proj = proj.replace("sheet_layer\n", "0\n5\n_handle_\n") + insert += proj # view.Rotation is ignored - elif view.isDerivedFrom("Drawing::FeatureViewAnnotation"): - r = view.Rotation - if r != 0: - r = -r # fix rotation direction + elif view.isDerivedFrom("TechDraw::DrawViewAnnotation"): insert = "0\nTEXT\n5\n_handle_\n8\n0\n100\nAcDbEntity\n100\nAcDbText\n5\n_handle_" - insert += "\n10\n" + str(view.X) + "\n20\n" + str(-view.Y) + insert += "\n10\n" + str(view.X) + "\n20\n" + str(view.Y) insert += "\n30\n0\n40\n" + str(view.Scale/2) - insert += "\n50\n" + str(r) + insert += "\n50\n" + str(view.Rotation) insert += "\n1\n" + view.Text[0] + "\n" else: @@ -4056,37 +4025,6 @@ def getViewDXF(view, blocks=True): return block, insert -def exportPageLegacy(page, filename): - """Export a page created with Drawing or TechDraw workbenches. DEPRECATED. - - It uses the `importSVG` module to import the SVG information of `page` - into a temporary document, then the objects of this document - are used with the exporter to produce the DXF file, - and the temporary document is closed. - :: - temp = importSVG.open(page.PageResult) - export(temp.Objects, filename, nospline=True, lwPoly=false) - App.closeDocument(temp.Name) - - Parameters - ---------- - page : object derived from 'Drawing::FeaturePage' or 'TechDraw::DrawPage' - A Drawing or TechDraw page to export. - - filename : str - The path of the new DXF file. - - See also - -------- - exportPage, export, importSVG.open - """ - import importSVG - tempdoc = importSVG.open(page.PageResult) - tempobj = tempdoc.Objects - export(tempobj, filename, nospline=True, lwPoly=False) - FreeCAD.closeDocument(tempdoc.Name) - - def readPreferences(): """Read the preferences of the this module from the parameter database.