Hi im trying to programatically add a parts list into a drawing whilst programatically creating the drawing - the code works fine without the parts list code. The error its showing is 'Parameter incorect' on the line that sais PartsList.add(... In the past when ive got this error with other code it has been because ive used an incorrect parameter (e.g. decimal instead of an integer). My error is somewhere inside the oPartsList.add(>>ERROR SOMEWHERE HERE<<<) Please Help!
oDrawDoc = InvApp.Documents.Add(Inventor.DocumentTypeEnum.kDrawingDocumentObject,AssyTemplate, True)
oSheet = oDrawDoc.Sheets.Item(1)
Dim oPoint1 = InvApp.TransientGeometry.CreatePoint2d(12, 14)
Dim oPoint2 = InvApp.TransientGeometry.CreatePoint2d(12, 32)
Dim oPoint3 = InvApp.TransientGeometry.CreatePoint2d(35, 14)
Dim oPoint4 = InvApp.TransientGeometry.CreatePoint2d(50, 32)
Dim oPoint5 = InvApp.TransientGeometry.CreatePoint2d(10, 10)
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, ViewScale, Inventor.ViewOrientationTypeEnum.kFrontViewOrientation, Inventor.DrawingViewStyleEnum.kShadedDrawingViewStyle, "Default")
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, Inventor.DrawingViewStyleEnum.kShadedDrawingViewStyle, ViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, Inventor.DrawingViewStyleEnum.kShadedDrawingViewStyle, ViewScale)
oView4 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint4, Inventor.DrawingViewStyleEnum.kShadedDrawingViewStyle, IsoScale)
Dim oPartsList1 As PartsList
oDrawDoc.Sheets(1).PartsLists.Add(oDrawDoc, oPoint5, PartsListLevelEnum.kPartsOnly, NumberingSchemeEnum.kNumericNumbering, 1, True)
'ERROR SOMEWHERE ON THE LINE ABOVE ^^^
oPartsList1 = oDrawDoc.oSheet.PartsLists.Item(1)
oPartsList1.Sort("VENDOR", 1, "PART NUMBER", 1)
oPartsList1.Renumber()
Thanks in advance, Craig
Could you please modify the following line:
Dim oPoint5 as Point2d = InvApp.TransientGeometry.CreatePoint2d(10, 10)
and let me know the result.
When your Bill of Materials for the Assembly has its view properties set to all levels rather than First Level it can cause some weird errors. This might be it.
Just thought i would post this in case anyone else is searching for parts list things again and comes across this.
The parts list is added to a view, not a drawing. So the first parameter should be a drawing view, not a drawing.
Also change "NumberingSchemeEnum.kNumericNumbering" to "Nothing".
E.g.
oDrawDoc = ThisApplication.ActiveDocument oSheet = oDrawDoc.ActiveSheet Dim oPoint5 = ThisApplication.TransientGeometry.CreatePoint2d(0, oSheet.Height) Dim viw As DrawingView = oDrawDoc.ActiveSheet.DrawingViews.Item(1) oDrawDoc.Sheets(1).PartsLists.Add(viw, oPoint5, PartsListLevelEnum.kPartsOnly, Nothing, 1, False)
Not entirely true...
From API Documentation:
PartsLists.Add( ViewOrModel As Object, PlacementPoint As Point2d, [Level] As PartsListLevelEnum, [NumberingScheme] As Variant, [NumberOfSections] As Long, [WrapLeft] As Boolean ) As PartsList
ViewOrModel: Input object that specifies the source for the parts list. This can either be a DrawingView object
or a Document object. Valid document types include part files and assembly files. Use the Documents.Open method
to open the file if not already open and obtain a Document object. Typically you'll want to set the OpenVisible
argument of the Open method to False so the open is invisible to the user.
Thus, he can just change the oDrawDoc to oPartDoc in his partslist call, rather than pulling from a view.