Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I need to rewrite VBA to ilogic sort partlist

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Darkforce_the_ilogic_guy
241 Views, 2 Replies

I need to rewrite VBA to ilogic sort partlist

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

 

 

 

 

2 REPLIES 2
Message 2 of 3

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
Message 3 of 3

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.

Post to forums  

Autodesk Design & Make Report