Python indentation error?

Hey folks, im getting an unexpected indent error following my attempted addition of the try and except area of my python script. (near the bottom) I had to make this addition because the script was failing on missing files. This may be something obvious, my python is pretty rusty.

#python nodes in dynamo 1.0.0  
#originally by Nicklas Østertgaard  nvo@bimshark.com / nvo@shl.fk  
#adapted to handle suffixes by Lucas Cunningham
 
import clr  
clr.AddReference('ProtoGeometry')  
from Autodesk.DesignScript.Geometry import *  
# Import ToDSType(bool) extension method  
clr.AddReference("RevitNodes")  
import Revit  
clr.ImportExtensions(Revit.Elements)  
# Import geometry conversion extension methods  
clr.ImportExtensions(Revit.GeometryConversion)  
# 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 RevitAPI  
clr.AddReference("RevitAPI")  
import Autodesk  
from Autodesk.Revit.DB import *  
doc = DocumentManager.Instance.CurrentDBDocument  
uiapp = DocumentManager.Instance.CurrentUIApplication  
app = uiapp.Application  
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument  
collector = Autodesk.Revit.DB.FilteredElementCollector(doc)  
linkInstances = collector.OfClass(Autodesk.Revit.DB.RevitLinkInstance)  
folderpath = IN[0]  
suffix = IN[1]  
reloadedlinks = []  
for i in linkInstances:
    name = i.Name
    path = folderpath + "\\" + name
    path = path.rsplit(' : ',2)[0]
    plist = list(path)
    plist.insert(-4, suffix)
    cpath = ''
    for s in plist:
        cpath += s
    filepath = FilePath(cpath)
    RevitLinkType  = doc.GetElement(i.GetTypeId())
	try:
    	RevitLinkType.LoadFrom(filepath,None)
    except:
    	reloadedlinks.append('failed on ' + filepath)
    reloadedlinks.append(RevitLinkType)

OUT= reloadedlinks, suffix, cpath

As always thanks for the help.

Hi @L.Cunningham - If you are using Dynamo 2.8 onwards, there is now a Show Whitespace Characters in Python Editor setting :slight_smile:

You can use this in Dynamo Sandbox for now, with release into a future version of Revit! For the time being, simply copy and paste your Python code when you run into issues.

In your particular case, you’ll see an issue inside your for loop, where you are mixing tabs, demarcated by chevrons, and spaces, demarcated by periods.

So change the 3x tabs (chevrons) into 4x spaces and it should resolve!

6 Likes

Awesome, @sol :metal:

Bring it to D4R asap pls :pray::smiley:

1 Like

It’s in the queue Martin! :smiley: Expect it to land sometime next year.

4 Likes