Error in rule: Exception from HRESULT: 0x80070057 (E_INVALIDARG)

Error in rule: Exception from HRESULT: 0x80070057 (E_INVALIDARG)

David_Bradley_2022
Participant Participant
1,286 Views
8 Replies
Message 1 of 9

Error in rule: Exception from HRESULT: 0x80070057 (E_INVALIDARG)

David_Bradley_2022
Participant
Participant

I have an iLogic code that creates a parts list for assembly level drawings that has recently been giving me errors when running on new drawings for a project. On new drawings in different directories, the code seems to work fine. Saving the document before running the rule doesn't seem to have any effect on the outcome. 

 

The project directories look identical for settings on where the code works and doesn't excluding the file paths. Both file paths are in the same shared network drive. 

I'm wondering if there's an issue with the code itself, or if I should be looking elsewhere for a solution? 

Also, any advice on how to interpret the error messages to solve these issues would be greatly appreciated. Thanks!

 

'[RULE SUMMARY
' This rule is designed to create a parts list for an assembly drawing document based on the Bill of Materials (BOM)
' in the assembly file. Additionally, this file resizes, sorts and places the partslist to follow company standards.
']

'[GET THE MOST UPDATED VERSION OF THE DOCUMENT
InventorVb.DocumentUpdate()
']

'[CHECK IF THE FILE IS A DRAWING FILE
'Define the variable as a string
Dim oDoc As String
'Give the variable doc the value of current document type
oDoc = ThisDoc.Document.DocumentType
'If doc (the file type)is an assembly file, continue through the code
If oDoc = DocumentTypeEnum.kDrawingDocumentObject
	'If doc is NOT an assembly file, prompt the user and end the program
	Else 
		MessageBox.Show("This program is to be ran in Drawing Files (.dwg or .idw) only.", "Error: Wrong File Type", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		Return
End If 
']

'[DEFINE & DECLARE 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 oPlaceX As Double
Dim oPlaceY As Double
'Open drawing document is defined as the open document
oDrawDoc = ThisApplication.ActiveDocument
'The oSheet is defined as currently active sheet
oSheet = oDrawDoc.ActiveSheet
oDrawingView = oSheet.DrawingViews(1)
oBorder = oSheet.Border
']

'[CHECK IF A PARTSLIST EXISTS ON THE SHEET
If oSheet.PartsLists.Count <> 0 Then
	MessageBox.Show("Partslist already exists on this sheet." & vbLf & "Exiting rule.", "ERROR: Partslist Already Exists", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
	Return
	Else
	End If 
']

'[CREATE, RESIZE, AND PLACE PARTSLIST
oPartsList = oSheet.PartsLists.Add(oDrawingView, oBorder.RangeBox.MinPoint)

'[ADD CUSTOM PROPERTIES
'LENGTH
oPartsList.PartsListColumns.Add(kCustomProperty, ,"LENGTH")
'ANGLE_A
oPartsList.PartsListColumns.Add(kCustomProperty, ,"ANGLE_A")
'ANGLE_B
oPartsList.PartsListColumns.Add(kCustomProperty, ,"ANGLE_B")
'FINISH
oPartsList.PartsListColumns.Add(kCustomProperty, ,"FINISH")
'FASTENERS
oPartsList.PartsListColumns.Add(kCustomProperty, ,"FASTENERS")
'GASKETS
oPartsList.PartsListColumns.Add(kCustomProperty, ,"GASKETS")
'ACCESSORIES
oPartsList.PartsListColumns.Add(kCustomProperty, ,"ACCESSORIES")
'WIDTH
oPartsList.PartsListColumns.Add(kCustomProperty, ,"WIDTH")
'HEIGHT
oPartsList.PartsListColumns.Add(kCustomProperty, ,"HEIGHT")
']

'[RESIZE PARTSLIST
'Access information on partlist font
Dim dWidth As Double
dWidth = oPartsList.DataTextStyle.FontSize * oPartsList.DataTextStyle.WidthScale

'[DEFINE & DECLARE VARIABLES
Dim oRow As PartsListRow
Dim sData As String
Dim iCol As Integer
Dim iCols As Integer
iCols = oPartsList.PartsListColumns.Count
Dim iLen() As Integer
'ReDim resizes the array, in this case, iLen from an empty array to an array with a count of iCols
ReDim iLen(iCols)
']

'[FOR LOOP TO CHANGE SIZING OF COLUMNS
'Find the longest text string in each column and resize them
For iCol = 1 To iCols
	iLen(iCol) = Len(oPartsList.PartsListColumns(iCol).Title)
	For Each oRow In oPartsList.PartsListRows
		If oRow.Visible = True Then
			sData = oRow.Item(iCol).Value
			If Len(sData) > iLen(iCol) Then
				iLen(iCol) = Len(sData)
			End If
		End If
	Next oRow
	If oPartsList.PartsListColumns(iCol).Width <> dWidth * (iLen(iCol) + 2) / 1.3 Then
		oPartsList.PartsListColumns(iCol).Width = dWidth * (iLen(iCol) + 2) / 1.3
	End If 
Next iCol
']
'[MODIFY PARTSLIST TO MATCH COMPANY STANDARDS
'Sort by part number, ascending (true), quantity, ascending (true), and auto sort on update (last true after commas)
oPartsList.Sort2("PART NUMBER", True, "QTY", True, , , , True)
oPartsList.Renumber()
']

'[MOVE PARTSLIST TO TOP LEFT CORNER
oPlaceX = oBorder.RangeBox.MinPoint.X + (oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X)
oPlaceY = oBorder.RangeBox.MaxPoint.Y
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oPlaceX, oPlaceY)
oPartsList.Position = oPlacementPoint
']

']

 

I'm using Autodesk Inventor Professional 2021 64-Bit Edition 

Build: 421, Release: 2021.5

0 Likes
1,287 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Hi @David_Bradley_2022.  It is encountering the error at line 50, where it is calling the PartsLists.Add method.  It seems to me like there could only be 2 possible reasons for this error, because it believes that one of its parameters (inputs) is not correct.

1)  This following line of code:

oDrawingView = oSheet.DrawingViews(1)

may not actually be finding a DrawingView on that sheet, leaving the oDrawingView variable without a value.

2) Or, this following line of code:

oBorder = oSheet.Border

...is not finding a Border on that sheet.  It is possible for that property to return Nothing, if no border is present on that sheet.  If either of those is true, that would cause this error.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 9

David_Bradley_2022
Participant
Participant

I checked to see what values those variables are carrying where it isn't working and it appears to be grabbing the info for both the oDrawingView variable and oBorder.  I added this bit of code at line 40 to check it, and got the values returned in the attached image. 

 

 

'[DISPLAY DRAWING VIEW AND BORDER VALUES
MessageBox.Show("oDrawingView value = " & oDrawingView.Name.ToString & vbLf & "oBorder = " & oBorder.Name.ToString)
']

 

 

So it seems like it's reading that there is a drawing view and border present. Any other thoughts on how I might resolve this? 

0 Likes
Message 4 of 9

WCrihfield
Mentor
Mentor

Not sure, but I do see a couple other things before that point in the code that I think could be done differently to make it more stable.  I always advise against using multiple different phrases in multiple locations to identify which document you want the code to be working on.  For instance the phrase "ThisDoc.Document" vs "ThisApplication.ActiveDocument".  Those two can be pointing to different documents in some situations.  I used to prefer the second one most of the time, but after learning more about their differences, I have been using the first one in almost every situation (when used in an iLogic rule, not in VBA or other external resource).  That being said, I do not understand the odd code sequence you are using to checking the document type near the beginning.  I would suggest something more like this:

'[CHECK IF THE FILE IS A DRAWING FILE
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MessageBox.Show("This program is to be ran in Drawing Files (.dwg or .idw) only.", "Error: Wrong File Type", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
	Return
End If 
']

..Then, to keep the reference consistent, I would change this following line:

oDrawDoc = ThisApplication.ActiveDocument

...to this:

oDrawDoc = ThisDoc.Document

Because if this code ever gets ran remotely, either by calling it to run from another rule, or by some sort of event trigger causing it to run, this drawing may not always be the true 'active' document in those situations.  And in those cases, the ThisDoc.Document term is generally more stable/reliable.  Whichever term you use in the document type check, should also be used when setting the value of the actual document you will be working on, just to make sure they are the same document that was checked.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 9

David_Bradley_2022
Participant
Participant

I've still got the error message going, but thanks for the code suggestions! I'm fairly new to iLogic, so the code was built off other forum posts and the API Help in Inventor. The drawing file type check is a lot simpler, and the code runs well with the change from ThisApplication.ActiveDocument to ThisDoc.Document! 

 

 

0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor

Is it still the same error message that you attached the image of in your first post here?  Does the 'More Info' tab include a line with "PartsList.Add" in it? 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 9

David_Bradley_2022
Participant
Participant

Yes, the error message is the exact same after those changes. 

0 Likes
Message 8 of 9

WCrihfield
Mentor
Mentor

Is it possible that the view being used as the input for this new PartsList references an assembly in which both the Strictured and the Parts Only tabs of the BOM have not been 'enabled' yet?  If that is the case, that might be the problem.  If you try to create a new PartsList manually, and select that view as what to base it on, does it show a pop-up notice asking you if you want to enable one of the BOM views?  If so, you may have to open that assembly, then open its BOM dialog, then right-click on the tab that you want to enable (or both tabs), and choose Enable BOM View, then click the Done button, then save that assembly.  That process of enabling the assembly's BOMViews can also be done by code, but that would require digging into that assembly document that the view is referencing.  If this is not the problem, then I'm running out of ideas. 😅

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 9

David_Bradley_2022
Participant
Participant

Good idea, however the Structured and Parts Only BoM were enabled. Thanks again for taking a look into this! 

0 Likes