can someone please provide an example of how to use Component.ReplacementCells?
I always end up with error.
Some more hints: does work fine for normal parts, only 'spare by package cell' fails!
For them I get a runtime error "subscript out of range: '[number: 0]'". Unfortunaly it was the first result in my query with pcbDoc.Components
The PCB Automation Reference confused me with "Returns the collection of replacement cells. This includes the current cell.", so I was not sure what data type is returned although it also states "Return/Set Type = An array of strings"
Any idea Mentor has a different behaviour for these spare types?
Why is not returning the used cell?
Function listReplacementCells( comp )
AppendOutput("repl. cells for comp " & comp.Name)
repCellArr = comp.ReplacementCells
if Ubound(repCellArr) < 0 Then
listReplacementCells = "" ' "spare by package cell" fails!
Dim result, i
result = repCellArr(0) ' at least the actually used cell is listed here too!
For i = 1 To Ubound(repCellArr)
result = result + "," + repCellArr(i)
listReplacementCells = result
Yes, you are right, the documentation is confusing - the function returns an array of Strings not a "Collection".
Your "for loop" should be:
For i = 0 To Ubound(repCellArr)
since arrays are zero-based, not one-based.
Not sure what the problem with Spares might be - it could be that the part does not exist in the local PDB (for whatever reason), this would give rise to your error (you might want to check that).
yes, but the loop starts on purpose with 1 - to avoid trimming of ',' the first element is used as initialization (see line before loop).
I've not found out why the Spare by Package Cell fails while a Spare by Part Number does work.
Probably Mentor is leaving the work to the user again: of course a Spare by Package Cell cannot not have a list of replacements cells, but how to find out the difference? .isSpare does only return True or False.
When you use "Spare by Package Cell" it does not attach a part number to the component - it just places a cell which can correspond to any number of different part numbers. So, since there is no part number on the component, the method ReplacementCells can't find any alternate cells in the PDB (since the part number is the index into the PDB).
If you want to differentiate between the two cases you could test for the presence of a part number (component.PartNumber) - there won't be one if you used "Spare by Package Cell". Other than that I am not sure what else to suggest.
I think we both have an idea why it fails, but why is Mentor Automation too lazy to do this check?
The documentation states "This includes the current cell" and no hint of possible failure.
So from my user point of view I'd expect that the currrent cell is returned.
I absolutely agree with you - it should return the current cell in such a situation. In my previous post I meant I am not sure what to suggest as a short-term fix to get you out of this jam.
I will raise this issue with the appropriate team.
Retrieving data ...