Export to DWG with the date the file was saved

I have the file to export using Konrads script and it works great (Thank you for that) what I was wondering is there a way to add a date stamp (the day it is exported) to the dwg that is exported. Here is the code

# Copyright(c) 2016, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

# Import Element wrapper extension methods
import clr
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

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

import System
from System.Collections.Generic import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

def ProcessList(_func, _list):
    return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )

def ProcessParallelLists(_func, *lists):
	return map( lambda *xs: ProcessParallelLists(_func, *xs) if all(type(x) is list for x in xs) else _func(*xs), *lists )

def Unwrap(item):
	return UnwrapElement(item)

folderPath = IN[0]

if isinstance(IN[1], list):
    views = ProcessList(Unwrap, IN[1])
else:
    views = list(Unwrap(IN[1]))

if isinstance(IN[2], list):
	names = IN[2]
else:
	names = list(IN[2])

dwg_opt = IN[3]

RunIt = IN[5]

def ExportDwg(name, view, folder = folderPath):
	options = None
	settings = FilteredElementCollector(doc).WherePasses(ElementClassFilter(ExportDWGSettings))
	for element in settings:
		if element.Name == dwg_opt:
			options = element.GetDWGExportOptions()
			break 
		
	if options is None:
		options = DWGExportOptions()
	
	options.MergedViews = IN[4]
	views = List[ElementId]()
	views.Add(view.Id)
	result = doc.Export(folder, name, views, options)
	return result

if RunIt:
	try:
		errorReport = None
		# run export
		ProcessParallelLists(ExportDwg, names, views)
	
	except:
		# if error accurs anywhere in the process catch it
		import traceback
		errorReport = traceback.format_exc()
else:
	errorReport = "Please set the RunIt to True!"

#Assign your output to the OUT variable
if errorReport == None:
	OUT = 0
else:
	OUT = errorReport

Assuming the file name does not have .dwg in its name, you can try this. First, import datetime from the datetime module in the top of your script:

from datetime import datetime

Next, add this to the beginning of your ExportDwg() function:

now = datetime.now()
year = now.strftime('%Y')
month = now.strftime('%m')
day = now.strftime('%d')

date_format = '{y}-{m}-{d}'.format(y=year, m=month, d=day)
name_format = name + '_' + date_format

Lastly, replace the second to last line within that function with this:

result = doc.Export(folder, name_format, views, options)

Given a file name like 'Sample.dwg', this should change it to 'Sample_2020-02-17.dwg', for example.

1 Like

you know that sound that a high flying airplane makes when it goes over. that is how I feel reading that. wayyyyy over my head. I am giving it a go however lol. will let you know if i get anywhere thanks you

1 Like

Aim for where the noise is coming from. Everyone I know who has wind up becoming another plane or landing in a much better place.

Just remember, if you get stuck the community is here to help.

1 Like

LOL well had to bring it down to my level and use the pretty pictures to get it to work thanks cgartland (from datetime import datetime was the clue for me) for the push in the right direction. I ended up using nodes to accomplish the task and left the code alone. here is the diagram of the finished product. Thanks again for the help

P.S. if it looks stupid but works it isn’t stupid correct lol

1 Like