Python Code breaking the original Excel Template from 'File Path'

Hello everyone,

I’m going through a process of using BVN Batch Processor to test multiple Revit files. The idea is, there is a template Excel file that already has all the categories in it and for each Revit file getting tested, the information will be inserted under each appropriate categories. Also it is important to include a piece of graph or code that saves each file separately - we don’t want those multiple Revit file results to override each other.

thanks to @Kulkul who helped me with the code and it saves a separate Excel file for each Revit file. The trouble that I’m seeing is that those results are not in a form of my template Excel file, rather all the information get inserted in an empty Excel sheet.

if you see the code
OUT = IN[0]+’_’+doc.Title+’.xlsx’
this part seems very straight forward and should be using whatever the file that is in the file path - which i set as my template Excel file.

this is the template Excel file. when I run the script without that Python code, the information get inserted in this file. With the code, it uses an empty Excel sheet instead of my template.

Thank you very much guys!

Hello @mixology
you can duplicate your Excel template (if not exist)

import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

#get Path Template
templatePath = IN[0]
#get folder Path
basePath = System.IO.Path.GetDirectoryName(templatePath)
#get fileName without extansion
baseFileName = System.IO.Path.GetFileNameWithoutExtension(templatePath)
#create a new path file
newFilePath = basePath + '\\' + baseFileName + '_' + doc.Title + '.xlsx'
#check if the new path file exist if not create it via Copy/Paste from Template
fileInf = System.IO.FileInfo(newFilePath)
if not fileInf.Exists :
	System.IO.File.Copy(templatePath, newFilePath)

OUT = newFilePath
2 Likes

hello

I just fixed the error.
Thank you very very much for your help.

Could you just simply explain to me what this code is doing though? I’m a beginner in Python and would like to understand each line - in a very generic way.

Thank you for your time!!

Hello
I just comment the code in previous post