iLogic - Bom / Part list in Drawing document. Create, edit and delete

iLogic - Bom / Part list in Drawing document. Create, edit and delete

Anonymous
Not applicable
6,255 Views
26 Replies
Message 1 of 27

iLogic - Bom / Part list in Drawing document. Create, edit and delete

Anonymous
Not applicable

Hi,

First post here, but needed at this time. I tried to find a solution searching again and again on the web, without success.

Working on Inventor Professional 2015 SP2 Build 223

 

I'm working on an iLogic rule to create a BOM which will be exported in an excel template.

I have multiple problems :

Problem 1 :

I can't create a BOM if there isn't one already.

My code, is very basic :

 

iLogicVb.UpdateWhenDone = True

Dim ThisDrawDoc As DrawingDocument = Nothing
ThisDrawDoc = ThisApplication.ActiveDocument
ThisSheet = ThisDrawDoc.ActiveSheet

Dim DrawingPartList As PartsLists = ThisSheet.PartsLists

Dim BomPlacementPoint As Point2d
Dim SheetBorder As Border
SheetBorder = ThisSheet.Border

BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, SheetBorder.RangeBox.MaxPoint.Y)

DrawingPartList.Add(ThisDrawingView,BomPlacementPoint)

If a part list already exist, it works fine. But if there is no part list, I have this error prompting :

 

 

Erreur de règle: math_BOM - Export de liste de piece client, dans le document assemblage.idw

Paramètre incorrect. (Exception de HRESULT : 0x80070057 (E_INVALIDARG))

I don't know why the argument is not valid. It's very strange.

 

Did anyone already have this problem?

 

Problem 2 :

I want to be able to delete the BOM I just create with the rule.

I didn't find the function of the class PartsLists.

I guess it's something like that :

 

Dim ThisDrawDoc As DrawingDocument = Nothing
ThisDrawDoc = ThisApplication.ActiveDocument
ThisSheet = ThisDrawDoc.ActiveSheet
Dim DrawingPartList As PartsLists = ThisSheet.PartsLists

DrawingPartList.Delete.Item(DrawingPartList.count)

But it doesn't work.

 

Is there a documentation where I can find class descriptions of Inventor? Like every functions of class PartsLists?

 

Thanks!

Math

0 Likes
Accepted solutions (1)
6,256 Views
26 Replies
Replies (26)
Message 21 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

You can still run a code to do this from the drawing file, and just "grab" the assembly BOM (database) from there, using the example at this link:

https://www.cadlinecommunity.co.uk/hc/en-us/articles/212849309-Inventor-2017-iLogic-Quick-BOM-Export

 

That example will export from the BOM (database), using the first drawing view on the sheet to find the assembly model, and leave the parts list untouched.

 

Note that in the example, there are PartsOnly lines of code that are commented out, and it is using a Structured BOM view, but you can change that.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 22 of 27

Anonymous
Not applicable

Hi @Curtis_Waguespack

I already had this link to my bookmarks 😉

 

Trying to find a workaround, and export directly from the assembly.

But it seems that Inventor won't let me do what I want...

The parts list I want to export need a custom template, different from the one I use to format my iProperty.

So, I use the method BOM.ImportBOMCustomization to set the BOM view template to the one needed to export.

The method works fine, but the column order is not the same in the excel and the order in the BOM view...

But I can export with the right column order when I export from the graphic built in function.

Like the method BOM.ImportBOMCustomization is corrupt. So I think it's an Inventor bug.

Here is the code I use :

If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("Le document actif n'est pas un assemblage" & vbCrLf & "Abandon de l'export", "Export du dessin", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End If

' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM

' Set the structured view to 'all levels'
'oBOM.StructuredViewFirstLevelOnly = False

' Make sure that the structured view is enabled.
'oBOM.StructuredViewEnabled = True

' Set a reference to the "Structured" BOMView
'Dim oStructuredBOMView As BOMView
'oStructuredBOMView = oBOM.BOMViews.Item("Structured")

' Export the BOM view to an Excel file
'oStructuredBOMView.Export("I:\Mathieu Martel\Inventor\1234. Projet_local\Mecanique\BOM-StructuredAllLevels.xls", kMicrosoftExcelFormat)

' Make sure that the parts only view is enabled.
oBOM.PartsOnlyViewEnabled = True

'Import the Cartable Client template
oBom.ImportBOMCustomization("G:\FichiersInventor\Nomenclature\_nouvelles_nomenclatures\Configuration - Nomenclature (Cartable Client).xml")

' Set a reference to the "Parts Only" BOMView
Dim oPartsOnlyBOMView As BOMView

'oPartsOnlyBOMView = oBOM.BOMViews.Item("Parts Only")
oPartsOnlyBOMView = oBOM.BOMViews.Item("Pièces Uniquement")

' Export the BOM view to an Excel file
oPartsOnlyBOMView.Export("I:\Mathieu Martel\Inventor\1234. Projet_local\Mecanique\BOM-PartsOnly.xls", kMicrosoftExcelFormat)

'Re-import iProperty formating template
oBom.ImportBOMCustomization("G:\FichiersInventor\Nomenclature\_nouvelles_nomenclatures\Configuration - Nomenclature (GENIUS).xml")

 

0 Likes
Message 23 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

It's strange that the column order in Excel does not match the BOM column order, but I think this is just how it works. This is one of the reasons I have always exported from the drawing's parts list rather than the assembly BOM.

 

In any case, here is a post that discusses the task of sorting the columns in Excel after it is exported:

https://forums.autodesk.com/t5/inventor-customization/thisbom-export-column-order-problem/td-p/4902030

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

0 Likes
Message 24 of 27

Anonymous
Not applicable

After studying every solution, I found the good one.

My rule will only work on assembly drawing.

Here the process I will use :

1. Delete every table of the drawing

2. Create the PartsList I want to export with the PartsOnly BOM view

3. Determine the path and the excel file name

4. Export the PartsList

5. Delete the PartsList

6. Create the default PartsList of the drawing with the Structured BOM view

 

So here is my last problem to have the rule working as I want.

On step 2, I have to had a column with the iProperty vendor.

I found that there is a method for that : PartsListColumns.Add but I could manage to have it work with the Vendor property.

I think I misunderstand the PropertySetId and PropertyIdentifier parameter.

Can someone help me on this last thing?

Message 25 of 27

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Anonymous,

 

Here is an example that adds the Vendor Column, based on earlier examples in the discussion.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
oSheet = oDrawDoc.ActiveSheet

Dim oBOM As BOM
Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList

'Try to get the first view on the sheet
Try
	oView = oSheet.DrawingViews(1)
Catch
	MessageBox.Show("There is no view in the drawing", _
	"Export du dessin", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End Try

'get the model that the view is looking at
oModelDoc = ActiveSheet.View(oView.Name).ModelDocument
'get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure  the BOM view is enabled
oBOM.PartsOnlyViewEnabled = True
'get the PartsLists collection
oPartsLists = oSheet.PartsLists

'clean up existing parts lists
For Each oPartsList In oPartsLists
	oPartsList.Delete
Next

'Setting BOM position
Dim BomPlacementPoint As Point2d
Dim oBorder As Border = oSheet.Border
BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d _
(0, oBorder.RangeBox.MaxPoint.Y)

'Create new partsList
oPartsList = oPartsLists.Add(oView,BomPlacementPoint,PartsListLevelEnum.kPartsOnly)

'specify property set
Dim oPropSet As Inventor.PropertySet
oPropSet = oModelDoc.PropertySets.Item("Design Tracking Properties")
Dim oPropSetID As String
oPropSetID = oPropSet.InternalName

'specify the property
Dim oProp As Inventor.Property
oProp = oPropSet.Item("Vendor")
Dim oPropTyp As String
oPropType = Inventor.PropertyTypeEnum.kFileProperty

'specifies the existing column number to index 
'when inserting the wnew one
oColTargetIndex = 5 

'false inserts after the indexed target column 
'True inserts before the indexed target column 
oColumnInsertBefore = False 

'add column
oCol = oPartsList.PartsListColumns.Add _
(oPropType,oPropSetID ,oProp.PropId,oColTargetIndex,oColumnInsertBefore)

'set column title
oCol.Title = "Vendor"

EESignature

0 Likes
Message 26 of 27

Anonymous
Not applicable

Thanks @Curtis_Waguespack

In the same time, I found another way to create it, finding the right PropertySetId and PropID.

Now, everything work!

0 Likes
Message 27 of 27

M.iwanow
Participant
Participant

Hi.

I had the same problem with (Exception de HRESULT : 0x80070057 (E_INVALIDARG)) error.

I don't now it could help You, but in my case problem was incorrect BOM type.

In assembly I had activated Structured BOM but with All Levels:
Znalezione obrazy dla zapytania inventor bom Structure All Levels

In iLogic I tried insert kStructured BOM instead kStructuredAllLevels , and there was a problem. 

I add Try..Catch for two different BOM types and now it's work perfect.

 

Try
	oPartsList = oPartsLists.Add(oModelDoc, BomPlacementPoint, PartsListLevelEnum.kStructured)
Catch
	oPartsList = oPartsLists.Add(oModelDoc, BomPlacementPoint, PartsListLevelEnum.kStructuredAllLevels)
End Try

 I'm hope that will help You.

0 Likes