Exemplo n.º 1
0
    def Activated(self):
        a2plib.setAutoSolve(True)  # makes no sense without autosolve = ON
        doc = FreeCAD.activeDocument()
        fileName = doc.FileName
        workingDir, basicFileName = os.path.split(fileName)

        filesToUpdate = []
        subAsmNeedsUpdate, filesToUpdate = createUpdateFileList(
            fileName, workingDir, filesToUpdate, True)

        for f in filesToUpdate:
            #-------------------------------------------
            # update necessary documents
            #-------------------------------------------

            # look only for filenames, not paths, as there are problems on WIN10 (Address-translation??)
            importDoc = None
            importDocIsOpen = False
            requestedFile = os.path.split(f)[1]
            for d in FreeCAD.listDocuments().values():
                recentFile = os.path.split(d.FileName)[1]
                if requestedFile == recentFile:
                    importDoc = d  # file is already open...
                    importDocIsOpen = True
                    break

            if not importDocIsOpen:
                if f.lower().endswith('.fcstd'):
                    importDoc = FreeCAD.openDocument(f)
                elif f.lower().endswith('.stp') or f.lower().endswith('.step'):
                    import ImportGui
                    fname = os.path.splitext(os.path.basename(f))[0]
                    FreeCAD.newDocument(fname)
                    newname = FreeCAD.ActiveDocument.Name
                    FreeCAD.setActiveDocument(newname)
                    ImportGui.insert(filename, newname)
                    importDoc = FreeCAD.ActiveDocument
                else:
                    msg = "A part can only be imported from a FreeCAD '*.fcstd' file"
                    QtGui.QMessageBox.information(
                        QtGui.QApplication.activeWindow(), "Value Error", msg)
                    return

            updateImportedParts(importDoc)
            FreeCADGui.updateGui()
            importDoc.save()
            print(u"==== Assembly '{}' has been updated! =====".format(
                importDoc.FileName))
            if importDoc != doc:
                FreeCAD.closeDocument(importDoc.Name)
Exemplo n.º 2
0
    def secondrun(self, newpart=False):
        doc = FreeCAD.activeDocument()

        if newpart is False:
            savedAutoSolveState = a2plib.getAutoSolveState()
            a2plib.setAutoSolve(False)
            a2p_importpart.updateImportedParts(doc, True)
            a2plib.setAutoSolve(savedAutoSolveState)

        newobj = g.partobj
        FreeCADGui.updateGui()
        g.shape2 = newobj.Shape
        getfacelists()
        self.runpostchange()
        doc.recompute()
        FreeCADGui.updateGui()
        CD_ConstraintDiagnostics.statusform.Closeme()
Exemplo n.º 3
0
    def Activated(self):
        a2plib.setAutoSolve(True)  # makes no sense without autosolve = ON
        doc = FreeCAD.activeDocument()
        fileName = doc.FileName
        workingDir, basicFileName = os.path.split(fileName)

        selectedFiles = []
        partial = False
        selection = [
            s for s in FreeCADGui.Selection.getSelection()
            if s.Document == FreeCAD.ActiveDocument and (
                a2plib.isA2pPart(s) or a2plib.isA2pSketch(s))
        ]
        if selection and len(selection) > 0:
            flags = QtGui.QMessageBox.StandardButton.Yes | QtGui.QMessageBox.StandardButton.No
            msg = u"Do you want to update only the selected parts?"
            response = QtGui.QMessageBox.information(
                QtGui.QApplication.activeWindow(), u"RECURSIVE UPDATE", msg,
                flags)
            if response == QtGui.QMessageBox.Yes:
                for s in selection:
                    fDir, fName = os.path.split(s.sourceFile)
                    selectedFiles.append(fName)
                    partial = True

        filesToUpdate = []
        subAsmNeedsUpdate, filesToUpdate = createUpdateFileList(
            fileName, workingDir, filesToUpdate, True, selectedFiles)

        for f in filesToUpdate:
            #-------------------------------------------
            # update necessary documents
            #-------------------------------------------

            # look only for filenames, not paths, as there are problems on WIN10 (Address-translation??)
            importDoc = None
            importDocIsOpen = False
            requestedFile = os.path.split(f)[1]
            for d in FreeCAD.listDocuments().values():
                recentFile = os.path.split(d.FileName)[1]
                if requestedFile == recentFile:
                    importDoc = d  # file is already open...
                    importDocIsOpen = True
                    break

            if not importDocIsOpen:
                if f.lower().endswith('.fcstd'):
                    importDoc = FreeCAD.openDocument(f)
                elif f.lower().endswith('.stp') or f.lower().endswith('.step'):
                    import ImportGui
                    fname = os.path.splitext(os.path.basename(f))[0]
                    FreeCAD.newDocument(fname)
                    newname = FreeCAD.ActiveDocument.Name
                    FreeCAD.setActiveDocument(newname)
                    ImportGui.insert(filename, newname)
                    importDoc = FreeCAD.ActiveDocument
                else:
                    msg = "A part can only be imported from a FreeCAD '*.fcstd' file"
                    QtGui.QMessageBox.information(
                        QtGui.QApplication.activeWindow(), "Value Error", msg)
                    return

            if importDoc == doc and partial == True:
                updateImportedParts(importDoc, True)
            else:
                updateImportedParts(importDoc)

            FreeCADGui.updateGui()
            importDoc.save()
            print(u"==== Assembly '{}' has been updated! =====".format(
                importDoc.FileName))
            if importDoc != doc:
                FreeCAD.closeDocument(importDoc.Name)