Python FreeCAD.open() Examples

The following are 14 code examples of FreeCAD.open(). 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: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 6 votes vote down vote up
def Activated(self):
        doc = FreeCAD.activeDocument()
        if doc is None:
            QtGui.QMessageBox.information(  QtGui.QApplication.activeWindow(),
                                        "No active document found!",
                                        "You have to open an assembly file first."
                                    )
            return
        assemblyPath = os.path.normpath(  os.path.split( os.path.normpath(doc.FileName) )[0])
        importParts = [ob for ob in doc.Objects if "mportPart" in ob.Content]
        for iPart in importParts:
            if (
                iPart.sourceFile.startswith("./") or
                iPart.sourceFile.startswith("../") or
                iPart.sourceFile.startswith(".\\") or
                iPart.sourceFile.startswith("..\\")
                ): continue # path is already relative
            filePath = os.path.normpath(iPart.sourceFile)
            if platform.system() == "Windows":
                prefix = '.\\'
            else:
                prefix = './'
            iPart.sourceFile = prefix + os.path.relpath(filePath, assemblyPath) 
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: EAInit.py    From ExplodedAssembly with GNU General Public License v2.0 5 votes vote down vote up
def Activated(self):
        FreeCAD.open(__dir__ + '/example.fcstd') 
Example #5
Source File: Commands.py    From NodeEditor with MIT License 5 votes vote down vote up
def reset():
    '''file laden und graph anzeigen testcase'''

    if 'aa' not in FreeCAD.listDocuments().keys():
        FreeCAD.open(u"/home/thomas/aa.FCStd")
    FreeCAD.setActiveDocument("aa")

    try:
        pfwrap.deleteInstance()
        del(FreeCAD.PF)
    except:
        pass
    instance=pfwrap.getInstance()
    clearGraph()
    loadGraph() 
Example #6
Source File: Commands.py    From NodeEditor with MIT License 5 votes vote down vote up
def loadFile():

    hidePyFlow()
    if 'graph' not in FreeCAD.listDocuments().keys():
        FreeCAD.open(u"/home/thomas/graph.FCStd")
    FreeCAD.setActiveDocument("graph")
    clearGraph()
    loadGraph() 
Example #7
Source File: Commands.py    From NodeEditor with MIT License 5 votes vote down vote up
def loadAll():
    showPyFlow()
    try:
        FreeCAD.getDocument(fn)
    except:
        FreeCAD.open(u"/home/thomas/{}.FCStd".format(fn))

    FreeCAD.setActiveDocument(fn)
    FreeCAD.ActiveDocument=FreeCAD.getDocument(fn)
    FreeCADGui.ActiveDocument=FreeCADGui.getDocument(fn)
    loadGraph()
    pass 
Example #8
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def GetResources(self):
        return {
            'Pixmap'  : a2plib.pathOfModule()+'/icons/a2p_EditPart.svg',
            'MenuText': 'Edit an imported part (open linked FCStd file)',
            'ToolTip':  toolTip
            } 
Example #9
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        if FreeCAD.activeDocument() is None:
            QtGui.QMessageBox.information(  QtGui.QApplication.activeWindow(),
                                        "No active document found!",
                                        "You have to open an assembly file first."
                                    )
            return
        selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
        FreeCADGui.Selection.clearSelection()
        doc = FreeCAD.ActiveDocument

        if len(selection) == 0: # Show all elements
            for obj in doc.Objects:
                if obj.Name == 'PartInformation': continue
                if obj.Name[:4] == 'Page': continue
                if obj.Name == 'SimpleAssemblyShape': continue
                if not self.hasFaces(obj): continue
                if hasattr(obj,'ViewObject'):
                    if hasattr(obj.ViewObject,'Visibility'):
                        obj.ViewObject.Visibility = True
        else:                   # Show only selected elements
            for obj in doc.Objects:
                if obj.Name == 'PartInformation': continue
                if obj.Name[:4] == 'Page': continue
                if obj.Name == 'SimpleAssemblyShape': continue
                if a2plib.isA2pConstraint(obj): continue
                if hasattr(obj,'ViewObject'):
                    if hasattr(obj.ViewObject,'Visibility'):
                        if obj in selection:
                            obj.ViewObject.Visibility = True
                        else:
                            obj.ViewObject.Visibility = False 
Example #10
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self, checked):
        if FreeCAD.activeDocument() is None:
            QtGui.QMessageBox.information(  QtGui.QApplication.activeWindow(),
                                        "No active document found!",
                                        "You have to open an assembly file first."
                                    )
            return
        if a2plib.isTransparencyEnabled():
            a2plib.restoreTransparency()
        else:
            a2plib.setTransparency() 
Example #11
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        if FreeCAD.activeDocument() is None:
            QtGui.QMessageBox.information(  QtGui.QApplication.activeWindow(),
                                        "No active document found!",
                                        "You have to open an assembly file first."
                                    )
            return
        a2plib.a2p_repairTreeView() 
Example #12
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        if FreeCAD.activeDocument() is None:
            QtGui.QMessageBox.information(  QtGui.QApplication.activeWindow(),
                                        "No active document found!",
                                        "You have to open an assembly file first."
                                    )
            return
        a2p_FlipConstraintDirection() 
Example #13
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 #14
Source File: Commands.py    From NodeEditor with MIT License 4 votes vote down vote up
def refresh_gui():

    store=saveGraph(False)
    # say(store)
    loadGraph(store)
    return

    sayl("REFRESH---------")
    hidePyFlow()
#   tempd=pfwrap.getInstance().getTempDirectory()

    instance=pfwrap.getInstance()
    saveData = instance.graphManager.get().serialize()

    gg=pfwrap.getGraphManager().getAllGraphs()[0]
    say(gg)

    #geaendert
#   saveData = pfwrap.getGraphManager().serialize()
#   saveData = pfwrap.getGraphManager().serialize()
#                json.dump(saveData, f, indent=4)


    #saveData = gg.serialize()
    sayl("naCH SE")
    import tempfile
    f = tempfile.NamedTemporaryFile(delete=False)
    fpath= f.name
    say("HUEW")
    say(saveData)
    say(f)
    say("---------------")
    json.dump(saveData, f, indent=4)
    f.close()
    say("fname",fpath)

    sayl("CCC")
    with open(fpath, 'r') as f:
        data = json.load(f)
        FreeCAD.data=data
        pfwrap.getInstance().loadFromData(data, fpath)

    sayl("huhu")

    pfwrap.getInstance().show()
    clearLogger()
    FreeCADGui.activeDocument().activeView().viewIsometric()
    FreeCADGui.SendMsgToActiveView("ViewFit")