Message 1 of 5
iLogic to Export BOM from Assembly to an excel template

Not applicable
05-10-2018
06:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Guys,
I've a folliwing problem to solve.
I have a working iLogic rule which export BOM (properly modified part only view) to an excell file and then starts a macro inside this file.
The rule is checking for purchased parts and skips them and then export data row by row.
All is working quite good but there is one issue I'd like to solve somehow.
I'd like to sort parts in BOM part view first and then export them to excell maintaining proper order.
Below You can see code snippet:
SyntaxEditor Code Snippet
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then UserChoice1 = MessageBox.Show ( "Regu�a generuje Kart� Ci�cia dla Z�o�e�!" & vbLf & "" & vbLf & "Czy chcesz wygenerowa� Kart� Ci�cia dla pojedy�czej cz�ci?", "iLogic",MessageBoxButtons.YesNo) If UserChoice1 = vbYes Then iLogicVb.RunExternalRule("C:\Users\t.palasz\Desktop\INVENTOR iLOGIC\Karta Ci�cia Cz��.txt") Exit Sub Else Exit Sub End If End If FilePath = ThisDoc.Path If FilePath = "" Then MessageBox.Show("Plik z�o�enia nie zosta� zapisany!" & vbLf & " " & vbLf & "Zapisz plik, nast�pnie uruchom regu�� ponownie.", "iLogic") Exit Sub End If UserChoice2 = MessageBox.Show ( "Czy chcesz wygenerowa� Kart� Ci�cia?" & vbLf & " " & vbLf & "Upewnij si� �e wszystkie niezb�dne dane zosta�y uzupe�nione.", "iLogic",MessageBoxButtons.YesNo) If UserChoice2 = vbNo Then Exit Sub End If Dim oAssyDef As AssemblyComponentDefinition oAssyDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oBOM As BOM oBOM = oAssyDef.BOM oBOM.PartsOnlyViewEnabled = True Dim oBOMView As BOMView oBOMView = oBOM.BOMViews.Item("Tylko cz�ci") Dim oBOMRow As BOMRow 'Kopiowanie danych zawartych w li�cie BOM do pliku Exel' GoExcel.Open("C:\Users\t.palasz\Desktop\Karta Ci�cia Wz�r.xlsm","Arkusz2") i=3 For Each oBOMRow In oBOMView.BOMRows If oBOMRow.BOMStructure <> 51973 Then NumerPozycji=oBOMRow.ItemNumber Dim oCompDef As ComponentDefinition oCompDef = oBOMRow.ComponentDefinitions.Item(1) FullFileName = oCompDef.Document.FullFileName Pozycja=InStrRev(FullFileName,"\", -1) NazwaModelu=Right(FullFileName,Len(FullFileName)-Pozycja) NumerCzesci=iProperties.Value(NazwaModelu, "Project", "Part Number") Opis=iProperties.Value(NazwaModelu, "Project", "Description") Try Nazwa=iProperties.Value(NazwaModelu, "Custom", "Nazwa") Catch End Try Try Rodzaj=iProperties.Material(NazwaModelu) Catch End Try Try Wymiar=iProperties.Value(NazwaModelu, "Custom", "Wymiar") Catch End Try Try Uwagi=iProperties.Value(NazwaModelu, "Custom", "Uwagi") Catch End Try Ilosc=oBOMRow.Totalquantity GoExcel.CellValue("A" & i)=NumerPozycji GoExcel.CellValue("B" & i)=Opis GoExcel.CellValue("C" & i)=NumerCzesci GoExcel.CellValue("D" & i)=Nazwa GoExcel.CellValue("E" & i)=Rodzaj GoExcel.CellValue("F" & i)=Wymiar GoExcel.CellValue("H" & i)=Uwagi GoExcel.CellValue("G" & i)=Ilosc i=i+1 End If Next Select Case i Case 1 To 12 Iloscstr = 1 Case 13 To 24 Iloscstr = 2 Case 25 To 36 Iloscstr = 3 Case 37 To 48 Iloscstr = 4 Case 49 To 60 Iloscstr = 5 End Select Try Artykul = iProperties.Value("Project", "Stock Number") Catch End Try GoExcel.CellValue("A1")=iProperties.Value("Project", "Part Number") GoExcel.CellValue("B1")= Iloscstr GoExcel.CellValue("A2")= "Art. Nr" & " " & Artykul GoExcel.CellValue("D1")=iProperties.Value("Project", "Description") GoExcel.DisplayAlerts = False GoExcel.Save GoExcel.Close 'Uruchomienie Makra zaimplementowanego w akruszu Excel' Dim ExApp As Object ExApp = CreateObject("Excel.Application") ExApp.workbooks.Open ("C:\Users\t.palasz\Desktop\Karta Ci�cia Wz�r.xlsm") ExApp.Application.Run ("KartaCieciaWzor") ExApp.Visible = False ExApp = Nothing MessageBox.Show("Karta ci�cia zosta�a wygenerowana pomy�lnie", "Gratulacje")
Thanks in Advance for any help
Tomek