How to use ListBox to choose change marterial ?
I have a code use change marterial in assembly
But I can't create a choice table like image
This is a code
Sub Main()
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oTM As TransactionManager = ThisApplication.TransactionManager
Dim oSS As SelectSet = oAsmDoc.SelectSet
If oSS.Count = 0 Then
MessageBox.Show("You have not selected components.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim oOccurrence As ComponentOccurrence
Dim oOccsList As New List(Of ComponentOccurrence)
Dim materialName As String = ""
Dim materialOption As Integer = MessageBox.Show("Choose a material:", "Material Selection", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
Select Case materialOption
Case DialogResult.Yes
materialName = "Stainless Steel"
Case DialogResult.No
materialName = "Water"
Case DialogResult.Cancel
materialName = "Titanium"
Case Else
materialName = "Steel"
End Select
Dim oAssetlib As AssetLibrary
Dim oAsset As Asset
For Each oAssetlib In ThisApplication.AssetLibraries
For i As Integer = 1 To oAssetlib.MaterialAssets.Count
If oAssetlib.MaterialAssets.Item(i).DisplayName = materialName Then
oAsset = oAssetlib.MaterialAssets.Item(i)
GoTo NextStep
End If
Next
Next
NextStep:
If oAsset Is Nothing Then Exit Sub
Dim newTM As Transaction = oTM.StartTransaction(oAsmDoc, "ChangeMaterial")
Dim strLocName, strLocType, currentMaterialName As String
For i As Integer = 1 To oSS.Count
If oSS.Item(i).Type = ObjectTypeEnum.kComponentOccurrenceObject Then
oOccsList.Add(oSS.Item(i))
End If
Next i
For i As Integer = 0 To oOccsList.Count - 1
oOccurrence = oOccsList.Item(i)
If Not oOccurrence.Suppressed Then
If TypeOf oOccurrence.Definition.Document Is PartDocument Then
Dim oPartDoc As PartDocument = oOccurrence.Definition.Document
If oPartDoc.IsModifiable Then
oPartDoc.GetLocationFoundIn(strLocName, strLocType)
If Not strLocType = kLibraryLocation Then
currentMaterialName = oPartDoc.ActiveMaterial.DisplayName
If currentMaterialName <> oAsset.DisplayName Then
oPartDoc.ActiveMaterial = oAsset
End If
End If
End If
End If
End If
Next i
newTM.End()
oAsmDoc.Update()
' oAsmDoc.Save()
End Sub