Community
I have an ilogic code and a VBA that I use today. I would like to rewrite it to one Ilogic code?
the ilogic code is this
Try
Dim SheetsNumber
SheetsNumber = ThisApplication.ActiveDocument.Sheets.Count
For i = 1 To SheetsNumber
Dim oPartslistCheck As PartsList
oPartslistCheck = ThisApplication.ActiveDocument.Sheets(i).PartsLists(1)
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Call oDoc.SelectSet.Select(oPartslistCheck)
InventorVb.RunMacro("ApplicationProject", "PartsListSort", "FormatSelectedPartsList")
Next
Catch
End Try
and the VBA code
Option Explicit
Option Base 1
Public Function GetActiveDrawing() As DrawingDocument
If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
Set GetActiveDrawing = ThisApplication.ActiveDocument
Else
MsgBox "Must have a drawing active", vbOKOnly, "Error"
End If
End Function
Public Function GetSelectedPartsList() As PartsList
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = GetActiveDrawing
If oDrawDoc Is Nothing Then Exit Function
Dim oSelectSet As SelectSet
Set oSelectSet = oDrawDoc.SelectSet
If oSelectSet.Count = 0 Then Exit Function
If oSelectSet.Item(1).Type <> kPartsListObject Then Exit Function
Set GetSelectedPartsList = oSelectSet.Item(1)
End Function
Public Function FormatPartsList(oPartsList As PartsList) As PartsList
On Error Resume Next
oPartsList.Sort "PART NUMBER", True
oPartsList.Renumber
oPartsList.SaveItemOverridesToBOM
If Err Then
Err.Clear
MsgBox "Could not sort Parts List", , "Error"
End If
Set FormatPartsList = oPartsList
End Function
Public Sub FormatSelectedPartsList()
Dim oPartsList As PartsList
Set oPartsList = GetSelectedPartsList
If oPartsList Is Nothing Then Exit Sub
FormatPartsList oPartsList
End Sub
Solved! Go to Solution.
Solved by Michael.Navara. Go to Solution.
I don't test it, but I hope it works
Sub Main()
Try
Dim drawing As DrawingDocument = ThisApplication.ActiveDocument
Dim sheetsNumber = drawing.Sheets.Count
For i = 1 To sheetsNumber
Dim oPartslistCheck As PartsList
oPartslistCheck = drawing.Sheets(i).PartsLists(1)
Dim oDoc As DrawingDocument
oDoc = drawing
Call oDoc.SelectSet.Select(oPartslistCheck)
'InventorVb.RunMacro("ApplicationProject", "PartsListSort", "FormatSelectedPartsList")
FormatSelectedPartsList()
Next
Catch
End Try
End Sub
#Region "VBA to iLogic"
'Option Explicit
'Option Base 1
Public Function GetActiveDrawing() As DrawingDocument
If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
GetActiveDrawing = ThisApplication.ActiveDocument
Else
MsgBox("Must have a drawing active", MsgBoxStyle.OkOnly, "Error")
End If
End Function
Public Function GetSelectedPartsList() As PartsList
Dim oDrawDoc As DrawingDocument
oDrawDoc = GetActiveDrawing()
If oDrawDoc Is Nothing Then Exit Function
Dim oSelectSet As SelectSet
oSelectSet = oDrawDoc.SelectSet
If oSelectSet.Count = 0 Then Exit Function
If oSelectSet.Item(1).Type <> ObjectTypeEnum.kPartsListObject Then Exit Function
GetSelectedPartsList = oSelectSet.Item(1)
End Function
Public Function FormatPartsList(oPartsList As PartsList) As PartsList
On Error Resume Next
oPartsList.Sort ("PART NUMBER", True)
oPartsList.Renumber()
oPartsList.SaveItemOverridesToBOM()
If Err() Then
Err.Clear()
MsgBox ("Could not sort Parts List", MsgBoxStyle.OkOnly , "Error")
End If
FormatPartsList = oPartsList
End Function
Public Sub FormatSelectedPartsList()
Dim oPartsList As PartsList
oPartsList = GetSelectedPartsList
If oPartsList Is Nothing Then Exit Sub
FormatPartsList (oPartsList)
End Sub
#End Region
I did need to delete this code
If Err() Then
Err.Clear()
MsgBox ("Could not sort Parts List", MsgBoxStyle.OkOnly , "Error")
End If
but the rest works
Can't find what you're looking for? Ask the community or share your knowledge.