Dear Fnakayama,
Thank you for your query.
In general, Revit will automatically and happily connect everything that can be connected.
Of course, in order to achieve this, I assume that the boxes need to be equipped with connector elements.
Are they?
Furthermore, have you tested and verified that the connection you wish to achieve works as expected when you drive it manually through the user interface?
In general, if a feature is not available in the Revit product manually through the user interface, then the Revit API will not provide it either.
You should therefore research the optimal workflow and best practices to address your task at hand manually through the user interface first.
To do so, please discuss and analyse it with an application engineer, product usage expert, or product support.
Once you have got that part sorted out, it is time to step into the programming environment.
I hope this clarifies.
Best regards,
Jeremy