My intent is for the script to determine if it is running in an assembly, and if so, add a new part to the assembly or just create a part if being run from a part file'
so, how it works.
try:
Assy = CurrentAssembly()
Screw = Assy.AddNewPart("Cap Screw M%dx%d" % (Diameter, Length), 0, 0, 0)
except:
Screw = CurrentPart()
It tries to reference the current file as Assy.
If it can, (because you have an assembly open) it then creates a new part in the assembly called Screw.
If it can't, (because you have a part file open) it throws an exception which is caught by the except statement and the current file gets defined as a part called Screw and the script continues