Create set through script

Dear all,

I want to create sets for molecules in MS, and I know the steps to do this in Find Patterns tool are as follows:

1. open the document for which you want to create the set 

2. edit -> Find Patterns, then select a document as the Pattern document

3. press "Find"

4. right click in the document, choose "Select Substructure Items"

5. back to Find Patterns tool, press "New Set", and create a new set

Now the problem is, I have to create at least 10 sets for each document. Operating this manually is tedious. So I tried to write a script. "FindPatterns" and "CreateSet" functions were used. However, the new set contained no particles. I think the reason may be the missing of "Select Substructure Items", but I don't know what functions can achieve this in Scripting. If my method is wrong, what other functions can be helpful?

Can anyone help me? Thank you very much.