- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm not sure what I am doing wrong. I'm trying to create an iLogic rule that will enable me to select an iPart in an assembly then have it pull out all the member names to an input list box from where you can select the member name and then change the iPart to the selected member. Here is the code I got through some trial an error. I can get it to run up to the input box and then it goes to the 'Catch'.
You should be able to run this in any assembly that contains an iPart. I'm trying to make it easier to change an iPart by selecting it in the graphics window without having to go to it in the Browser and expanding then going down to the Table, right-click, and select Change Component from the context menu.
Any help would be great. Sorry for the cluttered code it took a bit of work just to get the selected component to pull out the member names.
' Start of iLogic Rule ===============================================================================
' This rule by Luke Davenport @ Excitech
'Check whether open document is an assembly and exit rule if not
oDoc = ThisDoc.ModelDocument
If oDoc.DocumentType = kPartDocumentObject Then
MessageBox.Show("This rule can only be run in an assembly file - exiting rule", "Excitech iLogic")
Return
End If
Dim targetOcc As ComponentOccurrence = Nothing
Do While True
' Note the below line will prompt the user to pick an assembly occurrence (this can be a single part file or a sub-assembly of the active document...kAssemblyOccurrenceFilter
targetOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Occurrence to Modify...(Press ESC to cancel)")
If Not targetOcc Is Nothing Then
Exit Do
Else
Dim Res As MsgBoxResult = MsgBox("No model selected - exit?", 36, "Excitech iLogic")
If Res = vbYes Then
Return
Else
' Do nothing - keep on looping...
End If
End If
Loop
'targetOcc.IsiPartFactory Or
If targetOcc.IsiPartMember Then
MessageBox.Show("This IS an iPart", "Title")
' Return
Else
MessageBox.Show("This is NOT an iPart", "Title")
Return 'do nothing
End If
Dim compDef As PartComponentDefinition = targetOcc.Definition
Dim compiPartMem As iPartMember = compDef.iPartMember
Dim oFactory As iPartFactory = compiPartMem.ParentFactory
Try
Dim ChangePart As New ArrayList
' Iterate through the rows
' Dim oRow As iPartTableRow
For Each oRow As iPartTableRow In oFactory.TableRows
'rowNumber
i = oRow.Index
' Make this the active row so the model will recompute.
' If i > 0 Then
' oFactory.DefaultRow = oRow
xVal = oRow.MemberName
ChangePart.Add(xVal)
' End If
Next
Dim NewRow As VariantType
NewRow = InputListBox("Prompt", ChangePart, NewRow, Title := "Title", ListName := "Change Row")
' comiPartMem.ChangeRowOfiPartMember(NewRow)
Catch
targetName = iPart.RowName(comiPartMem) ' Name()
MessageBox.Show(targetName)
End Try
' End of iLogic Rule ===============================================================================
Solved! Go to Solution.