PartsLists.Add error with Inventor 2017?

PartsLists.Add error with Inventor 2017?

Curtis_Waguespack
Consultant Consultant
799 Views
9 Replies
Message 1 of 10

PartsLists.Add error with Inventor 2017?

Curtis_Waguespack
Consultant
Consultant

with ilogic I used to be able to use something like this in previous versions of Inventor:

 

Dim oDrawDoc As DrawingDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oPlacementPoint As Point2d
Dim oPartsList As PartsList 

oDrawDoc = ThisApplication.ActiveDocument
oSheet = oDrawDoc.ActiveSheet
oDrawingView = oSheet.DrawingViews(1)
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(60, 20)    
oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)

 

 

But now in Inventor 2017 I'm needing to specify the PartsList Level, otherwise I get an error.

 

Meaning that I must use something like this:

 

Dim oDrawDoc As DrawingDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oPlacementPoint As Point2d
Dim oPartsList As PartsList 

oDrawDoc = ThisApplication.ActiveDocument
oSheet = oDrawDoc.ActiveSheet
oDrawingView = oSheet.DrawingViews(1)
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(60, 20)    
oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint,PartsListLevelEnum.kFirstLevelComponents)

 

 

I'm trying to determine if there was a change, or if there is something else going on.

 

Can anyone else confirm that the first version creates an error and the 2nd version works in Inventor 2017... or any other version?

 

 

Thanks!

Curtis

EESignature

0 Likes
800 Views
9 Replies
Replies (9)
Message 2 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Curtis_Waguespack,

 

Without specifying PartsLevelEnum in PartsList.Add function through iLogic, a PartsList can be added into a drawing document. Please refer following screencast.

 

 

Syntax

PartsLists.Add( ViewOrModel As Object, PlacementPoint As Point2d, [Level] As PartsListLevelEnum, [NumberingScheme] As Variant, [NumberOfSections] As Long, [WrapLeft] As Boolean ) As PartsList
 
In API documentation, syntax of PartsLists.Add also says, 'PartsListLevelEnum is optional parameter'.
 
Please feel free to contact if there is any doubt.
 
If solves problem, click on "Accept as solution" / give a "Kudo".
 
Thanks and regards,

CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 10

bshbsh
Collaborator
Collaborator

can confirm that first version works in 2017 ilogic, just tried it.

i use vba and macros written in 2014 and they still do work in 2017.

 

0 Likes
Message 4 of 10

Curtis_Waguespack
Consultant
Consultant

Thanks for the replies.  So it sounds like it's not a version issue. And I've tried this with our template, and with a generic template, and I get the same results, so I don't think it's related to the file, but I've attached a drawing here just in case.

 

This is what I'm seeing. I get an error, when trying to place the parts list via code, but if I place one manually first, then the code works: 

 

 

It appears that the assembly BOM must be set to use the "First Level" Structured Properties? In this video when I set the BOM to use First Level the code works, but when set to use All Levels it does not.

 

Can anyone validate that this is the case?

 

 

 

 

 

 

Thanks again,

Curtis

EESignature

0 Likes
Message 5 of 10

GosponZ
Collaborator
Collaborator

I just tried and works on my Inventor2017. No problem at all. Your code is good

 

try this one

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 10780 StartFragment: 314 EndFragment: 10748 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

Sub Main()

'Declare local variables
Dim oDrawDoc As DrawingDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oPlacementPoint As Point2d
Dim oPartsList As PartsList 
Dim oBorder As Border
Dim oStyle As String
Dim oPlaceX As Double
Dim oPlaceY As Double

'initialize variables
oDrawDoc = ThisApplication.ActiveDocument
oSheet = oDrawDoc.ActiveSheet
oDrawingView = oSheet.DrawingViews(1)
oBorder = oSheet.Border

'create parts list
oPartsList = oSheet.PartsLists.Add(oDrawingView, oBorder.RangeBox.MinPoint)
'oPartsList.Style = oDrawDoc.StylesManager.PartsListStyles.Item(oStyle)

'reposition parts list to top left
oPlaceX = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)+(1.27)
oPlaceY = oBorder.RangeBox.MaxPoint.Y 
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oPlaceX,oPlaceY)
oPartslist.position = oPlacementPoint

End Sub
0 Likes
Message 6 of 10

Curtis_Waguespack
Consultant
Consultant

@MisterZS wrote:

I just tried and works on my Inventor2017. No problem at all...


Hi MisterZS,

 

Thanks for looking at this. Are you saying that you were able to get the code to work with an assembly that has the "Structured Properties" set to "All Levels" , with no problem at all?

 

Also thanks for the code example. I don't see anything in that example that is different concerning the parts list level, but I ran it anyway and I get the same error when I try it with an assembly set to "All Levels" .

 

Can you confirm that you can place a parts list for an assembly set to use All Levels using your example?

 

Thanks again,

Curtis

 

 

EESignature

0 Likes
Message 7 of 10

GosponZ
Collaborator
Collaborator

Capture.JPGNo for all levels it doesn't work

 

 

 

0 Likes
Message 8 of 10

Curtis_Waguespack
Consultant
Consultant

@MisterZS wrote:

No for all levels it doesn't work

 

 


 

Hi MisterZS,

 

Okay thanks for confirming this.

 

As chandra.shekar.g mentioned the API help says that the specifying the PartsListLevel is optional, but it seems maybe that is not the case?

 

I suppose I can just use something like this:

 

'create parts list
Try
	oPartsList = _
	oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, _
	PartsListLevelEnum.kStructuredAllLevels)
Catch
	oPartsList = _
	oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, _
	PartsListLevelEnum.kFirstLevelComponents)
End Try

 

Thanks,
Curtis

EESignature

0 Likes
Message 9 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Curtis_Waguespack,

 

When property of "Structured" is set to "All Levels", Exception thrown and says that "The parameter is incorrect".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 10 of 10

wmgshurik
Enthusiast
Enthusiast

I alsways had two variants. One of this works.

 

try
{
     oPartsList = oSheet.PartsLists.Add(oDrawView, oPlacementPoint, PartsListLevelEnum.kStructured);
}
catch
{
    try
    {
        oPartsList = oSheet.PartsLists.Add(oDrawView, oPlacementPoint, PartsListLevelEnum.kStructuredAllLevels);
    }
    catch
   {
       return;
   }
}

0 Likes