Error in rule: Exception from HRESULT: 0x80070057 (E_INVALIDARG)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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