Checking if Bounding Box is created using code in Custom Properties

I have found a coding solution for adding the bounding box properties to custom properties here, from Filipe:
https://forum.solidworks.com/thread/39446
But if the bounding box is not created, Solidworks crashes. Is there any way to add into this code so I could first see if bounding box exists first? Like an if statement, and if the bounding box isn't created, it doesn't run the code? Or automatically create a bounding box first with code? I do not want to use a macro. I am using 2014 solidworks.Thanks,

Jack

SolidworksApi macros