Python FreeCAD.closeDocument() Examples

The following are 11 code examples of FreeCAD.closeDocument(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module FreeCAD , or try the search function .
Example #1
Source File: Commands.py    From NodeEditor with MIT License 6 votes vote down vote up
def  test_AA():
    import FreeCAD
    import FreeCADGui
    App=FreeCAD
    Gui=FreeCADGui
    ### Begin command Std_RecentFiles
    try:
        App.closeDocument('Unnamed')
    except:
        pass
        App.setActiveDocument("")
        App.ActiveDocument=None
        Gui.ActiveDocument=None

    FreeCAD.open(u"/home/thomas/Schreibtisch/move_2.FCStd")
    App.setActiveDocument("move_2")
    App.ActiveDocument=App.getDocument("move_2")
    Gui.ActiveDocument=Gui.getDocument("move_2")
    ### End command Std_RecentFiles
    loadGraph() 
Example #2
Source File: test_data_data_utils.py    From qmt with MIT License 6 votes vote down vote up
def test_store_serial(datadir, fix_FCDoc):
    """Test serialisation to memory."""
    import FreeCAD

    # Serialise document
    obj = fix_FCDoc.addObject("App::FeaturePython", "some_content")
    serial_data = store_serial(fix_FCDoc, lambda d, p: d.saveAs(p), "fcstd")

    # Write to a file
    file_path = os.path.join(datadir, "test.fcstd")

    data = codecs.decode(serial_data.encode(), "base64")
    with open(file_path, "wb") as of:
        of.write(data)

    # Load back and check
    doc = FreeCAD.newDocument("instance")
    FreeCAD.setActiveDocument("instance")
    doc.load(file_path)

    assert doc.getObject("some_content") is not None
    FreeCAD.closeDocument("instance") 
Example #3
Source File: tests.py    From FreeCAD_assembly2 with GNU Lesser General Public License v2.1 6 votes vote down vote up
def _test_file( self, testFile_basename, solution = None ):
        testFile = os.path.join( test_assembly_path, testFile_basename + '.fcstd' )
        debugPrint(1, testFile_basename )
        stats.n_attempted += 1
        #if testFile == 'tests/testAssembly11-Pipe_assembly.fcstd':
        #    print('Skipping known fail')
        #    continue
        doc =  FreeCAD.open(testFile)
        t_start_solver = time.time()
        xOpt = solveConstraints( doc, solver_name = 'newton_solver_slsqp', use_cache = self.use_cache, showFailureErrorDialog=False )
        if solution:
            self.check_solution( xOpt, solution )
        stats.t_solver += time.time() - t_start_solver
        assert not self.use_cache
        if not xOpt is None:
            stats.n_solved += 1
        FreeCAD.closeDocument( doc.Name )
        debugPrint(1,'\n\n\n')
        return xOpt 
Example #4
Source File: Commands.py    From NodeEditor with MIT License 5 votes vote down vote up
def shutdown():
    '''fast stop of freecad test environ'''
    try:
        FreeCAD.closeDocument("Unnamed")
    except:
        pass
    try:
        FreeCAD.closeDocument("graph")
    except:
        pass

    FreeCADGui.runCommand("Std_Quit") 
Example #5
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        doc = FreeCAD.activeDocument()
        try:
            doc.save()
            FreeCAD.closeDocument(doc.Name)
        except:
            FreeCADGui.SendMsgToActiveView("Save")
            if not FreeCADGui.activeDocument().Modified: # user really saved the file           
                FreeCAD.closeDocument(doc.Name)
        #
        mw = FreeCADGui.getMainWindow()
        mdi = mw.findChild(QtGui.QMdiArea)
        sub = mdi.activeSubWindow()
        if sub != None:
            sub.showMaximized() 
Example #6
Source File: conftest.py    From qmt with MIT License 5 votes vote down vote up
def fix_FCDoc():
    """Set up and tear down a FreeCAD document."""
    import FreeCAD

    doc = FreeCAD.newDocument("testDoc")
    yield doc
    FreeCAD.closeDocument("testDoc")


################################################################################
# Sketches 
Example #7
Source File: test_geo_objects.py    From qmt with MIT License 5 votes vote down vote up
def test_overlapping_parts(datadir):
    """
    This tests that two parts that were generated from lithography over a wire register as intersecting. Due to
    an OCC bug, FC 0.18 at one point would claim that these didn't intersect, resulting in geometry and meshing errors.
    """
    path = os.path.join(datadir, "intersection_test.FCStd")
    doc = FreeCAD.newDocument("instance")
    FreeCAD.setActiveDocument("instance")
    doc.load(path)
    shape_1 = doc.Objects[0]
    shape_2 = doc.Objects[1]
    assert checkOverlap([shape_1, shape_2])
    FreeCAD.closeDocument(doc.Name) 
Example #8
Source File: tests.py    From FreeCAD_assembly2 with GNU Lesser General Public License v2.1 5 votes vote down vote up
def _test_file( self, testFile_basename, solution = None ):
        testFile = os.path.join( test_assembly_path, testFile_basename + '.fcstd' )
        debugPrint(1, testFile_basename )
        stats.n_attempted += 1
        #if testFile == 'tests/testAssembly11-Pipe_assembly.fcstd':
        #    print('Skipping known fail')
        #    continue
        doc =  FreeCAD.open(testFile)
        t_start_solver = time.time()
        constraintSystem = solveConstraints( doc, solver_name = 'dof_reduction_solver', use_cache = self.use_cache, showFailureErrorDialog=False )
        if solution:
            self.check_solution( constraintSystem, solution )
        stats.t_solver += time.time() - t_start_solver
        if  self.use_cache:
            debugPrint(1,'\n\n')
            X_org = constraintSystem.variableManager.X
            t_start_cache = time.time()
            #cache.debugMode = 1
            constraintSystem = solveConstraints( doc, solver_name = 'dof_reduction_solver', use_cache =  self.use_cache )
            self.assertTrue(
                numpy.allclose( X_org , constraintSystem.variableManager.X ),
                'Cache solution differs from originial solution: %s != %s' % ( X_org , constraintSystem.variableManager.X )
            )
            #cache.debugMode = 0
            stats.t_cache += time.time() - t_start_cache
            constraintSystem.update()
        stats.n_solved += 1
        FreeCAD.closeDocument( doc.Name )
        debugPrint(1,'\n\n\n') 
Example #9
Source File: Command.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Activated(self):
        # So we can open the save-as dialog
        mw = FreeCADGui.getMainWindow()
        cqCodePane = Shared.getActiveCodePane()

        if cqCodePane == None:
            FreeCAD.Console.PrintError("Nothing to save.\r\n")
            return

        # Try to keep track of the previous path used to open as a convenience to the user
        if self.previousPath is None:
            self.previousPath = "/home/"

        filename = QtGui.QFileDialog.getSaveFileName(mw, mw.tr("Save CadQuery Script As"), self.previousPath,
                                                     mw.tr("CadQuery Files (*.py)"))

        self.previousPath = filename[0]

        # Make sure the user didn't click cancel
        if filename[0]:
            # Close the 3D view for the original script if it's open
            try:
                docname = os.path.splitext(os.path.basename(cqCodePane.get_path()))[0]
                FreeCAD.closeDocument(docname)
            except:
                # Assume that there was no 3D view to close
                pass

            # Change the name of our script window's tab
            Shared.setActiveWindowTitle(os.path.basename(filename[0]))

            # Save the file before closing the original and the re-rendering the new one
            ExportCQ.save(filename[0])
            CadQueryExecuteScript().Activated() 
Example #10
Source File: TestAnim.py    From Animation with GNU General Public License v2.0 5 votes vote down vote up
def tearDown(self):
		FreeCAD.closeDocument("AnimTest")
		pass 
Example #11
Source File: cq_cad_tools.py    From kicad-3d-models-in-freecad with GNU General Public License v2.0 5 votes vote down vote up
def close_CQ_Example(App, Gui):

    #close the example
    App.setActiveDocument("Ex000_Introduction")
    App.ActiveDocument=App.getDocument("Ex000_Introduction")
    Gui.ActiveDocument=Gui.getDocument("Ex000_Introduction")
    App.closeDocument("Ex000_Introduction")
    FreeCAD.Console.PrintMessage('\r\nEx000 Closed\r\n')

    #Getting the main window will allow us to start setting things up the way we want
    mw = FreeCADGui.getMainWindow()

    #Adjust the docks as usual
    dockWidgets = mw.findChildren(QtGui.QDockWidget)
    for widget in dockWidgets:
        if (widget.objectName() == "Report view") or (widget.objectName() == "Python console") or (widget.objectName() == "Combo View"):
            widget.setVisible(True)
        if (widget.objectName()=="cqCodeView"):
            widget.setVisible(False)
    FreeCAD.Console.PrintMessage('Dock adjusted\r\n')

    return 0


###################################################################
# FuseObjs_wColors()  maui
#   Function to fuse two objects together.
###################################################################