iLogic BOM export all parts list posted on every sheet (not the parts only BOM)

iLogic BOM export all parts list posted on every sheet (not the parts only BOM)

cbn56B4Z
Enthusiast Enthusiast
871 Views
6 Replies
Message 1 of 7

iLogic BOM export all parts list posted on every sheet (not the parts only BOM)

cbn56B4Z
Enthusiast
Enthusiast

it seems there is something difficult with defining oSheet in my oOptionsBOM

i'm not sure

 

 

Imports System.Windows.Forms
' Get current location of this file
        Dim ExportPath As String = ThisDoc.Path

        ' Check that this file has been saved and actually exists on disk
        If String.IsNullOrEmpty(ExportPath) Then
            MsgBox("This file has not yet been saved and doesn't exist on disk! - please save it first", 64, "Cadline iLogic")
            Return
        End If

        ' Define folder browse dialog
        Dim Dialog = New FolderBrowserDialog()

        ' Set optionsBOM for folder browser dialog
        Dialog.SelectedPath = ExportPath
        Dialog.ShowNewFolderButton = True
        Dialog.Description = "Please choose Release Folder"

        ' Show dialog box
        If DialogResult.OK = Dialog.ShowDialog() Then
            ' User clicked 'ok' on dialog box - capture the export path
            ExportPath = Dialog.SelectedPath & "\"

        Else
            ' User clicked 'cancel' on dialog box - exit
            Return
        End If

        'Export to XLS

        'define oDoc................oDoc can be many documents, in this case you need the drwaing document
        Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument

        'specify the ACTIVE drawing sheet
        Dim oSheet As Sheet = oDrawDoc.ActiveSheet      '=active sheet!!  .......   = oDoc.Sheets(1) ' first sheet

        ' say there is a Partslist on the sheet.  what if there are more then one?
        Dim oPartslist As Inventor.PartsList = oSheet.PartsLists(1)

        ' create a new NameValueMap object
        Dim oOptionsBOM As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

        'specify an existing template file'to use For formatting colors, fonts, etc
        oOptionsBOM.Value("Template") = "C:\Users\cbn\Desktop\christian projekter\stuff\Partslist.xls"

        'specify the columns to export         
        oOptionsBOM.Value("ExportedColumns") = "ITEM#;QTY;PART#;MATERIAL;DESCRIPTION;COMMENTS;COM CODE;TOTAL WT."

        'specify the start cell
        oOptionsBOM.Value("StartingCell") = "B11"

        'specify the XLS tab name'here the file name is used
        oOptionsBOM.Value("TableName") = "BILL OF MATERIALS"

        'choose to include the parts list title row'in this example "Ye Old List of Parts" is written to the StartingCell
        oOptionsBOM.Value("IncludeTitle") = False

        'choose to autofit the column width in the xls file
        oOptionsBOM.Value("AutoFitColumnWidth") = True

        'get BOMrget folder path
        Dim oFolderBOM As String = Strings.Left(ExportPath, InStrRev(ExportPath, "\")) & "BOM"

        'Check for the BOM folder and create it if it does not exist
        If Not System.IO.Directory.Exists(oFolderBOM) Then
            System.IO.Directory.CreateDirectory(oFolderBOM)
        End If

        ' export the Partslist to Excel with optionsBOM
        oPartslist.Export(oFolderBOM & "\" & oSheet.Name & ".xls", PartsListFileFormatEnum.kMicrosoftExcel, oOptionsBOM)

 

 

0 Likes
Accepted solutions (1)
872 Views
6 Replies
Replies (6)
Message 2 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@cbn56B4Z,

 

Hoping that below changes in iLogic code may be helpful.

Imports System.windows.Forms
 
' Get current location of this file
        Dim ExportPath As String = ThisDoc.Path

        ' Check that this file has been saved and actually exists on disk
        If String.IsNullOrEmpty(ExportPath) Then
            MsgBox("This file has not yet been saved and doesn't exist on disk! - please save it first", 64, "Cadline iLogic")
            Return
        End If

        ' Define folder browse dialog
        Dim Dialog = New FolderBrowserDialog()

        ' Set optionsBOM for folder browser dialog
        Dialog.SelectedPath = ExportPath
        Dialog.ShowNewFolderButton = True
        Dialog.Description = "Please choose Release Folder"

        ' Show dialog box
        If DialogResult.OK = Dialog.ShowDialog() Then
            ' User clicked 'ok' on dialog box - capture the export path
            ExportPath = Dialog.SelectedPath & "\"

        Else
            ' User clicked 'cancel' on dialog box - exit
            Return
        End If

        'Export to XLS

        'define oDoc................oDoc can be many documents, in this case you need the drwaing document
        Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
		
		

        'specify the ACTIVE drawing sheet
        Dim oSheet As Sheet      '=active sheet!!  .......   = oDoc.Sheets(1) ' first sheet
		For Each oSheet In oDrawDoc.Sheets 
			Call oSheet.Activate 
		
	        ' say there is a Partslist on the sheet.  what if there are more then one?
	        Dim oPartslist As Inventor.PartsList = oSheet.PartsLists(1)

	        ' create a new NameValueMap object
	        Dim oOptionsBOM As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

	        'specify an existing template file'to use For formatting colors, fonts, etc
	        oOptionsBOM.Value("Template") = "C:\Users\cbn\Desktop\christian projekter\stuff\Partslist.xls"

	        'specify the columns to export         
	        oOptionsBOM.Value("ExportedColumns") = "ITEM#;QTY;PART#;MATERIAL;DESCRIPTION;COMMENTS;COM CODE;TOTAL WT."

	        'specify the start cell
	        oOptionsBOM.Value("StartingCell") = "B11"

	        'specify the XLS tab name'here the file name is used
	        oOptionsBOM.Value("TableName") = "BILL OF MATERIALS"

	        'choose to include the parts list title row'in this example "Ye Old List of Parts" is written to the StartingCell
	        oOptionsBOM.Value("IncludeTitle") = False

	        'choose to autofit the column width in the xls file
	        oOptionsBOM.Value("AutoFitColumnWidth") = True

	        'get BOMrget folder path
	        Dim oFolderBOM As String = Strings.Left(ExportPath, InStrRev(ExportPath, "\")) & "BOM"

	        'Check for the BOM folder and create it if it does not exist
	        If Not System.IO.Directory.Exists(oFolderBOM) Then
	            System.IO.Directory.CreateDirectory(oFolderBOM)
	        End If

	        ' export the Partslist to Excel with optionsBOM
	        oPartslist.Export(oFolderBOM & "\" & oSheet.Name & ".xls", PartsListFileFormatEnum.kMicrosoftExcel, oOptionsBOM)
		Next 

Thanks and regards


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 7

cbn56B4Z
Enthusiast
Enthusiast

sorry, but no, it still comes with an unhelpful error.

Error in rule: ExportPartsList, in document: Test1.idw

Wrong parameter. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

0 Likes
Message 4 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@cbn56B4Z,

 

Can you please provide non confidential sample drawing to test the behavior?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 7

cbn56B4Z
Enthusiast
Enthusiast

it's just a standard style layout with all of the normal stuff

 

https://www.dropbox.com/sh/ibj5xipopzv5bqw/AAAP46-v6EmUX2HvsRVCS2foa?dl=0

0 Likes
Message 6 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@cbn56B4Z,

 

Try below iLogic code to export partslist into excel. Unfortunately, sheet.name can not be used as excel names. As it contains special character (Sheet:1). "ExportedColumns" should be changed as per partslist columns.

Imports System.windows.Forms
 
' Get current location of this file
        Dim ExportPath As String = ThisDoc.Path

        ' Check that this file has been saved and actually exists on disk
        If String.IsNullOrEmpty(ExportPath) Then
            MsgBox("This file has not yet been saved and doesn't exist on disk! - please save it first", 64, "Cadline iLogic")
            Return
        End If

        ' Define folder browse dialog
        Dim Dialog = New FolderBrowserDialog()

        ' Set optionsBOM for folder browser dialog
        Dialog.SelectedPath = ExportPath
        Dialog.ShowNewFolderButton = True
        Dialog.Description = "Please choose Release Folder"

        ' Show dialog box
        If DialogResult.OK = Dialog.ShowDialog() Then
            ' User clicked 'ok' on dialog box - capture the export path
            ExportPath = Dialog.SelectedPath & "\"

        Else
            ' User clicked 'cancel' on dialog box - exit
            Return
        End If

        'Export to XLS

        'define oDoc................oDoc can be many documents, in this case you need the drwaing document
        Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
		
		Dim i As Integer = 1 

        'specify the ACTIVE drawing sheet
        Dim oSheet As Sheet      '=active sheet!!  .......   = oDoc.Sheets(1) ' first sheet
		For Each oSheet In oDrawDoc.Sheets 
			Call oSheet.Activate 
			If oSheet.PartsLists.Count > 0 Then
				
			
	        ' say there is a Partslist on the sheet.  what if there are more then one?
	        Dim oPartslist As Inventor.PartsList = oSheet.PartsLists(1)

	        ' create a new NameValueMap object
	        Dim oOptionsBOM As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

	        'specify an existing template file'to use For formatting colors, fonts, etc
	        'oOptionsBOM.Value("Template") = "C:\Users\cbn\Desktop\christian projekter\stuff\Partslist.xls"

	        'specify the columns to export         
	        oOptionsBOM.Value("ExportedColumns") = "TOTAL QTY;STOCK NUMBER;DESCRIPTION;MATERIAL;FOR ITEMS"

	        'specify the start cell
	        oOptionsBOM.Value("StartingCell") = "B11"

	        'specify the XLS tab name'here the file name is used
	        oOptionsBOM.Value("TableName") = "BILL OF MATERIALS"

	        'choose to include the parts list title row'in this example "Ye Old List of Parts" is written to the StartingCell
	        oOptionsBOM.Value("IncludeTitle") = False

	        'choose to autofit the column width in the xls file
	        oOptionsBOM.Value("AutoFitColumnWidth") = True

	        'get BOMrget folder path
	        Dim oFolderBOM As String = Strings.Left(ExportPath, InStrRev(ExportPath, "\")) & "BOM"

	        'Check for the BOM folder and create it if it does not exist
	        If Not System.IO.Directory.Exists(oFolderBOM) Then
	            System.IO.Directory.CreateDirectory(oFolderBOM)
	        End If

	        ' export the Partslist to Excel with optionsBOM
	        oPartslist.Export(oFolderBOM & "\" & i & ".xls", PartsListFileFormatEnum.kMicrosoftExcel, oOptionsBOM)
			
			i = i +1
			
			End If 
		Next 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 7 of 7

cbn56B4Z
Enthusiast
Enthusiast

ah, ofcourse. how dumb of me. it's always the simplest issue.

it still only outputs the "Structured BOM" not the actual partslist with static value changes. but that is very nice that it even works now. many thanks

it also only outputs one of the partslists per inventorSheet, which i would like to be another ExcelSheet.

again, many thanks. brilliantly done

0 Likes