Expected an indented block erro

Hi,

I’d be appreciated if anyone could help/advise on why am I getting the “expected an indented block” error. Code below.

Thanks in advance.

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

Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

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

FilesToIssue = IN[0]
if not isinstance(FilesToIssue,list):
	FilesToIssue = [FilesToIssue]

DestinationFolder = IN[1]

options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets

worksharingOptions = WorksharingSaveAsOptions()
worksharingOptions.SaveAsCentral = True

SaveOptions = SaveAsOptions()
SaveOptions.SetWorksharingOptions(worksharingOptions)

tOptions = TransactWithCentralOptions()

rOptions = RelinquishOptions(False)
rOptions.StandardWorksets = True
rOptions.ViewWorksets = True
rOptions.FamilyWorksets = True
rOptions.UserWorksets = True
rOptions.CheckedOutElements = True

sOptions = SynchronizeWithCentralOptions()
sOptions.SetRelinquishOptions(rOptions)
sOptions.Compact = True
sOptions.SaveLocalBefore = True
sOptions.SaveLocalAfter = True

RestOfSheets = []
splashscreen = []
			
for file in FilesToIssue:
	modelpath = FilePath(file)
	FileName = file.split("\\")[-1]
	newdoc = app.OpenDocumentFile(FilePath(file),options)
	newdoc.SaveAs(DestinationFolder+"\\"+FileName,SaveOptions)
	
	viewscollector = FilteredElementCollector(newdoc)
	views = viewscollector.OfCategory(BuiltInCategory.OST_Views).ToElementIds()
	sheetscollector = FilteredElementCollector(newdoc)
	sheets = sheetscollector.OfCategory(BuiltInCategory.OST_Sheets).ToElementIds()
	
	for sheet in sheets:
    	if sheet.Name =! "Splash Screen":
    		RestOfSheets.append(sheet)

	TransactionManager.Instance.EnsureInTransaction(newdoc)	
	
	newdoc.Delete(views)
	newdoc.Delete(RestOfSheets)
	
	TransactionManager.Instance.ForceCloseTransaction()
	
	newdoc.SynchronizeWithCentral(tOptions,sOptions)
	newdoc.Close(False)
	
OUT = views, sheets, list

You’re mixing tabs with spaces so the interpreter doesn’t like it. Its a bit of a nuisance to track down since you can’t see any difference but the best thing to do is paste your code into a text editor and search for a 3x or 4x space then replace it with a tab then paste the code back in and it will work.

1 Like

Nice one Thomas, thanks for the prompt reply. I’ve moved it to Word and indeed there’s a bit of a mix of spaces and tabs. I’m using Notepad++ for coding, would you recommend any other better?

Yeah, use Visual Studio Code, create dedicate projects (external py files) for each of your Dynamo graphs and use the Python from string node to run your py files in Dynamo instead. One of the other benefits (aside from being in a decent IDE) is you can re-use your python code in other Dynamo graphs and avoid duplication so your code is easier to maintain.

2 Likes

Thanks for that Thomas, much appreciated :+1:. I do use Visual Studio when messing with the Revit API and addins creation however not using Python for that one. I’ll start doing so…