MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / exportCSV

Method exportCSV

src/Mod/BIM/ArchCommands.py:1447–1488  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1445 self.descr.setText("")
1446
1447 def exportCSV(self):
1448 import csv
1449
1450 rows = self.tree.topLevelItemCount()
1451 if rows:
1452 filename = QtGui.QFileDialog.getSaveFileName(
1453 QtGui.QApplication.activeWindow(),
1454 translate("Arch", "Export CSV File"),
1455 None,
1456 "CSV file (*.csv)",
1457 )
1458 if filename:
1459 with open(filename[0].encode("utf8"), "w") as csvfile:
1460 csvfile = csv.writer(csvfile, delimiter="\t")
1461 suml = 0
1462 for i in range(rows):
1463 item = self.tree.topLevelItem(i)
1464 row = []
1465 row.append(item.text(0))
1466 if item.text(1):
1467 u = FreeCAD.Units.Quantity(item.text(1))
1468 if item.toolTip(0) == "total":
1469 row.append("=SUM(B" + str(suml + 1) + ":B" + str(i) + ")")
1470 else:
1471 row.append(u.Value / u.getUserPreferred()[1])
1472 row.append(u.getUserPreferred()[2])
1473 else:
1474 row.extend(["", ""])
1475 if item.text(2):
1476 t = item.text(2).replace("²", "^2")
1477 u = FreeCAD.Units.Quantity(t)
1478 if item.toolTip(0) == "total":
1479 row.append("=SUM(D" + str(suml + 1) + ":D" + str(i) + ")")
1480 else:
1481 row.append(u.Value / u.getUserPreferred()[1])
1482 row.append(u.getUserPreferred()[2])
1483 else:
1484 row.extend(["", ""])
1485 csvfile.writerow(row)
1486 if item.toolTip(0) == "total":
1487 suml = i + 1
1488 print("successfully exported ", filename[0])
1489
1490
1491def toggleIfcBrepFlag(obj):

Callers

nothing calls this directly

Calls 15

translateFunction · 0.90
rangeFunction · 0.85
printFunction · 0.85
getSaveFileNameMethod · 0.80
activeWindowMethod · 0.80
encodeMethod · 0.80
getUserPreferredMethod · 0.80
openFunction · 0.50
writerMethod · 0.45
appendMethod · 0.45
textMethod · 0.45
QuantityMethod · 0.45

Tested by

no test coverage detected