Code:
Imports CATIA
Imports INFITF
Imports ProductStructureTypeLib
Imports MECMODPublic Class Form1
Public CATApp As INFITF.Application
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'hide Form cause not used currently
Me.Hide()
'Check Catia session
Try
CATApp = CATIA.CATIA.CheckCATIA()
Catch ex As Exception
MsgBox("No Catia session was found.")
End
End Try
'checking if open documents
Dim doccount As Boolean
doccount = CATIA.CATIA.ActiveDoccheck(CATApp.Documents.Count)
'check if a product is opened
Dim classtype As String
classtype = CATIA.CATIA.DocClassCheck(CATApp.ActiveDocument)
If classtype <> "ProductDocument" Then
MsgBox("Please open a Catia Product")
End
End If
'Declaration of variables
Dim productDocument1 As ProductDocument = CATApp.ActiveDocument
Dim Selection1 As Selection = productDocument1.Selection
Dim ObjectInputType(0)
ObjectInputType(0) = "Product"
Dim UserSelection As Object
Dim selcount As Integer
Dim counter As Integer
'Clear any previous selection and initialize
Selection1.Clear()
'User Prompt allowing multi-selection
UserSelection = Selection1.SelectElement3(ObjectInputType, "Please select Product(s) (Hold CTRL for multi-selection). Confirm with FINISH. Abort with ESC", True, CATMultiSelectionMode.CATMultiSelTriggWhenUserValidatesSelection, False)
'range of selection
selcount = Selection1.Count
'switch all selected into design mode
For counter = 1 To selcount
productDocument1.Product.Products.Item(Selection1.Item(counter).Value.Name).ApplyWorkMode(CatWorkModeType.DEFAULT_MODE)
Next
'Open in new window
CATApp.StartCommand("Open in New Window")
Me.Close()
End Sub
End Class