Indention Troubles

Hello pyRevit Friends :slight_smile:

I have a big problem with a function.
It is working properly and gives me a list as output, but as soon as I want to change or add anything to the function i get errors because of expected/unexpected indents.

  1. I tried to remove all indents and make new one with tabs, as result the list will only have one item.
  2. I tried to throw the code into a beautifier, as result the list will only have one item.
  3. I asked ChatGPT, it says everything is fine.

After 2 hours of trying to fix this I have to give up.
It seems that there is an indention mistake but this mistake makes the code magically work.

Here is the working code and a screenshot how it looks in notepad++

def PaperSize():
	PaperSizeStrings = []
	PaperSizeElements=[]
	SizeErrors=[]
	for sheet in sheets:
		firstTTBL = FilteredElementCollector(doc,sheet.Id).OfCategory(BuiltInCategory.OST_TitleBlocks).FirstElement()
		width = firstTTBL.get_Parameter(BuiltInParameter.SHEET_WIDTH).AsValueString()
		if width == "1,19 m":
			size = "A0"
		elif width == "0,84 m":
			size = "A1"
		elif width == "0,59 m":
			size = "A2"
		elif width == "0,42 m":
			size = "A3"
		else:
			size = "A0"
			error = "error"
			SizeErrors.append(error)
		PaperSizeStrings.append(size)

Would appreciate any help!
Kind regards!

It seems the problem was mixed tab and space indents.
As I fixed it I had the same problems with another function. It is nearly impossible to find such mistakes because i didnt get errors, there were just loops in the script that didnt iterate correct :confused:

How can I avoid and handle such problems in the future?

I’ve had this problem when copying in code from Dynamo to VS Code and this is the solution I used:

If you are working in VS Code, you can check your settings to make sure that when you tap tab, it uses spaces instead. And if you copy in code that has tabs instead of spaces, you can hit Ctrl+Shift+P and search for “Convert indentation to spaces” to covert all tabs to spaces.

1 Like

Hello Kyle, thanks for your reply!

Now i found out that notepad++ also has those features. Converting all tabs to spaces and also making spaces if the tab key is used :slight_smile: