Hello all,
I have tried to make VBA script to control iAssembly Tables using ComponentOccurrence.ChangeRowOfiAssemblyMember method Like Sanjay proposed me here http://discussion.autodesk.com/adskcsp/thread.jspa?messageID=5955470 .
Unfortunately this method doesn't work properly for me. The model is quite big, the tables may have about 1000 members and the structure of the model looks like below:
iAssembly
|
+Assembly1
| |
| +iAssembly1_1
| |
| +iAssembly1_2
|
+Assembly2
| |
| +iAssembly2_1
| |
| +iAssembly2_2
|
+Assembly3
| |
| +iAssembly3_1
| |
| +iAssembly3_2
|
+Assembly4
|
+iAssembly4_1
|
+iAssembly4_2
So I'm using members from iAssembly1_1, iAssembly1_2, iAssembly2_1 tables etc. and changing them using ChangeRowOfiAssemblyMember method.
The exaple part of my script you can see below. I'm using this code few times in my script so it is most important.
The problem is, that after calling ChangeRowOfiAssemblyMember (very often but not always) I receive Error 5 "Invalid procedure call or argument".
Why it appears? I think that the procedure is OK, the calling table path is OK and I'm quite sure that the Member names I use are OK and they exists in the tables I call.
This error just sometimes appear and then ChangeRowOfiAssemblyMember doesn't work or works sometimes (even if error appear). The interesting thing is that sometimes when I try to set the Member using its Name, it doesn't work but when i use its Index, it works. Sometimes it works and sometimes it doesn't work even for the same member called two times. Why? This is so strange!
Is this an Inventor issue, or i have missed something important? I have checked it in IV 11, IV 2008 and IV 2009 and there is the same issue whichever version I use.
I have noticed that sometimes it is better when I open the called table with excel, then save it and update the model, but it isn't the solution for me and besides it doesn't help each times. Generally I suppose that somehow, after using ChangeRowOfiAssemblyMember method the iassembly table got broken and with opening this table using Excel and saving it I can fix it. I'm confused... Please help.
The other error i have noticed is
error -2147467259 - Method 'Value' of object '_IRxiAssemblyTableCell' failed
and same here, I have no idea why.
Please Help!
The code:
'Other Declarations
Err.Clear
Dim Processing As String
Dim ErrorNumber As Long
'Caching Errors
On Error GoTo ErrorHandler
'Information for user
Processing = "Setting up Proper Member..."
GoSub LogHandler
'here i call ExcelWorkSheet to refresh the iAssembly table (it helps sometimes)
oSheetCP.Select
oWBCP.Save
oWBCP.Close
'saving called iAssembly
oAssTableCP.Save
'The true calling script code start here
'Looking for member in iAssembly table
oRight = CombinationOfiAssemblyKeys
For i = 1 To oFactoryCP.TableRows.Count
oLeft = oFactoryCP.TableRows.Item(i).Item(14).Value
If oLeft = oRight Then
oCurrentRowValue = oFactoryCP.TableRows.Item(i).MemberName
oCurrentRowIndex = oFactoryCP.TableRows.Item(i).index
Exit For
End If
Next
iCompName = oOccPattCS1.OccurrencePatternElements(1).Occurrences(1).Name
Processing = "Setting up Member: " & oCurrentRowValue
GoSub LogHandler
oOccsCS1.ItemByName(iCompName).ChangeRowOfiAssemblyMember (oCurrentRowValue)
'Here I get Error 5 very often
'This below sometimes help even if Error 5 appear
If ErrorNumber = 5 Then
Processing = "Trying to set member by index..."
GoSub LogHandler
oOccsCS1.ItemByName(iCompName).ChangeRowOfiAssemblyMember (oCurrentRowIndex)
End If
'Update the model
ThisApplication.ActiveDocument.Update
Exit Sub
LogHandler:
Code = Code & Processing & vbCrLf
xUserConsole.xConsole.Value = Code
Return
ErrorHandler:
Code = Code & "WARNING! Got error " & Err.Number & " - " & Err.Description & " | " & "Source: " & Err.Source & vbCrLf
xUserConsole.xConsole.Value = Code
ErrorNumber = Err.Number
Resume Next
End Sub