Using MeshTrim in macros

Thanks for your help with my previous questions.
Please help me again as I still don’t know about Rhino macros.
How can I pass cutting and mesh objects to MeshTrim using their name? I was able to name two objects using SetObjectName and want to use them as the arguments of MeshTrim. I have confirmed that it works manually, but I want to make it work with macros.
In this connection, where can I find this type of information on macros?

Rhino help topic on macros

Wiki page: Creating Macros [McNeel Wiki]

Thank you for your information.

I was able to set the cutting object by calling SelName immediately before MeshTrim.
However, I still do not know how to set the mesh object using SelName.
Can SelName be used as an argument to MeshTrim to set the mesh object in the first place?

Yes, in general in macros you can pre-select the first input object (by name) and then run your command and post-select the second input object (by name). However MeshTrim - as well as Trim and other similar commands - requires an on-screen pick to determine which side of the object to trim away. This cannot be accomplished reliably with a macro. MeshSplit on the other hand can, as it leaves all the parts and does not require a screen pick.

! _-SelName "hmesh"
_MeshSplit
_CoplanarFaces=_Keep
_CreateNgons=_No
_DiscardUnsplitMeshes=_No
_-SelName "vmesh"
_Enter

Thank you for your reply. I don’t think I understand exactly what you mean by “which side of the object”. What I want to do is remove the part outside the box. Anyway, I’d like to try your macro tomorrow.

Run the command manually to see. You have to choose which part to trim away by clicking somewhere on the screen…

Now I understand what you mean. It will take me some time to understand and use the macro you suggested.