I have an assembly including 2 parts. I want to take a face in first part as an input for designing second one. Interactively in the CATProduct Workbench, I only choose the face I want in the first part, assumming that I am running a Pad command and need the face as the reference plane, then a copy of the face is automatically created in the workbench I am designing on (for the second part), through which the Pad command is referenced and completed. In VBA programming, if I use Selection for the face in the first part, there will be a error as the face is not in the workbench (a copy is not created automatically as above). If anyone has an idea or workaround for this problem, please let me know! Thanks for your help in advance!
Here is a copy of my code:
Sub CATMain()
Dim productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
Dim product1 As Product
Set product1 = productDocument1.Product
Dim products1 As Products
Set products1 = product1.Products
Set partDocument1 = products1.Item(1)
MsgBox partDocument1.PartNumber
Dim partDoc1 As PartDocument
Set partDoc1 = partDocument1.GetMasterShapeRepresentation(True)
'Dim partDocument2 As PartDocument
Set partDocument2 = products1.Item(2)
MsgBox partDocument2.PartNumber
Dim partDoc2 As PartDocument
Set partDoc2 = partDocument2.GetMasterShapeRepresentation(True)
Dim oSel_1 As Object
Set oSel_1 = partDoc1.Selection
Dim InputObjectType(0) As String
Dim Status As String
InputObjectType(0) = "Face" 'the needed face is cylindrical
Status = oSel_1.SelectElement4(InputObjectType, "Select a face", "Select face", True, partDoc2)
'error keep occuring here with the message "Type mismatch".
MsgBox Status
If (Status = "Normal") Then
partDoc2.Selection.Copy
oSel_1.Clear
oSel_1.Add partDoc1.Part.HybridBodies.Item(1) 'first hybrid body
oSel_1.PasteSpecial "CATPrtResult"
End If
End Sub