Place Parts List Error

Place Parts List Error

mat_hijs
Collaborator Collaborator
924 Views
6 Replies
Message 1 of 7

Place Parts List Error

mat_hijs
Collaborator
Collaborator

I must be missing something completely obvious but I'm having issues placing a parts list. I had some code that I used before that worked perfectly. Now it doesn't seem to work anymore. Here's the simplified code:

' Set a reference to the Drawing Document
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument

' Set a reference to the Active Sheet
Dim oSheet As Sheet = oDoc.Sheets.Item(1)

' Set a reference to the Drawing Views collection
Dim oDrawingViews As DrawingViews = oSheet.DrawingViews

' Set a reference to the Drawing View
Dim oDrawingView As DrawingView = oDrawingViews.Item(1)

' Set a reference to the sheet's Title Block
Dim oTitleBlock As TitleBlock = oSheet.TitleBlock

' Set the Parts List Position
Dim oTempPartsListPosition As Point2d = oTitleBlock.RangeBox.MaxPoint

' Place the Parts List
Dim oPartsList As PartsList = oSheet.PartsLists.Add(oDrawingView, oTempPartsListPosition)

 

Then I tried the VBA sample (converted to iLogic), but the error still remains:

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisApplication.ActiveDocument

'Set a reference to the active sheet.
Dim oSheet As Sheet
	oSheet = oDrawDoc.ActiveSheet

' Set a reference to the first drawing view on
' the sheet. This assumes the first drawing
' view on the sheet is not a draft view.
Dim oDrawingView As DrawingView
	oDrawingView = oSheet.DrawingViews(1)

' Set a reference to th sheet's border
Dim oBorder As Border
	oBorder = oSheet.Border

Dim oPlacementPoint As Point2d

If Not oBorder Is Nothing Then
    ' A border exists. The placement point
    ' is the top-right corner of the border.
	oPlacementPoint = oBorder.RangeBox.MaxPoint
Else
    ' There is no border. The placement point
    ' is the top-right corner of the sheet.
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height)
End If

' Create the parts list.
Dim oPartsList As PartsList
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)

I'm on Inventor 2024.3, the last time I used my original code was on Inventor 2023.3. Does anyone see something wrong with the code or is there some kind of bug?

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

Michael.Navara
Advisor
Advisor

Both code snippets works as expected. (Inv 2024.2)

PartsList was placed without errors.

 

Do you have placed the drawing view on sheet?

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

Hi @mat_hijs.  Is it showing an error?  If so, can you copy / paste the contents of both tabs of that error message here, so we can review it.  There are a few possibilities, but difficult to say for sure, without any error message to go from.  Maybe it did not find that first view on the first sheet.  Maybe it did not find the TitleBlock on that sheet.  Maybe you need to 'Activate' that first sheet, if it is not already the active one, before adding a PartsList to it.  Maybe the 'model' needs to be opened before it will place the PartsList.  Just some initial thoughts.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 7

mat_hijs
Collaborator
Collaborator

@Michael.Navara Thank you for testing, at least I know now that the code can work so it might be a bug with my computer.

 

@WCrihfield It is indeed showing an error, I attached screenshots of the error. I tried to check if all the objects were found with a messagebox, and as far as I can tell they're all found correctly.

 

What's most weird to me is that my code had always worked for me, and now it doesn't. I did move to another company and a newer version of Inventor, but besides that I don't see why it won't work.

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @mat_hijs.  If those objects along the way were all obtained correctly, then the only other thing I can think of is that maybe the assembly has not had either of its Stuctured or PartsOnly BOMViews enabled.  I believe that may cause an error like this.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

mat_hijs
Collaborator
Collaborator

@WCrihfield The structured BOM is enabled (All levels). In my full code it specified 

PartsListLevelEnum.kStructured

instead of

PartsListLevelEnum.kStructuredAllLevels

 This seems to have solved it, but I still think it's weird that when not specified it still won't work. Anyways, I'm one step closer to working code again, thank you!

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

Good to hear that we made at least a step in the right direction for you.  I guess if you wanted to make it as error free as possible, you could get a reference to the model that the view is referencing, then make sure it is an assembly, then get its BOM, then check its properties, to make sure at least one of those is enabled, then which one it is, then match that setting within the PartsLists.Add method.

BOM.PartsOnlyViewEnabled 

BOM.StructuredViewEnabled 

BOM.StructuredViewFirstLevelOnly 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes