Message 1 of 3
ParentOccurrence of selected ComponentOccurrence

Not applicable
08-20-2009
08:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I'm writing a macro that runs through all components in an assembly and sorts them into collections by their material. The collections store a unique string that corresponds to the components name as follows:
ComponentName + SubComponentName + SubSubComponentName + etc
To do this, I have this function:
{code}Private Function OccurrenceName(Comp As ComponentOccurrence)
Dim Name As String
Dim Parent As ComponentOccurrence
Err.Clear
On Error Resume Next
'see if there is a parent...
Set Parent = Comp.ParentOccurrence
'if there isn't, then the name is the components name
If Err.Number <> 0 Then
Name = Comp.Name
'If there is, then recursively call OccurrenceName to create a unique name for each component
Else
Name = OccurrenceName(Parent) + Comp.Name
End If
OccurrenceName = Name
End Function{code}
There are two ways that this function is called. First is by a sub that automatically runs through all components and subcomponents in the assembly. The function is called for each component and subcomponent individually. Each component's unique name is just the
{code}Component.Name{code}
and each subcomponent's name is
{code}Component.Name + SubComponent.Name{code}
Then these names are stored in a collection.
The second is by a sub that runs through all components in a SelectedSet. The SelectedSet technically contains an OccurrenceProxy for each selected component. So, in this case the function is called using the OccurrenceProxy.NativeObject as the argument. Sometimes the NativeObject is a subcomponent. But for some reason the function isn't able to find a .ParentOccurrence for the NativeObject. Consequently, the subcomponents unique name is not
{code}Component.Name + SubComponent.Name{code}
but rather, it comes out as just
{code}SubComponent.Name{code}
I'm not sure why this is happening. I don't see why the function can tell a difference between a ComponentOccurrence object that was found automatically and one that was found through a SelectedSet. Am I missing something here?
I'm writing a macro that runs through all components in an assembly and sorts them into collections by their material. The collections store a unique string that corresponds to the components name as follows:
ComponentName + SubComponentName + SubSubComponentName + etc
To do this, I have this function:
{code}Private Function OccurrenceName(Comp As ComponentOccurrence)
Dim Name As String
Dim Parent As ComponentOccurrence
Err.Clear
On Error Resume Next
'see if there is a parent...
Set Parent = Comp.ParentOccurrence
'if there isn't, then the name is the components name
If Err.Number <> 0 Then
Name = Comp.Name
'If there is, then recursively call OccurrenceName to create a unique name for each component
Else
Name = OccurrenceName(Parent) + Comp.Name
End If
OccurrenceName = Name
End Function{code}
There are two ways that this function is called. First is by a sub that automatically runs through all components and subcomponents in the assembly. The function is called for each component and subcomponent individually. Each component's unique name is just the
{code}Component.Name{code}
and each subcomponent's name is
{code}Component.Name + SubComponent.Name{code}
Then these names are stored in a collection.
The second is by a sub that runs through all components in a SelectedSet. The SelectedSet technically contains an OccurrenceProxy for each selected component. So, in this case the function is called using the OccurrenceProxy.NativeObject as the argument. Sometimes the NativeObject is a subcomponent. But for some reason the function isn't able to find a .ParentOccurrence for the NativeObject. Consequently, the subcomponents unique name is not
{code}Component.Name + SubComponent.Name{code}
but rather, it comes out as just
{code}SubComponent.Name{code}
I'm not sure why this is happening. I don't see why the function can tell a difference between a ComponentOccurrence object that was found automatically and one that was found through a SelectedSet. Am I missing something here?