Working script to create metric bolts on the fly as block items (but some feedback needed)

Wow - I think you are demonstrating two of Python’s superpowers here - rapid development and easy sharing and readability of code.

In terms of the general structure of the script, your CreateBolt() function has definitely become too long - almost everything is happening inside one big function, including the addBolt() call at the end.

You can create a new main function as I show below, and then split CreateBolt into a number of different steps as well as placing some of the logic from CreateBolt into separate functions, possibly with arguments where necessary, e.g. to handle different diameters / lengths / bolt types. There is plenty of scope to reduce repetition in the code (DRY coding principle), for instance the ‘add cosmetic spiral’ section seems ideal for splitting out into a separate add_cosmetic_spiral() function. You do not add the spiral to the bolt curves in all of the sections. Is that deliberate? If not, this is the type of inconsistency which you can avoid by refactoring. :slight_smile:

I would also attempt to separate the loop logic out from the geometry creation / adding, for instance by putting a while loop in the main function and calling the necessary functions from that.

This should make the code easier to read, debug and maintain. Well done on the work you’ve done - this is great !

def main():
    bolt = CreateBolt()
    while True:
        addBolt(bolt)