I came across this code a while trying to figure out how I can accomplish this.
Bulk Save as Central
I am very much a rookie to Python and so I was trying to figure out how I can tweak the code below to essentially open a family from a directory, and change the default view to 3D and then check the regenerate box.
I know the code is from working with central models and I deleted what I think I didnt need. I would also like to change the visual style to realistic. Any assistance would be very much appreciated it.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.Attributes import*
import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import Revit Nodes
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
# Import python library
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
from System.IO import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
SaveOptions = SaveAsOptions()
SaveOptions.MaximumBackups = 1
SaveOptions.OverwriteExistingFile = True
SaveOptions.Compact = False
SaveOptions = IsValidPreviewViewId()
SaveOptions.PreviewViewId = "View 1"
tOptions = TransactWithCentralOptions()
TransactionManager.Instance.ForceCloseTransaction()
filepaths = IN[0]
RVer = "R" + app.VersionNumber[-2:]
docpath = []
if IN[1] == True:
try:
for filepath in filepaths:
file = FileInfo(filepath)
filein = file.FullName
modelpath = FilePath(filein)
filename = filepath.Split("\\")[-1].Replace(".rfa","")
newdoc = app.OpenDocumentFile(filepath)
if RVer not in filename:
if "Central" in filename:
x = filepath.split("_")
x.insert(len(filepath.split("_"))-1,RVer)
y = "_".join(x)
else:
x = filepath[:-4]
y = x + "_" + RVer + ".rfa"
else:
y = filepath
newdoc.SaveAs(y,SaveOptions)
newdoc.Close(True)
docpath.append(y)
OUT = [filepaths,docpath]
except Exception,e:
OUT = str(e)
else:
OUT = "Please set it to true"