Enumerating Occurrences

Enumerating Occurrences

Anonymous
Not applicable
393 Views
6 Replies
Message 1 of 7

Enumerating Occurrences

Anonymous
Not applicable
I'm using the following function to enumerate the occurrence collection:

Public Function FindOccurrence(OccurCollection As ComponentOccurrences, Name As String) As ComponentOccurrence

Dim Occ As ComponentOccurrence

Set FindOccurrence = Nothing

On Error Resume Next
For Each Occ In OccurCollection
Debug.Print Name,
Debug.Print Occ.Name,
If InStr(UCase(Occ.Name), UCase(Name)) 0 Then
If Err.Number = 0 Then
Debug.Print "Found"
Set FindOccurrence = Occ
Exit Function
Else
Debug.Print Err.Description
Err.Clear
End If
Else
Debug.Print "Found"
End If
Next Occ

SkipOnError:
Set FindOccurrence = Nothing

End Function

When I do so, I get this output:

Slide_SBPocketTop Slide:1 Found
Slide_SBPocketTop SidePlate:1 Found
Slide_SBPocketTop SidePlate:2 Found
Slide_SBPocketTop SlideTrapezoid:1 Found
Slide_SBPocketTop Slide_SBPocketSide:1 Found
Slide_SBPocketTop Slide_SBPocketSide:2 Found
Slide_SBPocketTop Method 'Name' of object '_IRxComponentOccurrence' failed
Slide_SBPocketTop Method 'Name' of object '_IRxComponentOccurrence' failed
Slide_SBPocketTop Coupling Nut:1 Found
Slide_SBPocketTop Coupling Nut:2 Found
Slide_SBPocketTop JamNut:1 Found
Slide_SBPocketTop JamNut:2 Found
Slide_SBPocketTop JamBolt:1 Found
Slide_SBPocketTop JamBolt:2 Found
Slide_SBPocketTop Method 'Name' of object '_IRxComponentOccurrence' failed
Slide_SBPocketTop VerticalPlate_Angle:1 Found
Slide_SBPocketTop SlideStiffenerAngle:1 Found
Slide_SBPocketTop Method 'Name' of object '_IRxComponentOccurrence' failed
Slide_SBPocketTop SlideStiffenerAngle:2 Found
Slide_SBPocketTop SlideStiffenerAngle:3 Found

Notice that the 'Name' method fails fairly frequently. Can anyone enlighten me as to why this might be the case? It seems like a bug to me...

Thanks,
Jon Brierley
0 Likes
394 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Is this problem specific to an assembly you are working with? I tried this
on a couple of samples that ship with Inventor and didn't see the problem.
Could you provide specific steps to reproduce the issue?

Sanjay-

wrote in message news:5012921@discussion.autodesk.com...
I'm using the following function to enumerate the occurrence collection:

Public Function FindOccurrence(OccurCollection As ComponentOccurrences, Name
As String) As ComponentOccurrence

Dim Occ As ComponentOccurrence

Set FindOccurrence = Nothing

On Error Resume Next
For Each Occ In OccurCollection
Debug.Print Name,
Debug.Print Occ.Name,
If InStr(UCase(Occ.Name), UCase(Name)) 0 Then
If Err.Number = 0 Then
Debug.Print "Found"
Set FindOccurrence = Occ
Exit Function
Else
Debug.Print Err.Description
Err.Clear
End If
Else
Debug.Print "Found"
End If
Next Occ

SkipOnError:
Set FindOccurrence = Nothing

End Function

When I do so, I get this output:

Slide_SBPocketTop Slide:1 Found
Slide_SBPocketTop SidePlate:1 Found
Slide_SBPocketTop SidePlate:2 Found
Slide_SBPocketTop SlideTrapezoid:1 Found
Slide_SBPocketTop Slide_SBPocketSide:1 Found
Slide_SBPocketTop Slide_SBPocketSide:2 Found
Slide_SBPocketTop Method 'Name' of object
'_IRxComponentOccurrence' failed
Slide_SBPocketTop Method 'Name' of object
'_IRxComponentOccurrence' failed
Slide_SBPocketTop Coupling Nut:1 Found
Slide_SBPocketTop Coupling Nut:2 Found
Slide_SBPocketTop JamNut:1 Found
Slide_SBPocketTop JamNut:2 Found
Slide_SBPocketTop JamBolt:1 Found
Slide_SBPocketTop JamBolt:2 Found
Slide_SBPocketTop Method 'Name' of object
'_IRxComponentOccurrence' failed
Slide_SBPocketTop VerticalPlate_Angle:1 Found
Slide_SBPocketTop SlideStiffenerAngle:1 Found
Slide_SBPocketTop Method 'Name' of object
'_IRxComponentOccurrence' failed
Slide_SBPocketTop SlideStiffenerAngle:2 Found
Slide_SBPocketTop SlideStiffenerAngle:3 Found

Notice that the 'Name' method fails fairly frequently. Can anyone enlighten
me as to why this might be the case? It seems like a bug to me...

Thanks,
Jon Brierley
0 Likes
Message 3 of 7

Anonymous
Not applicable
Thanks for the response - I figured it out: It happens when the reference to those components is unresolved. Which (IMHO) shouldn't be the case - because the reason I'm looking for those components in the first place is to delete them from the assembly. Even if they're unresolved, you should still be able to set an object variable to them so you can use it's properties to resolve them! It'd be nice if you could pass this on to your developers.

So I'm going to have to copy those components over to the project folder, delete them from the assembly, then delete the files again.
0 Likes
Message 4 of 7

Anonymous
Not applicable
This is exactly the situation where ReferencedFileDescriptors help. These
are obtained from a document and list all the referenced documents even if
they are not resolved. The ReferenceStatus indicates whether the documents
resolved ok. If not, you can use the FullFileName property on
ReferencedFileDescriptor object to find the last known full file name of the
referenced file.

Sanjay-

wrote in message news:5016666@discussion.autodesk.com...
Thanks for the response - I figured it out: It happens when the reference
to those components is unresolved. Which (IMHO) shouldn't be the case -
because the reason I'm looking for those components in the first place is to
delete them from the assembly. Even if they're unresolved, you should still
be able to set an object variable to them so you can use it's properties to
resolve them! It'd be nice if you could pass this on to your developers.

So I'm going to have to copy those components over to the project folder,
delete them from the assembly, then delete the files again.
0 Likes
Message 5 of 7

Anonymous
Not applicable
Ok, but as far as I can see in the object browser, they still don't give you a way to resolve it - they just tell you where to file used to be (unless I'm missing it). If you want to delete the reference, or replace it?
0 Likes
Message 6 of 7

Anonymous
Not applicable
There isn't a way to delete a reference. A reference can be replaced, but
only thru Apprentice (using the PutLogicalFileNameUsingFull method). This is
currently not available in Inventor, but will be in a future release. Also,
one other option is to advise on to the FileAccessEvents.OnFileResolution.
This event fires for each referenced document when a document is opened. You
can either allow Inventor to attempt file resolution or resolve the files
yourself.

Sanjay-

wrote in message news:5017731@discussion.autodesk.com...
Ok, but as far as I can see in the object browser, they still don't give you
a way to resolve it - they just tell you where to file used to be (unless
I'm missing it). If you want to delete the reference, or replace it?
0 Likes
Message 7 of 7

Anonymous
Not applicable
None of which works for me. Due to the other inventor limitations (the fact that 2D object model is practically nonexistent), I have to put at least one instance of each reference in the assembly in order to dimension to it. Then I have to delete the ones I don't use. Bottom line is the only way I can delete an occurrence is if it's been properly resolved to start with, then I delete the occurrence, then I delete the file. That works.

Thanks for the info. Any idea when we'll be seeing a completed object model (or a rebate because we paid full price for the product under the assurance that "it's all there")?
0 Likes