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,233 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,234 Views
26 Replies
Replies (26)
Message 2 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

Welcome to the forums. 

 

Note that future programming questions of this type are better placed on the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

Also here are some programming help links:

 

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

 

Here is a sample ilogic rule that addresses your questions with the parts list:

 

iLogicVb.UpdateWhenDone = True

Dim ThisDrawDoc As DrawingDocument 
ThisDrawDoc = ThisApplication.ActiveDocument
Dim ThisSheet As Sheet
ThisSheet = ThisDrawDoc.ActiveSheet
Dim oPartsList As PartsList
Dim oView As DrawingView

Try 
	'Try to get the first view on the sheet
	oView = ThisSheet.DrawingViews(1)
Catch
	'catch error when no view exists
	'and exit rule
	MessageBox.Show("View not found", "ilogic")

	Return
End Try

Try 
	'try to get the first parts list 
	'in the PartsLists collection
	oPartsList = ThisSheet.PartsLists.Item(1)
Catch
	'catch error when no parts list is found
	'and then create one
	Dim BomPlacementPoint As Point2d
	Dim SheetBorder As Border
	SheetBorder = ThisSheet.Border
	
	BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, SheetBorder.RangeBox.MaxPoint.Y)
	
	oPartsList = ThisSheet.PartsLists.Add(oView,BomPlacementPoint)
End Try

oQuestion = MessageBox.Show("Do you want to delete the parts list", "iLogic",MessageBoxButtons.YesNo)

If oQuestion = vbYes Then
	oPartsList.Delete
End If

 

 

EESignature

Message 3 of 27

Curtis_Waguespack
Consultant
Consultant

@Anonymous wrote:

 

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

 


here are some ilogic Parts List / Excel links also:

 

http://inventortrenches.blogspot.com/2011/06/ilogic-export-parts-list-with-options.html

http://inventortrenches.blogspot.com/2012/06/create-new-excel-file-with-ilogic.html

EESignature

0 Likes
Message 4 of 27

Anonymous
Not applicable

Hi,

Thanks for your answer.

Unfortunately, I also have the problem with your code.

I have the same error when I run your rule if there is no PartList in the drawing.

0 Likes
Message 5 of 27

mcgyvr
Consultant
Consultant

@Anonymous wrote:

Hi,

Thanks for your answer.

Unfortunately, I also have the problem with your code.

I have the same error when I run your rule if there is no PartList in the drawing.


His code works just fine for me.. (in Inventor 2019 though but I don't think much has changed there with this basic stuff)

Are you sure you aren't running the old rule or something?

Does your drawing have a proper border defined/placed?

 

Did you place a base view on the drawing already? (try should show an error for that though)

 

break the code up into sections and try a bit at a time to see which part is causing the error..

Remove the whole second "try/catch" and see if it errors out then..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 6 of 27

Anonymous
Not applicable

I found where the problem comes from.

I activate in my assembly template the Structured Tab of the BOM by default, to avoid activate it each time.

I seems to cause the problem.

I modified my template, and even if I activate the Structured Tab after creating my assembly but before creating the BOM with the iLogic rule, the code won't work.

Is there a way to avoid that?

Can I deactivate the Structured Tab of the assembly from the drawing with iLogic and activate it again after creating the BOM?

0 Likes
Message 7 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

Ahhh, so I think you will want to specify the BOM structure in the partslist.add line, see the example below.

 

Edit: to note that I've asked someone at Autodesk to take a look, as the behavior seems a bit incorrect here, to me.

 

Note that this example tries to use the kStructured ( First Level) enum, and then uses All Levels

 

PartsList.Add Reference link:

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-64121FC0-E936-4A2B-9F84-46D9BD5701EC

 

PartsListLevelEnum Enumerators

Name Value Description
kFirstLevelComponents 46593 First level components.
kPartsOnly 46594 Parts only.
kStructured 46593 Structured first level components.
kStructuredAllLevels 46595 Structured all components.

 

 

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

 

iLogicVb.UpdateWhenDone = True

Dim ThisDrawDoc As DrawingDocument 
ThisDrawDoc = ThisApplication.ActiveDocument
Dim ThisSheet As Sheet
ThisSheet = ThisDrawDoc.ActiveSheet
Dim oPartsList As PartsList
Dim oView As DrawingView

Try 
	'Try to get the first view on the sheet
	oView = ThisSheet.DrawingViews(1)
Catch
	'catch error when no view exists
	'and exit rule
	MessageBox.Show("View not found", "ilogic")

	Return
End Try

Try 
	'try to get the first parts list 
	'in the PartsLists collection
	oPartsList = ThisSheet.PartsLists.Item(1)
Catch
	'catch error when no parts list is found
	'and then create one
	Dim BomPlacementPoint As Point2d
	Dim SheetBorder As Border
	SheetBorder = ThisSheet.Border
	
	BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, SheetBorder.RangeBox.MaxPoint.Y)

	Try 'try structured 1st level
		oPartsList = ThisSheet.PartsLists.Add _
		(oView,BomPlacementPoint,PartsListLevelEnum.kStructured)
	Catch 'catch error and try all levels
		oPartsList = ThisSheet.PartsLists.Add _
		(oView,BomPlacementPoint,PartsListLevelEnum.kStructuredAllLevels)
	End Try
End Try

oQuestion = MessageBox.Show("Do you want to delete the parts list", "iLogic",MessageBoxButtons.YesNo)

If oQuestion = vbYes Then
	oPartsList.Delete
End If

 

EESignature

0 Likes
Message 8 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @MjDeck,


Can you take a look at this discussion and comment about the issue that arises when the assembly BOM is edited and closed with the Structured tab active. This seems to cause and error with the code when the "optional" parts list level enum is not specified. 

 

If the assembly BOM is edited and closed with the Model Data tab active, then it seems that the optional enum is not required.

 

Can you determine if this is behaving as designed? 

 

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

EESignature

0 Likes
Message 9 of 27

Anonymous
Not applicable

Thanks a lot @Curtis_Waguespack! In the same time, you resolve my next step in my rule!

In fact, I wanted to use the kPartsOnly from the beginning.

But... (there is always a but 🙂 )

If a BOM already exist, the PartsListLevelEnum Enumerators in oPartsLists.Add(oDrawingView,BomPlacementPoint,PartsListLevelEnum.kPartsOnly) is not use.

The PartsList use the PartsListLevelEnum of the existing BOM.

Is there a workaround?

0 Likes
Message 10 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,


Try this version, it looks at the drawing view, gets the model referenced in the view, then gets the BOM object from the model, and then sets the BOM view to use partsonly, then specifies the partsonly enum when adding the partslist.

 

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

 

iLogicVb.UpdateWhenDone = True

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

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


Try 
	'Try to get the first view on the sheet
	oView = ThisSheet.DrawingViews(1)
	'get the model that the veiw is looking at
	oModelDoc = ActiveSheet.View(oView.Name).ModelDocument
	'get the BOM object from the model
	oBOM = oModelDoc.ComponentDefinition.BOM
	'set the BOM to use parts only
	oBOM.PartsOnlyViewEnabled = True
Catch
	'catch error when no view exists
	'and exit rule
	MessageBox.Show("View not found", "ilogic")

	Return
End Try

Try 
	'try to get the first parts list 
	'in the PartsLists collection
	oPartsList = ThisSheet.PartsLists.Item(1)
Catch
	'catch error when no parts list is found
	'and then create one
	Dim BomPlacementPoint As Point2d
	Dim SheetBorder As Border
	SheetBorder = ThisSheet.Border
	
	BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, SheetBorder.RangeBox.MaxPoint.Y)

	oPartsList = ThisSheet.PartsLists.Add _
	(oView,BomPlacementPoint, PartsListLevelEnum.kPartsOnly)

End Try

oQuestion = MessageBox.Show("Do you want to delete the parts list", "iLogic",MessageBoxButtons.YesNo)

If oQuestion = vbYes Then
	oPartsList.Delete
End If

EESignature

0 Likes
Message 11 of 27

Curtis_Waguespack
Consultant
Consultant

@Anonymous

 

Note that my original example answered your questions in the order asked simply to serve as an example, but this version likely handles the removing of an existing parts list and adding a new one it a more real world manner:

 

iLogicVb.UpdateWhenDone = True

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

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


Try 
	'Try to get the first view on the sheet
	oView = ThisSheet.DrawingViews(1)
	'get the model that the veiw is looking at
	oModelDoc = ActiveSheet.View(oView.Name).ModelDocument
	'get the BOM object from the model
	oBOM = oModelDoc.ComponentDefinition.BOM
	'set the BOM to use parts only
	oBOM.PartsOnlyViewEnabled = True
Catch
	'catch error when no view exists
	'and exit rule
	MessageBox.Show("View not found", "ilogic")

	Return
End Try

Try 
	'try to get the first parts list 
	'in the PartsLists collection
	oPartsList = ThisSheet.PartsLists.Item(1)
	
	'set flag
	oNoPartList = False
	
	oQuestion = MessageBox.Show _
	("Do you want to delete the existing parts list, and place a new one?", _
	"iLogic",MessageBoxButtons.YesNo)

	If oQuestion = vbYes Then
		oPartsList.Delete
		'set flag
		oNoPartList = True
	End If
	
Catch
	'set flag
	oNoPartList = True
End Try

'add parts list if none exists
If oNoPartList = True Then
	'catch error when no parts list is found
	'and then create one
	Dim BomPlacementPoint As Point2d
	Dim SheetBorder As Border
	SheetBorder = ThisSheet.Border
	
	BomPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, SheetBorder.RangeBox.MaxPoint.Y)

	oPartsList = ThisSheet.PartsLists.Add _
	(oView,BomPlacementPoint, PartsListLevelEnum.kPartsOnly)
End If

 

EESignature

0 Likes
Message 12 of 27

Anonymous
Not applicable

I tried oyur solution, but it doesn't seem to work.

Maybe I should clarify the goal, to avoid complexity (but everything you did was useful) :

1. Create a new BOM using partsonly level, whether of not a BOM already exist and and it exists, wathever its level.

2. Export the BOM (next step, not the subjet of this post)

3 Delete the table

So here is my rule, without the export part :

 

' CREATE TABLE

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

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

'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 object from the model
oBOM = oModelDoc.ComponentDefinition.BOM
'set the BOM to use parts only
oBOM.PartsOnlyViewEnabled = True
'Try to get the PartsLists collection
oPartsLists = oSheet.PartsLists

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

'Create BOM
Dim BOMexport As PartsList
BOMexport = oPartsLists.Add(oView,BomPlacementPoint,PartsListLevelEnum.kPartsOnly)

iLogicVb.UpdateWhenDone = True

' EXPORT TABLE

' DELETE TABLE
oQuestion = MessageBox.Show("Do you want to delete the parts list", "iLogic",MessageBoxButtons.YesNo)

If oQuestion = vbYes Then
	BOMexport.Delete
	If Debug = True Then
		MessageBox.Show("BOM supprimée", "Debug", MessageBoxButtons.OK, MessageBoxIcon.Warning)
	End If
End If

The problem is that the BOM doesn't use the PartsListLevelEnum even with your previous modifications.

 

0 Likes
Message 13 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

I suspect it is using the PartsOnly view to create the parts list, but you are not seeing it do anything in the assembly BOM, because as written the only thing it does to the BOM is ensure that that PartsOnly view is enabled, but it is not disabling the structured views. 

 

Note that you can have a Structured view enabled and the PartsOnly view enabled at the same time with no issues. You simply set the parts list to be created using the PartsOnly view if that is what you intend to use. Then when you export the partslist, the BOM view that was used when the part list was created is what gets exported.

 

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

 

 

 

 

EESignature

0 Likes
Message 14 of 27

Anonymous
Not applicable

I understand that this part of the code :

'get the BOM object from the model
oBOM = oModelDoc.ComponentDefinition.BOM
'set the BOM to use parts only
oBOM.PartsOnlyViewEnabled = True

is just there to assure that the PartsOnly view is active in the Assembly.

 

But, even if it's active, if I use :

BOMexport = oPartsLists.Add(oView,BomPlacementPoint,PartsListLevelEnum.kPartsOnly)

The BOMexport still use the Structured view and not the PartsOnly view if another BOM already exist in the drawing.

The existing BOM should not have an impact on the newly created BOM.

That's the point I don't understand.

0 Likes
Message 15 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

okay, let's first clarify some terminology:

 

BOM = the internal database of the assembly 

Parts List = the table on the drawing that is "looking at" the BOM

 

In this code the goal is not to export the BOM, but instead to export the Parts List.

 

The code looks at the BOM (database) only to ensure the PartsOnly view of it is enabled. 

Then it uses that PartsOnly  view of the database, when creating the Parts List (table ) 

And then eventually it will grab the Parts List (table ) and export it to Excel, just as it is... meaning it will export it using the PartsOnly view.

 

So even though the BOM (database) could have multiple views enabled, the PartsList.Add line is telling it which view to use via the enumerator kPartsOnly. So the table gets created as Parts Only, and therefore when we export the table, that is what we will get.

 

 

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

 

EESignature

0 Likes
Message 16 of 27

Anonymous
Not applicable

Ok, I was confuse with the terminology.

So here my previous comment with the right terminology :

###################

I understand that this part of the code :

'get the BOM object from the model
oBOM = oModelDoc.ComponentDefinition.BOM
'set the BOM to use parts only
oBOM.PartsOnlyViewEnabled = True

is just there to assure that the PartsOnly view is active in the Assembly BOM. So we can use this BOM view to create our part list.

 

But, even if it's active, if I use :

PartsListToExport = oPartsLists.Add(oView,BomPlacementPoint,PartsListLevelEnum.kPartsOnly)

The PartsListToExport still use the Structured view and not the PartsOnly view of the BOM if another PartsList already exist in the drawing.

The existing PartsList should not have an impact on the newly created PartsList.

That's the point I don't understand.

#####################

What I meant is I don't understand why the option PartsListLevelEnum is not considered when I create the parts list "PartsListToExport"

I hope I will make me understood as english is my second language. But I think we are close to find the solution.

0 Likes
Message 17 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

If you are only placing the parts list, just for export, and do not want it on the sheet in the end, then it might better to export directly from the BOM (database).

 

See this link for an example:

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

 

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

EESignature

0 Likes
Message 18 of 27

Curtis_Waguespack
Consultant
Consultant

@Anonymous wrote:

The PartsListToExport still use the Structured view and not the PartsOnly view of the BOM if another PartsList already exist in the drawing.

The existing PartsList should not have an impact on the newly created PartsList.

That's the point I don't understand.

#####################

What I meant is I don't understand why the option PartsListLevelEnum is not considered when I create the parts list "PartsListToExport"

I hope I will make me understood as english is my second language. But I think we are close to find the solution.


Hi @Anonymous,

 

Your english is great, don't worry about that.

 

I think I now understand the problem now. If you already have a parts list on your drawing, then all parts lists will use the same BOM view, this is just the way Inventor works, otherwise balloons would get confused.

 

As currently written, your code is just placing another parts list without looking to see if one exists already

 

Do you want to check if one  exists first, and replace it?

 

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

 

EESignature

0 Likes
Message 19 of 27

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

So here is an example code that looks for an existing parts list   all existing parts lists , deletes them, then places a new one that is PartsOnly.

 

 

 

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

 

' CREATE TABLE

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) iLogicVb.UpdateWhenDone = True ' EXPORT TABLE ' DELETE TABLE oQuestion = MessageBox.Show("Do you want to delete the parts list", "iLogic",MessageBoxButtons.YesNo) If oQuestion = vbYes Then oPartsList.Delete If oDebug = True Then MessageBox.Show("BOM supprimée", "Debug", MessageBoxButtons.OK, MessageBoxIcon.Warning) End If End If

 

EESignature

0 Likes
Message 20 of 27

Anonymous
Not applicable

Thank you @Curtis_Waguespack, it's very clear now why I can't do what I want.

It makes sense that I can't create a new parts list with a view different from the existing parts list.

So I will change the purpose of the rule to export the PartsOnly parts list from the assembly, and not from the assembly drawing.

I wanted to give the user the opportunity to keep the PartsOnly part list in his drawing for archive purpose.

0 Likes