From 089aa163fc9c16596fc4d8511b575bb1d0b3a531 Mon Sep 17 00:00:00 2001 From: kbwbe Date: Wed, 7 Nov 2018 14:16:41 +0100 Subject: [PATCH] force saving before partlist creation --- a2p_bom.py | 28 +++++++++++++++++++++------- a2p_partlistglobals.py | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/a2p_bom.py b/a2p_bom.py index 22fd0f88..db390b3e 100644 --- a/a2p_bom.py +++ b/a2p_bom.py @@ -24,15 +24,17 @@ from PySide import QtGui, QtCore import Spreadsheet import os +import string import a2plib from a2p_fcdocumentreader import FCdocumentReader -from a2p_partlistglobals import PARTLIST_COLUMN_NAMES from a2p_partlistglobals import ( + PARTLIST_COLUMN_NAMES, BOM_SHEET_NAME, BOM_SHEET_LABEL, - PARTINFORMATION_SHEET_NAME + PARTINFORMATION_SHEET_NAME, + BOM_MAX_LENGTH ) @@ -115,6 +117,16 @@ def createPartList( #------------------------------------------------------------------------------ class a2p_CreatePartlist(): + + def clearPartList(self): + alphabet_list = list(string.ascii_uppercase) + doc = FreeCAD.activeDocument() + ss = doc.getObject(BOM_SHEET_NAME) + for i in range(0,12): #12 Rows enought for a partlist + for k in range(0,BOM_MAX_LENGTH): + cellAdress = alphabet_list[i]+str(k+1) + print cellAdress + ss.set(cellAdress,'') def Activated(self): doc = FreeCAD.activeDocument() @@ -154,14 +166,16 @@ def Activated(self): recursive=subAssyRecursion ) - # delete old BOM if one exists... + ss = None try: - doc.removeObject(BOM_SHEET_NAME) + ss = doc.getObject(BOM_SHEET_NAME) except: pass - # create a spreadsheet with a special reserved name... - ss = doc.addObject('Spreadsheet::Sheet',BOM_SHEET_NAME) - ss.Label = BOM_SHEET_LABEL + if ss == None: + ss = doc.addObject('Spreadsheet::Sheet',BOM_SHEET_NAME) + ss.Label = BOM_SHEET_LABEL + else: + self.clearPartList() # Write Column headers to spreadsheet ss.set('A1',u'POS') diff --git a/a2p_partlistglobals.py b/a2p_partlistglobals.py index 286e213a..f4520609 100644 --- a/a2p_partlistglobals.py +++ b/a2p_partlistglobals.py @@ -25,6 +25,7 @@ BOM_SHEET_NAME = '_PARTSLIST_' #BOM = BillOfMaterials... BOM_SHEET_LABEL = '#PARTSLIST#' +BOM_MAX_LENGTH = 150 PARTLIST_COLUMN_NAMES = [