Script to duplicate an object and skin wrap it to a reference object to create morph targets from

Hi everyone, I want to create a Maxscript to help create attachment items to a character I’ve been working on. I have a head that is skinned and has a morpher modifier on, and then I have some attachment objects like a beard, a pair of rubber lips etc that I want to be able to skin wrap to the face and “copy” over the morph target positions so the attachment objects deform correctly when the face object is animating.

So when the user selects the attachment object, I want the script to:

Duplicate the object
Add a suffix to its name that corresponds to the reference face object’s first morpher channel name. Eg: RubberLips_upward_smile
Add a skin wrap modifier
Add the reference face object to the skin wrap modifier (but don’t convert to skin)
Duplicate this object
Add a suffix to the new objects name that corresponds to the reference face objects second morpher channel name, Eg: RubberLips_frown
Repeat for all the morph targets in the reference face object.

I tried to record a macro but it fell apart pretty quickly. It doesn’t seem to record the reference object in the skin wrap modifier and I’m apparently too stupid to even be able to work out how to rename the duplicated objects without their 001 suffixes.

This stuff could be split up to a few functions I guess too.

So yeah it’s pretty beyond me. If anyone could help, and help me learn how it works because I’d really like to learn more than the very basics it would be amazing.

I don’t know how much this stuff costs so if anyone could help please let me know your details. It’s not urgent at all, I’d just really like to understand it more.