Python script to add leading zeros to a list of ranges (beginner)

Hi everybody!
My first Python script is a fact!
It takes a list of ranges, changes the integers to strings and put one or two leading zeros in front to create a serial number. I use it as a suffix for all instances of a specific FamilyType in the model.

I’m creating Dynamo graphs for years now but finally got around to start learning Python.
This forum is a great help as always. As well as other sources like the videos by Gavin Crump (Aussie Bim Guru), my friend Juun and this website: https://treyhunner.com/.

In the attached pdf you will find the script as well as a full explaination on what every line does.
There may be other and/or better ways to do what I did and I’m happy to learn them.

I hope this document will be usefull to any of you fellow beginners.
(More will follow but I am slow and have more hobbies so I don’t know when that will be…)

AGMM01_integer to string with leading zeros.pdf (324.5 KB)

4 Likes

I started learning Python last year and it’s wonderful. Are you following a course or just watching videos on youtube etc?

People keep telling me to start for years now and I decided to finally listen.

For now, youtube and websites that explain the things I encounter.
I follow the tutorials by the Aussie Bim Guru
Haven’t done all of them yet. I also was helping a friend with a big Python script so that’s how I rolled into it and finally started.

He made a big script outside Revit.
But when some things failed during the testing I did for him, he broke it up into pieces and made a Dynamo graph containing a lot of smaller scripts. That way I could understand it better and find mistakes, typo’s etc.

1 Like

You can also have a look here: GitHub - Amoursol/dynamoPython: Python Modules for Dynamo :slight_smile: 60+ heavily annotated python scripts from 9+ community members.

Just what a beginner need, thanks a lot!

1 Like

You are most welcome @Menno_Mekes ! One thing to note - if you see any that have an error similar to below - then it’s a newline issue which is very solvable … I’ve just not had the time to go and validate all of these yet :cry:

Simply drag open the Python editor like so…

and then move back anything that isn’t wrapping correctly (i.e. it’s been put on a new line and Python can’t read it)

1 Like