OK. So you were using the ItemByName() instead of the Pick method, that's just fine. Looking back over the code I posted above, I can see now that I left out an important step that might have prevented this behavior. There needed to be a step in there just before the CopyFile line, where it checks to see if that file already exists, before trying to save over it. Something like this:
If System.IO.File.Exists(oCopiedFile) Then
MsgBox("A file by that name already exists. Exiting rule.", vbCritical, "")
Exit Sub 'or Return
End If
Once we add that step in, we still need to deal with the new challenge of making multiple copies of the same part, with each having a unique file name. To do this, we will either need to hard code a quantity number into the code, or prompt the user for a quantity. Maybe something like this:
Dim oQty As Integer = CInt(InputBox("Specify Quantity Of Copies To Make.", "QUANTITY","1"))
(I put the InputBox within CInt() to change its return data Type from String to Integer.)
Then, we will need to work on a naming scheme, or plan for making each file name unique. What would you like to see happen with the file names instead of just appending "_copy" to the end? One fairly simple option might be to add a simple Integer to the end of the file name, then increment that number by 1 for each copy in the quantity.
This would be an example of this idea:
For oCopy As Integer = 1 To oQty
Dim oCopiedFile As String = oPath & oDirSep & oOrigName & oCopy & oExt
Try
ThisApplication.FileManager.CopyFile(oOrigFile, oCopiedFile, FileManagementEnum.kCopyFileMask)
Catch
MsgBox("Failed to copy file.", vbInformation, "")
End Try
Dim oPosition As Matrix = ThisApplication.TransientGeometry.CreateMatrix
oADef.Occurrences.Add(oCopiedFile, oPosition)
Next
Also, if you wanted we could capture the 'position/orientation' (Matrix) of the original component, before we copy it, then use that when we insert the copied versions of it, instead of placing them at the origin. The way to capture this would be like this:
Dim oPosition As Matrix = oOriginal.Transformation
Then don't re-create that same variable again down below, because it has already been created and its value set here.
Does all this make sense to you?
Wesley Crihfield

(Not an Autodesk Employee)