Strategic automated placement of dimension labels

I currently have a program that balloons all of the dimension on a drawing with a hexagonal balloon (which also exists in part on this forum). The main issue I am having is how readable/clean the output drawing looks. As you can imagine, the balloon placement gets complicated when the drawings get more complicated/crowded. I do have a basic collision detection function that checks to make sure the balloons don't collide (creates bounding boxes based on of XY coordinates and checks to see if there is an overlap between features), but the code gets quite complicated to cover all of the potential cases.

I am wondering if there is a smarter way to go about this. When I manually insert a balloon, I see that it "snaps" into a dotted box around the dimension if I hover it there. It also seems to move other dimensional features if there is an unavoidable overlap/collision. I was wondering if this might be a better way to balloon everything as neatly as possible, and if so, how the feature can be implemented in code.

Besides that, any suggestions for the most optimal method of placing balloons down quickly and neatly would be very much appreciated!

The "snapping in a dotted box" behavior is known as "annotation stacking"; if you search in the NX help file on that term, you will get more information about it. I believe that it is covered by the journal recorder, if you record a journal while stacking an annotation, you should get some sample code to work with.