Esempio n. 1
0
def importFolder(p, *x):
    for root, folders, files in os.walk(p):
        for f in files:
            for e in x:
                if (f.endswith(e)):
                    try:
                        filename = os.path.join(root, f)
                        importerIL.open(filename)
                        gc.collect()
                    except:
                        importerUtils.logError(traceback.format_exc())
Esempio n. 2
0
def ReadFile(doc, readProperties):
    first = 0
    list = {}
    counters = {}

    # LOG.LOG_FILTER = LOG.LOG_FILTER | LOG.LOG_DEBUG

    if (isOleFile(getInventorFile())):
        ole = OleFileIO(getInventorFile())
        setFileVersion(ole)
        elements = ole.listdir(streams=True, storages=False)

        folder = getInventorFile()[0:-4]
        if not os.path.exists(folder):
            os.makedirs(folder)

        counter = 1
        list = []
        for fname in elements:
            if (len(fname) == 1):
                list.append(fname)
            else:
                #Ensure that RSe* files will be parsed first
                if (fname[-1].startswith('RSe')):
                    #ensure RSeDb is the very first "file" to be parsed
                    list.insert(first, fname)
                    if (fname[-1] == 'RSeDb'):
                        first += 1
                elif (not fname[-1].startswith('B')):
                    list.append(fname)

        for fname in list:
            ReadElement(ole, fname, doc, counter, readProperties)
            counter += 1
        ole.close()

        now = datetime.datetime.now()
        if (len(doc.Comment) > 0):
            doc.Comment += '\n'
        doc.Comment = '# %s: read from %s' % (
            now.strftime('%Y-%m-%d %H:%M:%S'), getInventorFile())

        logMessage("Dumped data to folder: '%s'" % (getInventorFile()[0:-4]),
                   LOG.LOG_INFO)

        return True
    logError("Error - '%s' is not a valid Autodesk Inventor file." % (infile))
    return False
 def addPart(self):
     table = self.form.tableView
     model = table.model()
     rows = model.rowCount(table)
     index = table.currentIndex()
     if (index.isValid()):
         row = index.row() + 1
     else:
         row = rows
     if (model.insertRow(row)):
         index = model.index(row, 0)
         model.setData(index, 'Part-%02d' % (rows + 1), Qt.EditRole)
         FreeCAD.ActiveDocument.recompute()
     else:
         logError("Failed to insert row %d", row)
     return
 def addParam(self):
     parameters = self.getParameters()
     (prmName,
      ok) = QInputDialog.getItem(None, u"FreeCAD - add iPart parameter",
                                 u"Name of the parameter:", parameters)
     if (ok):
         table = self.form.tableView
         model = table.model()
         cols = model.columnCount(table)
         index = table.currentIndex()
         if (index.isValid()):
             col = index.column() + 1
         else:
             col = cols
         if (model.insertColumn(col)):
             model.setHeaderData(col, Qt.Horizontal, prmName,
                                 Qt.DisplayRole)
             FreeCAD.ActiveDocument.recompute()
         else:
             logError("Failed to insert column %d", row)
     return
Esempio n. 5
0
def isFileValid(filename):
	if (not os.path.exists(os.path.abspath(filename))):
		logError(u"File doesn't exists (%s)!", os.path.abspath(filename))
		return False
	if (not os.path.isfile(filename)):
		logError(u"Can't import folders!")
		return False
	if (filename.split(".")[-1].lower() in ("ipt", "iam", "ipn", "idw")):
		if (not isOleFile(filename)):
			logError(u"ERROR> '%s' is not a valid Autodesk Inventor file!", filename)
			return False
	return canImport()
Esempio n. 6
0
def read(doc, filename, readProperties):
    name, ext = os.path.splitext(filename)
    ext = ext.lower()
    if (ext == '.ipt'):
        if (Import_IPT.read(doc, filename, readProperties)):
            return Import_IPT
    elif (ext == '.sat'):
        if (importerSAT.readText(filename)):
            return importerSAT
    elif (ext == '.sab'):
        if (importerSAT.readBinary(filename)):
            return importerSAT
    elif (ext == '.dxf'):
        if (importerDXF.read(filename)):
            return importerDXF
    elif (ext == '.iam'):
        logError(u"Sorry, AUTODESK's Inventor assemblies not yet supported!")
    elif (ext == '.ipn'):
        logError(
            u"Sorry, AUTODESK's Inventor presentations not yet supported!")
    elif (ext == '.idw'):
        logError(u"Sorry, AUTODESK's Inventor drawings not yet supported!")
    return None